Skip to content

Commit

Permalink
fix: wechat oauth scope为snsapi_base getRaw返回空数组 (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
153264 authored Sep 27, 2024
1 parent de873da commit 1baae73
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Providers/WeChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected function getTokenUrl(): string
public function userFromCode(string $code): Contracts\UserInterface
{
if (\in_array('snsapi_base', $this->scopes)) {
return $this->mapUserToObject($this->fromJsonBody($this->getTokenFromCode($code)));
return $this->getSnsapiBaseUserFromCode($code);
}

$token = $this->tokenFromCode($code);
Expand All @@ -128,6 +128,19 @@ public function userFromCode(string $code): Contracts\UserInterface
->setTokenResponse($token);
}

protected function getSnsapiBaseUserFromCode(string $code): Contracts\UserInterface
{
$token = $this->fromJsonBody($this->getTokenFromCode($code));
$user = [
'openid' => $token['openid'],
];
if (isset($token['unionid'])) {
$user['unionid'] = $token['unionid'];
}

return $this->mapUserToObject($token)->setProvider($this)->setRaw($user)->setAccessToken($token[$this->accessTokenKey]);
}

protected function getUserByToken(string $token): array
{
$language = $this->withCountryCode ? null : (isset($this->parameters['lang']) ? $this->parameters['lang'] : 'zh_CN');
Expand Down

0 comments on commit 1baae73

Please sign in to comment.