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

调式微信分享

... ... @@ -554,20 +554,28 @@ class LoginController extends HomeBaseController
return $str;
}
//获取微信分享签名
public function getSignature(){
//获取access_token
public function getWxAccessToken(){
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$this->appkey2.'&secret='.$this->appsecret2;
$res = $this->http_get($url);
$json_arr = json_decode($res,true);
if(isset($json_arr['errcode'])&&!empty($json_arr['errcode'])){
//用户取消登录
$this->apiResponse(0, '获取配置失败');
}
$token = $json_arr['access_token'];
return $token;
}
//获取微信分享签名
public function getSignature(){
if($_SESSION['ticket_expire_time'] > time() && $_SESSION['ticket']){
$ticket = $_SESSION['ticket'];
}else{
$token = $this->getWxAccessToken();
$url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$token.'&type=jsapi';
$res = $this->http_get($url);
$json_arr = json_decode($res,true);
$ticket = $json_arr['ticket'];
$_SESSION['ticket'] = $ticket;
$_SESSION['ticket_expire_time'] = time()+7000;
}
return $ticket;
}
... ...
... ... @@ -62,13 +62,12 @@
}
});
wx.config({
debug: false,
debug: true,
appId: appid,
timestamp: timestamp,
nonceStr: nonceStr,
signature: signature,
jsApiList: [
'checkJsApi',
'updateAppMessageShareData',
]
});
... ...