文件存储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 出阁宴祝福语姐姐简短