作者 jinglong
1 个管道 的构建 通过 耗费 0 秒

调式微信分享

@@ -554,20 +554,28 @@ class LoginController extends HomeBaseController @@ -554,20 +554,28 @@ class LoginController extends HomeBaseController
554 return $str; 554 return $str;
555 } 555 }
556 556
557 - //获取微信分享签名  
558 - public function getSignature(){ 557 + //获取access_token
  558 + public function getWxAccessToken(){
559 $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$this->appkey2.'&secret='.$this->appsecret2; 559 $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$this->appkey2.'&secret='.$this->appsecret2;
560 $res = $this->http_get($url); 560 $res = $this->http_get($url);
561 $json_arr = json_decode($res,true); 561 $json_arr = json_decode($res,true);
562 - if(isset($json_arr['errcode'])&&!empty($json_arr['errcode'])){  
563 - //用户取消登录  
564 - $this->apiResponse(0, '获取配置失败');  
565 - }  
566 $token = $json_arr['access_token']; 562 $token = $json_arr['access_token'];
  563 + return $token;
  564 + }
  565 +
  566 + //获取微信分享签名
  567 + public function getSignature(){
  568 + if($_SESSION['ticket_expire_time'] > time() && $_SESSION['ticket']){
  569 + $ticket = $_SESSION['ticket'];
  570 + }else{
  571 + $token = $this->getWxAccessToken();
567 $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$token.'&type=jsapi'; 572 $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$token.'&type=jsapi';
568 $res = $this->http_get($url); 573 $res = $this->http_get($url);
569 $json_arr = json_decode($res,true); 574 $json_arr = json_decode($res,true);
570 $ticket = $json_arr['ticket']; 575 $ticket = $json_arr['ticket'];
  576 + $_SESSION['ticket'] = $ticket;
  577 + $_SESSION['ticket_expire_time'] = time()+7000;
  578 + }
571 return $ticket; 579 return $ticket;
572 } 580 }
573 581
@@ -62,13 +62,12 @@ @@ -62,13 +62,12 @@
62 } 62 }
63 }); 63 });
64 wx.config({ 64 wx.config({
65 - debug: false, 65 + debug: true,
66 appId: appid, 66 appId: appid,
67 timestamp: timestamp, 67 timestamp: timestamp,
68 nonceStr: nonceStr, 68 nonceStr: nonceStr,
69 signature: signature, 69 signature: signature,
70 jsApiList: [ 70 jsApiList: [
71 - 'checkJsApi',  
72 'updateAppMessageShareData', 71 'updateAppMessageShareData',
73 ] 72 ]
74 }); 73 });