使用微信第三方授权,获取api_component_token错误。

错误提示

1
errcode:40001 errmsg:invalid credential, access_token is invalid or not latest hint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
private function _get_component_access_token(){

$url = 'https://api.weixin.qq.com/cgi-bin/component/api_component_token';
$data = '{' . "\r\n"
. ' "component_appid":"'
. $this->appId . '" ,'
. "\r\n" . '"component_appsecret": "'
. $this->appSecret . '", '
. "\r\n" . '"component_verify_ticket": "'
. $this->component_verify_ticket . '"' . "\r\n" . '}';

$res = $this->https_request($url, $data);
return $res;
}

原因

测试环境和线上环境同时使用时相同的开发平台app_id
测试环境连接测试数据库。
线上环境连接线上数据库。
api_component_token是保存在对应的数据库的。
测试环境刷新了api_component_token后,线上环境的api_component_token只能使用5分钟。而且这时候线上环境的token过期时间还未到,不会自动刷新。