//获取Access_Token
private function getWxAccessToken(){
$res = json_decode(cache('access_token'),true);//获取缓存
if($res !== null && $res["access_token"] && $res["expires_in"]>time()){
return $res['access_token'];
}else {
$lturl="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->appid."&secret=".$this->secret;
//初始化
$ch = curl_init();
//2.设置url 的参数
curl_setopt($ch,CURLOPT_URL,$lturl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//不需要安全检验证书
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//3.采集
$res = curl_exec($ch);
if ( curl_errno($ch)){
var_dump(curl_error($ch));
}
//4.关闭
curl_close($ch);
$arr = json_decode($res,true);
if($arr !== null && $arr['access_token'] ){
$arr['expires_in'] = $arr['expires_in'] +time();
//将access_token 全局缓存
cache('access_token',json_encode($arr));
return $arr['access_token'];
}else {
exit('微信获取acess_token 失败');
}
var_dump($arr);
}
}
05-09
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交