EasyWechat 代公众号发起网页授权(急)
Github(issue),Google,都进行搜索过了,没有找到相应的解决办法
PHP版本:7.4
Laravel版本:7.30.1
包版本说明:
错误提示:
{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest, hints: [ req_id: CFOF69Nre-so7btA ]"}
问题:
追踪到代码是在/vendor/overtrue/socialite/src/Providers/WeChat.php
通过 code 换取 access_token 时提示 access_token 异常。
/**
* @param string $code
*
* @return \Psr\Http\Message\ResponseInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getTokenFromCode(string $code): ResponseInterface
{
return $this->getHttpClient()->get($this->getTokenUrl(), [
'headers' => ['Accept' => 'application/json'],
'query' => $this->getTokenFields($code),
]);
}
发起授权是可以的:
到回调页去获取用户的信息时提示:40001 错误。我调用别的接口是可以的就是网页授权不行。
获取用户信息使用的方法:
$officialAccount = $this->openPlatform->officialAccount(config('wechat.open_platform.officialAccount.app_id'), config('wechat.open_platform.officialAccount.refresh_token'));
$userinfo = $officialAccount->oauth->userFromCode($code);
session(['wechat.oauth_user.default' => $userinfo]);
最后决定放弃使用这个版本的包,使用
"overtrue/laravel-wechat:5.0
,可以正常使用。晚上研究一下到底是什么问题导致。