微信那边的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%
如何写ai提示词让大模型根据主题生成视频脚本json,然后让Hyperframe渲染出mp4视频?
有哪些字体使用等宽编程代码展示?
如果让演唱会歌迷的上万手机屏幕和闪光灯一起被现场中控控制闪烁?
Midjourney为啥进军医疗领域了?
python如何跟踪足球比赛指定球员全场运动标注打聚光灯合成
如何将linux服务器的文件目录映射到windows电脑磁盘?
Docling 与 MarkItDown 两个库有啥不同?
豆包收费后国产其他ai软件也会跟进收费吗?
JPEG 与 HEIF图片格式区别?
centos7版本太旧无法安装python3.11,如何在docker中运行python3.11?


