微信公众平台40001错误 invalid credential, access_token is invalid or not latest hint
2018-01-04 12:52
906 查看
网站微信公众平台老是报错 {"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest hint: [70D7Ma0416vr70!]"} ,应该是access_token过期了,但直接用浏览器访问$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
这个地址获取的access_token是正常的。
因为网站的access_token是缓存在数据库中的,用这个函数获取和更新的。发现即使新获取的access_token也是立即过期,很纳闷。
public function get_access_token($db)
{
$ret = $db->getRow("SELECT * FROM `wxch_config` WHERE `id` = 1");
$appid = $ret['appid']; //AppId 18
$appsecret = $ret['appsecret'];//AppSecret 32
$dateline = $ret['dateline'];
$time = time();
if(($time - $dateline) > 7200)
{
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
$ret_json = $this->curl_get_contents($url); //access_token 150
$ret = json_decode($ret_json);
if($ret->access_token){
$db->query("UPDATE `wxch_config` SET `access_token` = '$ret->access_token',`dateline` = '$time' WHERE `wxch_config`.`id` =1;");
}
}
return $db->getOne("SELECT access_token FROM `wxch_config` WHERE `id` = 1");
}
突然发现,直接浏览器访问获取的 access_token 和 保存在数据库中的access_token长度不一样。
浏览器里:5_kaRdp42zead-_QRaArOEKTeNhNDWCdceXKiVv5QnyDiFuXS30KXnffvj9-hy6fN_UM-AS5OQGSlMOvNUn-psWIk0uQUpDT5oTmqtS_kohnZ88QrrUyiuV47bC7crsWV-o6o2FGQOxi_C5TeiLTIdACAVDS
数据库里保存的:5_kaRdp42zead-_QRaArOEKTeNhNDWCdceXKiVv5QnyDiFuXS30KXnffvj9-hy6fN_UM-AS5OQGSlMOvNUn-psWIk0uQUpDT5oTmqtS_kohnZ88QrrUyiuV47bC7crsWV-o6o2FGQOxi_C5TeiLTId
原来是数据库定义的长度是150 ,获取的access_token的长度是156
估计微信那边又调整access_token的长度了
把数据库中access_token长度改为156 , 问题解决。
这个地址获取的access_token是正常的。
因为网站的access_token是缓存在数据库中的,用这个函数获取和更新的。发现即使新获取的access_token也是立即过期,很纳闷。
public function get_access_token($db)
{
$ret = $db->getRow("SELECT * FROM `wxch_config` WHERE `id` = 1");
$appid = $ret['appid']; //AppId 18
$appsecret = $ret['appsecret'];//AppSecret 32
$dateline = $ret['dateline'];
$time = time();
if(($time - $dateline) > 7200)
{
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
$ret_json = $this->curl_get_contents($url); //access_token 150
$ret = json_decode($ret_json);
if($ret->access_token){
$db->query("UPDATE `wxch_config` SET `access_token` = '$ret->access_token',`dateline` = '$time' WHERE `wxch_config`.`id` =1;");
}
}
return $db->getOne("SELECT access_token FROM `wxch_config` WHERE `id` = 1");
}
突然发现,直接浏览器访问获取的 access_token 和 保存在数据库中的access_token长度不一样。
浏览器里:5_kaRdp42zead-_QRaArOEKTeNhNDWCdceXKiVv5QnyDiFuXS30KXnffvj9-hy6fN_UM-AS5OQGSlMOvNUn-psWIk0uQUpDT5oTmqtS_kohnZ88QrrUyiuV47bC7crsWV-o6o2FGQOxi_C5TeiLTIdACAVDS
数据库里保存的:5_kaRdp42zead-_QRaArOEKTeNhNDWCdceXKiVv5QnyDiFuXS30KXnffvj9-hy6fN_UM-AS5OQGSlMOvNUn-psWIk0uQUpDT5oTmqtS_kohnZ88QrrUyiuV47bC7crsWV-o6o2FGQOxi_C5TeiLTId
原来是数据库定义的长度是150 ,获取的access_token的长度是156
估计微信那边又调整access_token的长度了
把数据库中access_token长度改为156 , 问题解决。
相关文章推荐
- bug: {"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest hint: xxx
- 微信报错: [40001,"invalid credential, access_token is invalid or not latest hint: [BzKHIa0609vr29!]"]
- [微信开发]invalid credential, access_token is invalid or not latest hint
- 微信图片上传 invalid credential, access_token is invalid or not latest
- 微信接口开发报错invalid credential, access_token is invalid or not latest hint
- 微信接口开发报错invalid credential, access_token is invalid or not latest hint
- 错误信息:Bean property 'sessionFactory' is not writable or has an invalid setter method.
- Spring配置文件加载时出现Bean property 'newscontentDAO' is not writable or has an invalid setter method错误的解决
- 关于创建FLex项目时候的 Cannot access the web server. The server may not be running, or the web root folder or root URL may be invalid.错误
- SSH框架 Bean property * is not writable or has an invalid setter method错误分析与解决方法
- is not writable or has an invalid setter method错误的解决
- SSH框架 Bean property * is not writable or has an invalid setter method错误分析与解决方法
- is not writable or has an invalid setter method错误
- Spring配置文件加载时出现Bean property 'newscontentDAO' is not writable or has an invalid setter method错误的解决[00原创]
- 安装Visual Studio 2010时提示"The location specified for the help content store is invalid or you do not have access to it".
- 在创建一个Dialog时,发生的错误: Unable to add window -- token null is not for an application
- Solution to "Could not load file or assembly or one of its dependencies. Access is denied"
- 错误:Unable to add window -- token null is not for an application
- Unable to add window -- token null is not for an application错误的解决方法 android开发