Skip to content

Commit

Permalink
Fix QQ error_description and missing OpenidMode::UNION_ID_FIRST (#18)
Browse files Browse the repository at this point in the history
* Fix QQ error_description

* Fix missing OpenidMode::UNION_ID_FIRST
  • Loading branch information
sy-records authored Dec 7, 2021
1 parent 0f5fe7b commit 3f67cc3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
36 changes: 14 additions & 22 deletions src/QQ/OAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,20 @@ public function getAuthUrl($callbackUrl = null, $state = null, $scope = null)
*/
protected function __getAccessToken($storeState, $code = null, $state = null)
{
$content = $this->http->get($this->getUrl('oauth2.0/token', [
'grant_type' => 'authorization_code',
'client_id' => $this->appid,
'client_secret' => $this->appSecret,
'code' => isset($code) ? $code : (isset($_GET['code']) ? $_GET['code'] : ''),
'state' => isset($state) ? $state : (isset($_GET['state']) ? $_GET['state'] : ''),
'redirect_uri' => $this->getRedirectUri(),
]))->body();
$jsonData = json_decode($content, true);
if ($jsonData)
{
$this->result = $jsonData;
throw new ApiException($jsonData['error_description'], $jsonData['error']);
}
parse_str($content, $result);
$this->result = $result;
if (isset($this->result['code']) && 0 != $this->result['code'])
{
throw new ApiException($this->result['msg'], $this->result['code']);
}
else
{
$this->result = $this->http->get(
$this->getUrl('oauth2.0/token', [
'grant_type' => 'authorization_code',
'client_id' => $this->appid,
'client_secret' => $this->appSecret,
'code' => isset($code) ? $code : (isset($_GET['code']) ? $_GET['code'] : ''),
'state' => isset($state) ? $state : (isset($_GET['state']) ? $_GET['state'] : ''),
'redirect_uri' => $this->getRedirectUri(),
'fmt' => 'json',
])
)->json(true);
if (isset($this->result['error'])) {
throw new ApiException($this->result['error_description'], $this->result['error']);
} else {
return $this->accessToken = $this->result['access_token'];
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/QQ/OpenidMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ class OpenidMode
* 使用unionid.
*/
const UNION_ID = 2;

/**
* 优先使用unionid,否则使用openid.
*/
const UNION_ID_FIRST = 3;
}

0 comments on commit 3f67cc3

Please sign in to comment.