overtrue / laravel-wechat

微信 SDK for Laravel, 基于 overtrue/wechat
MIT License
2.88k stars 502 forks source link

获取access_token过期之后不自动刷新 #475

Open RJustice opened 1 year ago

RJustice commented 1 year ago

laravel-wechat 版本: 7.2 Laravel版本: 10 Laravel设置缓存derive : redis

正常清除缓存之后可以正常访问, 查看缓存过期时间1500. 使用配置:

$config = [
            'app_id' => "xxxx",
            'secret' => "xxxx",
            'http' => [
                'timeout' => 5.0,
                'retry' => true,
            ],
        ];

        $app = EasyWeChat::officialAccount()
                         ->setConfig(new Config($config));

        $api = $app->getClient();

设置 use_stable_access_tokenfalse,

当第一次请求之后, 经过缓存时间过期之后就出现了 access_token 过期, 未自动刷新

 {
    "errcode": 40001,
     "errmsg": "invalid credential, access_token is invalid or not latest, could get access_token by getStableAccessToken, more details at https://mmbizurl.cn/s/JtxxFh33r rid: 6497fc3d-2a485f40-20e51066"
}

是否需要自动判断出现 40001 错误码, 使用 $app->getAccessToken()->refresh() , 或者改用 use_stable_access_token

LixHu commented 1 year ago

同样遇到了,报错之后进行刷新又获取了一次,才有效