微信那边的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%
如何编写一个chrome插件实现多线程高速下载大文件?
cdn版本的vue在网页中出现typeerror错误无法找到错误代码位置怎么办?
pywebview能否使用webrtc远程控制共享桌面和摄像头?
pywebview6.0如何让窗体接受拖拽文件获取真实的文件路径?
如何在linux系统中同时能安装运行apk的安卓应用?
python有没有离线验证码识别ocr库?
各家的ai图生视频及文生视频的api价格谁最便宜?
openai、gemini、qwen3-vl、Doubao-Seed-1.6在ui截图视觉定位这款哪家更强更准?
如何在linux上创建一个沙箱隔离的目录让python使用?
pywebview如何使用浏览器自带语音识别与webspeech 的api?