微信 getAccessToken方法详解及实例
网络编程 2021-07-05 08:23www.168986.cn编程入门
这篇文章主要介绍了微信 getAessToken方法详解及实例的相关资料,这里提供了简单的实例代码,需要的朋友可以参考下
memcache缓存存储用户信息7000秒
<?php function getAessToken($appid,$appsecret) { $mem = new CacheMemcache(); $a = $mem->get('aess_token_'.$appid); if (!$a) { $url = "https://api.weixin.qq./cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret"; $result = https_request($url); $jsoninfo = json_decode($result, true); $aess_token = $jsoninfo['aess_token']; if ($aess_token) { $expire = time() + 7000; $mem = new CacheMemcache(); $mem->set('aess_token_'.$appid,$aess_token,$expire); } } else { $aess_token = $a; } return $aess_token; } ?>
文件存储aess_token
function getAessToken() { // aess_token 应该全局存储与更新,以下代码以写入到文件中做示例 $data = json_decode(file_get_contents("aess_token.json")); if ($data->expire_time < time()) { $url = "https://api.weixin.qq./cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret"; $res = json_decode($this->httpGet($url)); $aess_token = $res->aess_token; if ($aess_token) { $data->expire_time = time() + 7000; $data->aess_token = $aess_token; $fp = fopen("aess_token.json", "w"); fwrite($fp, json_encode($data)); fclose($fp); } } else { $aess_token = $data->aess_token; } return $aess_token; }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
上一篇:微信 开发生成带参数的二维码的实例
下一篇:Yii核心验证器api详解
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程