예제 #1
0
 function updatefeedback()
 {
     $id = $this->_get('id', 'intval');
     header('Content-Type:text/html;charset=utf-8');
     $wetallroute = dirname(dirname(dirname(dirname(dirname(__FILE__)))));
     //dump($wetallroute);exit;
     include $wetallroute . "/wxpay/config.php";
     //dump($config);exit;
     include $wetallroute . "/wxpay/lib.php";
     $wechat = new Wechat();
     // openid 与 feedback参数都可以从数据库中得到
     $feedback = $this->_mod->where(array('id' => $id))->find();
     //dump($feedback);exit;
     //$content = 'http://api.weixin.qq.com/cgi-bin/pay/delivernotify?access_token=' . $wechat->getAccessToken($config) . '&openid=' . $feedback['openid'] . '&feedbackid=' . $feedback['feedbackid'];
     $content = 'https://api.weixin.qq.com/payfeedback/update?access_token=' . $wechat->getAccessToken($config) . '&openid=' . $feedback['openid'] . '&feedbackid=' . $feedback['feedbackid'];
     //dump($content);
     $result = $wechat->curlGet($content);
     //dump($result);exit;
     $result = json_decode($result, true);
     if ($result['errcode'] == 0) {
         //echo 'success';
         //IS_AJAX && $this->ajaxReturn(1, $result['errmsg'], '', 'edit');
         $this->_mod->where(array('id' => $id))->save(array('status' => 1));
         $this->success('通知微信成功!');
     } elseif ($result['errcode'] == -1 && $result['errmsg'] == 'system error') {
         $this->_mod->where(array('id' => $id))->save(array('status' => 1));
         $this->success('已经通知过微信,更改状态成功!');
     } else {
         //IS_AJAX && $this->ajaxReturn(0, $result['errmsg']);
         $this->error($result['errmsg']);
     }
 }
 public function getAccessToken($appIndex = 10)
 {
     $whArr = array('mpid' => $appIndex);
     $rowArr = $this->where($whArr)->find();
     //参数 判别token是否有效,true-有效;false-无效;
     $TokenFlag = true;
     //对数据中的缓存token处理
     //数据库不存在accesstoken
     if ($this->where($whArr)->count() <= 0) {
         $TokenFlag = false;
     } else {
         $expiresDate = $rowArr['expired'] == null ? null : strtotime($rowArr['expired']);
         if ($expiresDate == null || $rowArr['access_token'] == null) {
             $TokenFlag = false;
         } else {
             //与当前时间差是否超过2小时-分钟计算;
             $minteDif = time() - $expiresDate;
             if ($minteDif > 0) {
                 $TokenFlag = false;
             }
         }
     }
     if (!$TokenFlag) {
         //获取当前应用ID等信息
         $AppKey = Platform::$AppArr[$appIndex];
         //实例化微信插件
         $wechat = new Wechat($AppKey['AppID'], $AppKey['AppSecret']);
         $newRow = $wechat->getAccessToken();
         if ($newRow == null || $newRow['access_token'] == null) {
             echo "获取不到accesstoken";
             exit;
         }
         //将accesstoken存入数据库
         $ok = $this->where($whArr)->delete();
         $newAdd['access_token'] = $newRow['access_token'];
         $newAdd['mpid'] = $appIndex;
         $newAdd['expired'] = date('Y-m-d H:i:s', $newRow['expire_time']);
         $this->add($newAdd);
         return $newAdd['access_token'];
     } else {
         return $rowArr['access_token'];
     }
 }
예제 #3
0
 /**
  * 授权回调
  * @param string $code
  * @param string $data
  * @throws CException
  * @throws Exception
  */
 public function actionWechat($code = '', $data = '')
 {
     Yii::import('ext.wechat.*');
     //判断不同授权来源
     //code: 正常微信授权的参数
     //data: 群友代理授权json
     if (!empty($code)) {
         $wehcat = Yii::app()->params['wechat'];
         $wechat = new Wechat($wehcat['appid'], $wehcat['appsecret']);
         $accessToken = $wechat->getAccessToken($code);
         if (!empty($accessToken) && !empty($accessToken['openid'])) {
             $openid = $accessToken['openid'];
             $wechat = new Wechat($wehcat['appid'], $wehcat['appsecret'], $accessToken['access_token']);
             $data = $wechat->getUserInfo($openid);
         }
     } else {
         if (!empty($data)) {
             $data = json_decode(base64_decode($data), 1);
             if (!empty($data['openid'])) {
                 $openid = $data['openid'];
             }
         }
     }
     //都不存在时,创建一个默认帐号
     if (empty($openid)) {
         $openid = 'temp-' . md5(microtime());
         $data = array();
     }
     $user = UserService::instance()->save($openid, $data);
     //登录
     $identity = new UserIdentity($user);
     if ($identity->authenticate()) {
         Yii::app()->user->login($identity, 24 * 3600 * 30);
         $returnUrl = Yii::app()->user->returnUrl;
         $this->redirect(!empty($returnUrl) ? $returnUrl : Yii::app()->homeUrl);
     } else {
         exit('很抱歉,微信授权失败!');
     }
 }
예제 #4
0
 public function pay()
 {
     $wechat_config['app_id'] = "wx82a1bf2cd1bfbba2";
     // 公众号身份标识
     $wechat_config['app_secret'] = "b7b01c0c5e92811d36a716403d3b2515";
     // 权限获取所需密钥 Key
     $wechat_config['pay_sign_key'] = "VxyJYhODSlANB0ezCH4uHsGcSRQ43awQQdeKn20mDv3RajAuHR63rsnsaHXisX8c1PDuqDGtGYmDFpnOmb1VMlMcd19eOqFPfYkmDcxkv4cFd5mUQAdoVMKWJIS9Zmil";
     // 加密密钥 Key,也即appKey
     $wechat_config['partner_id'] = '1220793801';
     // 财付通商户身份标识
     $wechat_config['partner_key'] = '7b7631c5c6db7ccd1f2817d49052501f';
     // 财付通商户权限密钥 Key
     $wechat_config['notify_url'] = 'http://17huaitao.com/wechat_notify.php';
     // 微信支付完成服务器通知页面地址
     $wechat_config['cacert_url'] = dirname(__FILE__) . '/1220793801_20140901150545.pfx';
     //        $total_fee = 0.01; //金额
     //        $params['total_fee'] = $total_fee*100;
     //        $params['body']=to_date(get_gmtime(),"Ymdhis").rand(10,99);
     //        $params['out_trade_no'] = $params['body'];
     $total_fee = $_POST['total_fee'];
     //金额
     $params['total_fee'] = $total_fee * 100;
     //echo "totol_fee=".$params['total_fee']."\n";
     $params['body'] = $_POST['body'];
     //echo "body=".$params['body']."\n";
     $params['out_trade_no'] = $_POST['order_sn'];
     //echo "out_trade_no=".$params['out_trade_no']."\n";
     $params['spbill_create_ip'] = get_client_ip();
     //        $checker = check_deal_order_is_can_buy($params['out_trade_no'],'order_sn');
     //        if($checker['status']==0)
     //        {
     //            $res = array(
     //                'ret'=>'-1',
     //                'msg'=>"商品:".$check['info']."不在可购买时间内",
     //            );
     //            ajax_return($res);
     //        }
     //
     //        $checker = check_deal_number($deal_info_arr[$index]['id'],$deal_info_arr[$index]['number'],"app");
     //        if($checker['status']==0)
     //        {
     //            $res = array(
     //                'ret'=>'-1',
     //                'msg'=>"商品:".$check['info']."库存不足",
     //            );
     //            ajax_return($res);
     //        }
     //
     //echo "spbill_create_ip=".$params['spbill_create_ip']."\n";
     //file_put_contents("/tmp/xiao.log", "\n".date("Y-m-d H:i:s")." params:".json_encode($params)."\n",FILE_APPEND);
     $wechat = new Wechat($wechat_config);
     $access_token = $wechat->getAccessToken();
     //file_put_contents("/tmp/xiao.log", "\n".date("Y-m-d H:i:s")." access_token:".json_encode($access_token)."\n",FILE_APPEND);
     //var_dump($access_token);
     $tran_result = $wechat->createOrder($access_token, $params);
     //file_put_contents("/tmp/xiao.log", "\n".date("Y-m-d H:i:s")." tran_result:".json_encode($tran_result)."\n",FILE_APPEND);
     //var_dump($tran_result);
     if ($tran_result["errmsg"] == 'Success') {
         $info['noncestr'] = $wechat->wechat_noncestr;
         $info['package'] = 'Sign=WXPay';
         $info['partnerid'] = $wechat_config['partner_id'];
         $info['prepayid'] = $tran_result['prepayid'];
         $info['timestamp'] = $wechat->wechat_time;
         $info['appid'] = $wechat_config['app_id'];
         $info['sign'] = $wechat->buildSign($info);
         unset($info['appid']);
         unset($info['package']);
         $info['packageValue'] = 'Sign=WXPay';
         $info['ret'] = '0';
         $info = json_encode($info);
         $info = str_replace('null', '""', $info);
         header('Content-Type:application/json;charset=utf-8');
         header("Access-Control-Allow-Origin:*");
         exit($info);
     } else {
         $info['ret'] = '-1';
         $info = json_encode($info);
         header('Content-Type:application/json;charset=utf-8');
         header("Access-Control-Allow-Origin:*");
         exit($info);
     }
 }
예제 #5
0
<?php

/**
 * 标记客户的投诉处理状态
 * @author www.linauror.com
 * @copyright 2014
 */
include 'config.php';
include 'lib.php';
$wechat = new Wechat();
$data = $wechat->getXmlArray();
// 具体参数可以查看文档
// openid 与 feedback参数都可以从数据库中得到
$result = file_get_contents('http://api.weixin.qq.com/cgi-bin/pay/delivernotify?access_token=' . $wechat->getAccessToken() . '&openid=' . $openid . '&feedbackid=' . $feedbackid);
$result = json_decode($result, true);
if ($result['errcode'] == 0) {
    echo 'success';
} else {
    print_r($result);
}
예제 #6
0
파일: passport.php 프로젝트: beyondye/ENPHP
 /**
  * 微信登录回调
  */
 public function wechatCallback()
 {
     require_once APP_DIR . "vendors/auth/wechat.php";
     $wechat = new \Wechat();
     $code = $this->input->get('code');
     if (!$code) {
         echo 'code error';
         return;
     }
     //授权之后的操作,默认是登录
     $auth_action = $this->input->cookie('auth_action');
     if (!$auth_action) {
         $auth_action = isset($_REQUEST['auth_action']) ? $_REQUEST['auth_action'] : '';
     }
     if ($auth_action) {
         //清楚此临时cookie
         $this->output->cookie(['auth_action' => ''], 0);
     } else {
         $auth_action = 'login';
     }
     //哪个app的操作
     $app = $this->input->cookie('app');
     if ($app) {
         //清楚此临时cookie
         $this->output->cookie(['app' => ''], 0);
     } else {
         $app = 'okay';
     }
     $data = $wechat->getAccessToken($code);
     if (!$data) {
         echo 'access token error';
         return;
     }
     $token = $data['access_token'];
     $openid = $data['openid'];
     $unionid = $data['unionid'];
     $account = $this->related_account->one($unionid);
     $isopenid = false;
     if (!$account) {
         $account = $this->related_account->one($openid);
         $isopenid = true;
     }
     if ($auth_action == 'login') {
         if ($account) {
             // 转移数据
             $this->transferData($account->uid);
             //如果是openid登录替换成unionid
             if ($isopenid) {
                 $this->related_account->update(['app_uid' => $unionid], ['app_uid' => $openid, 'uid' => $account->uid, 'app_id' => $this->config->logintype['wechat']]);
             }
             //查询用户
             $user = $this->user->one($account->uid);
             //执行同步登录(手机,网页,扩展)
             $logindata = $this->helper->user->getUserLoginInfo($user);
             $token = $this->helper->user->setUserLoginCookie($logindata);
             if ($app == 'okay') {
                 $this->model('passport')->login($account->uid, 'password');
                 //方片登录
             } else {
                 /*$info       = array('uid'     => $user->uid,      'mail'     => $user->mail, 
                                                         'nickname'=> $user->nickname, 'signature'=> $user->signature, 'avatar'=>$user->avatar_url);
                 
                 
                                     //过期时间
                                     $time       = 3600 * 24 * 90;
                                     $endtime    = time() + $time;
                 
                 
                                     //授权令牌
                                     $token      = $this->helper->auth->getToken(md5($token . time() . $user->uid . $endtime));
                                     $this->redis('w')->set($token, $info, $endtime);
                 
                 
                                     //数据包
                                     $data       = array('user'  => $info, 'token'  => $token, 'expire' => $endtime );
                                     $this->output->cookie(['token'=>$token], $endtime, '/', '.funp.in', false, true);*/
                 if ($app == 'wechat_website') {
                     $this->output->redirect(MOBILE_API . 'website.php');
                 }
             }
             $token = isset($token) ? $token : null;
             $this->output->view('passport/wechat', ['uid' => $account->uid]);
         } else {
             $userinfo = $wechat->getUserInfo($token, $openid);
             //判断nickname是否存在
             $userinfo['nickname'] = str_replace(' ', '_', trim($userinfo['nickname']));
             if ($this->user->isNicknameExist($userinfo['nickname'])) {
                 $userinfo['nickname'] = $userinfo['nickname'] . '_' . substr(md5(time()), 0, 2);
             }
             $data = ['with_openid' => 1, 'nickname' => trim($userinfo['nickname']), 'created' => time(), 'modified' => time(), 'login_ip' => ip2long($this->input->ip())];
             $uid = $this->user->insert($data);
             if ($uid) {
                 $this->user_config->insert(['uid' => $uid]);
                 // 添加默认标签
                 $this->tag->addDefaultTags($uid);
                 // 转移数据
                 $this->transferData($account->uid);
             }
             //头像放入队列获取
             $this->redis('queue')->lPush('queue:avatar:download', "{$uid}|{$userinfo['headimgurl']}");
             if ($uid) {
                 if ($this->related_account->insert(['uid' => $uid, 'app_uid' => $unionid, 'app_id' => $this->config->logintype['wechat'], 'access_token' => $token])) {
                     //查询用户
                     $user = $this->user->one($uid);
                     //执行同步登录(手机,网页,扩展)
                     $logindata = $this->helper->user->getUserLoginInfo($user);
                     $token = $this->helper->user->setUserLoginCookie($logindata);
                     if ($app == 'okay') {
                         $this->model('passport')->login($account->uid, 'password');
                         //方片登录
                     } else {
                         //查询用户
                         //$user       = $this->user->one($uid);
                         /*$info       = array('uid'     => $user->uid,      'mail'     => $user->mail, 
                                                                         'nickname'=> $user->nickname, 'signature'=> $user->signature, 'avatar'=>$user->avatar_url);
                         
                         
                                                     //过期时间
                                                     $time       = 3600 * 24 * 90;
                                                     $endtime    = time() + $time;
                         
                         
                                                     //授权令牌
                                                     $token      = $this->helper->auth->getToken(md5($token . time() . $user->uid . $endtime));
                                                     $this->redis('w')->set($token, $info, $endtime);
                         
                         
                                                     //数据包
                                                     $data       = array('user'  => $info, 'token'  => $token, 'expire' => $endtime );
                                                     $this->output->cookie(['token'=>$token], $endtime, '/', '.funp.in', false, true);*/
                         //执行同步登录(手机,网页,扩展)
                         //$logindata   = $this->helper->user->getUserLoginInfo($user);
                         //$token       = $this->helper->user->setUserLoginCookie($logindata);
                         if ($app == 'wechat_website') {
                             $this->output->redirect(MOBILE_API . 'website.php');
                         }
                     }
                     $token = isset($token) ? $token : null;
                     $this->output->view('passport/wechat', ['uid' => $uid]);
                 } else {
                     echo 'login error';
                 }
             } else {
                 echo 'login error';
             }
         }
     } else {
         if ($auth_action == 'bind') {
             //得到当前用户
             //$uid = $this->passport->getAuthenticatedUid();
             $userinfo = $this->currentLoginUser();
             $uid = $userinfo['uid'];
             //用户未登录
             if (!$uid) {
                 $this->output->view('passport/bind_failed', ['message' => "请您先登录", 'app' => 'wechat']);
                 exit;
             }
             //检测当前登录用户是否已经绑定了qq账号,如果绑定了则要求解绑
             $result = $this->related_account->select(['where' => ['uid' => $uid]]);
             if ($result && $result[0] && $result[0]->app_id == $this->config->logintype['wechat']) {
                 //已经绑定qq
                 if ($result[0]->app_uid == $openid || $result[0]->app_uid == $unionid) {
                     $this->output->view('passport/bind_failed', ['message' => "您已经绑定此微信账号,无需再次绑定", 'app' => 'wechat']);
                 } else {
                     $this->output->view('passport/bind_failed', ['message' => "您已经绑定其他微信账号,请先解绑,然后绑定新的微信账号", 'app' => 'wechat']);
                 }
                 exit;
             }
             //绑定微信账户
             if ($account) {
                 //如果此账户已经在数据库中存在关联,
                 $user = $this->user->one($account->uid);
                 //如果此微信账号已经绑定邮箱
                 if ($user->mail) {
                     $this->output->view('passport/bind_failed', ['message' => "此账户已经与另一账号绑定,请先解绑另一账户", 'app' => 'wechat']);
                     exit;
                 } else {
                     //将第三方关联到当前用户,
                     if ($this->related_account->update(['uid' => $uid, 'access_token' => $token], ['app_uid' => $unionid, 'uid' => $account->uid, 'app_id' => $this->config->logintype['wechat']])) {
                         //转移数据(贴纸,标签,图片,书签)到当前用户
                         $from = $account->uid;
                         $to = $uid;
                         $this->user->mergeUserData($from, $to);
                         $this->output->view('passport/bind_success', ['app' => 'wechat']);
                     } else {
                         $this->output->view('passport/bind_failed', ['message' => "绑定失败", 'app' => 'wechat']);
                     }
                 }
             } else {
                 if ($this->related_account->insert(['uid' => $uid, 'app_uid' => $unionid, 'app_id' => $this->config->logintype['wechat'], 'access_token' => $token])) {
                     //成功页面
                     $this->output->view('passport/bind_success', ['app' => 'wechat']);
                 } else {
                     $this->output->view('passport/bind_failed', ['message' => "绑定失败", 'app' => 'wechat']);
                     exit;
                 }
             }
         }
     }
 }
예제 #7
0
/** 
 * 微信支付
 * @author funbox www.funboxpower.com
 * @copyright 2014
 */
require 'Wechatconfig.php';
require 'WechatAPISDK.php';
$total_fee = 1.0;
//金额
$params['total_fee'] = $total_fee * 100;
$params['body'] = 'www.funboxpower.com专用充值';
$params['out_trade_no'] = 'WX' . date('YmdHis') . $uid . rand(100, 999);
$params['spbill_create_ip'] = get_client_ip();
$wechat = new Wechat($wechat_config);
$access_token = $wechat->getAccessToken();
$tran_result = $wechat->createOrder($access_token, $params);
if ($tran_result["errmsg"] == 'Success') {
    $info['noncestr'] = $wechat->wechat_noncestr;
    $info['package'] = 'Sign=WXPay';
    $info['partnerid'] = $wechat_config['partner_id'];
    $info['prepayid'] = $tran_result['prepayid'];
    $info['timestamp'] = $wechat->wechat_time;
    $info['appid'] = $wechat_config['app_id'];
    $info['sign'] = $wechat->buildSign($info);
    unset($info['appid']);
    unset($info['package']);
    $info['packageValue'] = 'Sign=WXPay';
    $info = json_encode($info);
    $info = str_replace('null', '""', $info);
    header('Content-Type:application/json;charset=utf-8');