当前位置: 首页>>代码示例>>PHP>>正文


PHP Wechat::getAccessToken方法代码示例

本文整理汇总了PHP中Wechat::getAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP Wechat::getAccessToken方法的具体用法?PHP Wechat::getAccessToken怎么用?PHP Wechat::getAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Wechat的用法示例。


在下文中一共展示了Wechat::getAccessToken方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updatefeedback

 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']);
     }
 }
开发者ID:dlpc,项目名称:weixinshop,代码行数:32,代码来源:wxpay_rightsAction.class.php

示例2: getAccessToken

 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'];
     }
 }
开发者ID:Molly2Molly,项目名称:fiance,代码行数:43,代码来源:WxAccessTokenModel.class.php

示例3: actionWechat

 /**
  * 授权回调
  * @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('很抱歉,微信授权失败!');
     }
 }
开发者ID:vikaanet,项目名称:v5,代码行数:46,代码来源:OauthController.php

示例4: pay

 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);
     }
 }
开发者ID:YouthAndra,项目名称:huaitaoo2o,代码行数:82,代码来源:wxpayModule.class.php

示例5: Wechat

<?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);
}
开发者ID:dlpc,项目名称:weixinshop,代码行数:20,代码来源:updatefeedback.php

示例6: wechatCallback

 /**
  * 微信登录回调
  */
 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);
//.........这里部分代码省略.........
开发者ID:beyondye,项目名称:ENPHP,代码行数:101,代码来源:passport.php

示例7: date

/** 
 * 微信支付
 * @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');
开发者ID:waibo,项目名称:wechat_app_pay,代码行数:30,代码来源:pay.php


注:本文中的Wechat::getAccessToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。