微信那边的acces_token有效期为7200秒,一天调用2000次,如果程序访问量上来后,会无法获取access_token,请问有什么办法?
网友回复
可以写个定时任务,定时更新token,将新token保存到文件中或redis、数据库中。
<?php $AppID = "123123"; $AppSecret = "123123"; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$AppID."&secret=".$AppSecret; $result = http_request($url); $tokendata = json_decode($result, 1); if (isset($tokendata['access_token'])) { $dir = __DIR__; //真实路径,crontab命令的php执行在cli模式下,不能正确识别相对路径,所以使用__DIR__ $filename = $dir."/access_token.ini"; create_file($filename, $tokendata['access_token']); } else...
点击查看剩余70%
<?php /** * 获取 access_tonken值 * @param string $token_file 用来存储的文件 * @return access_token */ function getAccessToken($token_file = 'access_token_file') { //处理是否过期问题,将access_token存储到文件 $life_time = 7200; if (file_exists($token_file) && time() - filemtime($token_file) < $life_time) { // 存在有效的access_token 直接返回文件内容 return file_get_contents($token_file); } //接口URL $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->_appid."&secret=".$this->_appsecret; //发送GET请求 $result = _request('get', $url); if (!$result) { return false; } //处理数据 $result_obj = json_decode($result); //写入到文件 file_put_contents($token_file, $result_obj->access_toke...
点击查看剩余70%
python如何实现torrent的服务端进行文件分发p2p下载?
如何在浏览器中录制摄像头和麦克风数据为mp4视频保存下载本地?
go如何编写一个类似docker的linux的虚拟容器?
python如何写一个bittorrent的种子下载客户端?
ai能通过看一个网页的交互过程视频自主模仿复制网页编写代码吗?
ai先写功能代码通过chrome mcp来进行测试功能最后ai美化页面这个流程能行吗?
vue在手机端上下拖拽元素的时候如何禁止父元素及body的滚动导致无法拖拽完成?
使用tailwindcss如何去掉响应式自适应?
有没有直接在浏览器中运行的离线linux系统?
nginx如何保留post或get数据进行url重定向?