文件存储access_token

functiongetAccessToken(){
//access_token应该全局存储与更新,以下代码以写入到文件中做示例
$data=json_decode(file_get_contents("access_token.json"));
if($data->expire_time<time()){
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
$res=json_decode($this->httpGet($url));
$access_token=$res->access_token;
if($access_token){
$data->expire_time=time()+7000;
$data->access_token=$access_token;
$fp=fopen("access_token.json","w");
fwrite($fp,json_encode($data));
fclose($fp);
}
}else{
$access_token=$data->access_token;
}
return$access_token;
}


感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

热门推荐

1 部门过年祝福语简短独特
2 访贫问苦祝福语简短句子
3 生日祝福语简短霸气男
4 新年祝福语大全简短成语
5 填志愿的祝福语简短
6 朋友出国读书祝福语简短
7 妈妈生日祝福语卡片简短
8 祝福语美甲店文案简短幽默
9 微信立冬祝福语简短
10 毛笔哥哥结婚祝福语简短
11 向国庆送祝福语简短
12 建队节祝福语简短
13 朋友喜得外孙简短祝福语
14 小店营业的祝福语简短
15 餐饮生日祝福语简短独特
16 鲜花英语祝福语卡片简短
17 男朋友暴富祝福语简短
18 婶婶拜年祝福语大全简短