文件存储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 爱生日祝福语简短独特