mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-28 21:31:37 +08:00
* Merge branch 'master' of gitee.com:koogua/course-tencent-cloud into develop * Merge branch 'demo' of gitee.com:koogua/course-tencent-cloud into develop * Merge remote-tracking branch 'github/develop' into develop * Merge branch 'develop' of https://gitee.com/koogua/course-tencent-clou… * 更改QQ登录获取ACCESS_TOKEN的请求方式 * Merge branch 'master' into develop * Merge branch 'master' of gitee.com:koogua/course-tencent-cloud into develop * !44 v1.2.1阶段性合并 * 优化开发登录逻辑 * v1.2.1阶段性合并 (#13) * !43 v1.2.0阶段性合并 * Merge branches 'develop' and 'master' of https://gitee.com/koogua/cour… * 优化开发登录,计划任务执行路径,周期 * !41 修复课程分类未过滤2 * !39 修复课程分类未过滤 * Merge branch 'master' of https://gitee.com/koogua/course-tencent-cloud into demo * Merge branch 'master' of https://gitee.com/koogua/course-tencent-cloud… * Merge branch 'develop' of https://gitee.com/koogua/course-tencent-clou… * 优化第三方登录,修复注册密码加密问题 * !33 开放登录阶段性合并 * Merge branch 'xiaochong0302/I280IZ' of https://gitee.com/koogua/course… * Merge remote-tracking branch 'gitee/xiaochong0302/I280IZ' into xiaocho… * 初步完成开放登录,待线上测试7 * !31 开放登录线上测试6 * Merge branch 'demo' of gitee.com:koogua/course-tencent-cloud into xiao… * 初步完成开放登录,待线上测试6 * !30 开放登录线上测试5 * !29 开放登录线上测试5 * 初步完成开放登录,待线上测试5 * !28 开放登录线上测试4 * 初步完成开放登录,待线上测试4 * !27 开放登录线上测试3 * 初步完成开放登录,待线上测试3 * !26 开放登录线上测试2 * 初步完成开放登录,待线上测试2 * !25 开放登录线上测试 * 初步完成开放登录,待线上测试 * !24 修复添加课时后进入编辑页面500错误 * !22 验证更新h5支付 * 更新H5支付方式 * Merge remote-tracking branch 'remotes/gitee/develop' into demo * 更新H5支付方式 * !20 验证更新h5支付 * 更新H5支付方式 * v1.2.0阶段性合并 (#11) * Merge remote-tracking branch 'remotes/gitee/master' into develop * Merge pull request #10 from xiaochong0302/develop * Merge branch 'develop' of https://gitee.com/koogua/course-tencent-clou… * 增加微信H5支付需要的Referer头信息 * Merge pull request #8 from xiaochong0302/develop * !16 v1.2.0阶段性合并 * 删除调试断点代码 * 删除重复的signature方法 * Merge branch 'develop' of https://gitee.com/koogua/course-tencent-clou… * demo后台增加统计 * Merge pull request #5 from xiaochong0302/develop * Merge pull request #3 from xiaochong0302/develop * !5 更新版本号1.1.0 * !4 v1.1.0版本develop->demo * Merge branch 'develop' into demo * 1.增加changelog.md * Merge branch 'develop' into demo * Merge branch 'develop' into demo * Merge branch 'develop' into demo * !1 精简优化代码 * Merge branch 'develop' into demo * 合并修改
116 lines
3.0 KiB
PHP
116 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services\OAuth;
|
|
|
|
use App\Models\Connect as ConnectModel;
|
|
use App\Services\OAuth;
|
|
|
|
class QQ extends OAuth
|
|
{
|
|
|
|
const AUTHORIZE_URL = 'https://graph.qq.com/oauth2.0/authorize';
|
|
const ACCESS_TOKEN_URL = 'https://graph.qq.com/oauth2.0/token';
|
|
const OPENID_URL = 'https://graph.qq.com/oauth2.0/me';
|
|
const USER_INFO_URL = 'https://graph.qq.com/user/get_user_info';
|
|
|
|
public function getAuthorizeUrl()
|
|
{
|
|
$params = [
|
|
'client_id' => $this->clientId,
|
|
'redirect_uri' => $this->redirectUri,
|
|
'state' => $this->getState(),
|
|
'response_type' => 'code',
|
|
'scope' => 'get_user_info',
|
|
];
|
|
|
|
return self::AUTHORIZE_URL . '?' . http_build_query($params);
|
|
}
|
|
|
|
public function getAccessToken($code)
|
|
{
|
|
$params = [
|
|
'code' => $code,
|
|
'client_id' => $this->clientId,
|
|
'client_secret' => $this->clientSecret,
|
|
'redirect_uri' => $this->redirectUri,
|
|
'grant_type' => 'authorization_code',
|
|
];
|
|
|
|
$response = $this->httpGet(self::ACCESS_TOKEN_URL, $params);
|
|
|
|
$this->accessToken = $this->parseAccessToken($response);
|
|
|
|
return $this->accessToken;
|
|
}
|
|
|
|
public function getOpenId($accessToken)
|
|
{
|
|
$params = ['access_token' => $accessToken];
|
|
|
|
$response = $this->httpGet(self::OPENID_URL, $params);
|
|
|
|
$this->openId = $this->parseOpenId($response);
|
|
|
|
return $this->openId;
|
|
}
|
|
|
|
public function getUserInfo($accessToken, $openId)
|
|
{
|
|
$params = [
|
|
'oauth_consumer_key' => $this->clientId,
|
|
'access_token' => $accessToken,
|
|
'openid' => $openId,
|
|
];
|
|
|
|
$response = $this->httpGet(self::USER_INFO_URL, $params);
|
|
|
|
return $this->parseUserInfo($response);
|
|
}
|
|
|
|
protected function parseAccessToken($response)
|
|
{
|
|
$result = [];
|
|
|
|
parse_str($response, $result);
|
|
|
|
if (!isset($result['access_token'])) {
|
|
throw new \Exception("Fetch Access Token Failed:{$response}");
|
|
}
|
|
|
|
return $result['access_token'];
|
|
}
|
|
|
|
protected function parseOpenId($response)
|
|
{
|
|
$result = $matches = [];
|
|
|
|
if (!empty($response)) {
|
|
preg_match('/callback\(\s+(.*?)\s+\)/i', $response, $matches);
|
|
$result = json_decode($matches[1], true);
|
|
}
|
|
|
|
if (!isset($result['openid'])) {
|
|
throw new \Exception("Fetch OpenId Failed:{$response}");
|
|
}
|
|
|
|
return $result['openid'];
|
|
}
|
|
|
|
protected function parseUserInfo($response)
|
|
{
|
|
$data = json_decode($response, true);
|
|
|
|
if (isset($data['ret']) && $data['ret'] != 0) {
|
|
throw new \Exception("Fetch User Info Failed:{$response}");
|
|
}
|
|
|
|
$userInfo['id'] = $this->openId;
|
|
$userInfo['name'] = $data['nickname'];
|
|
$userInfo['avatar'] = $data['figureurl'];
|
|
$userInfo['provider'] = ConnectModel::PROVIDER_QQ;
|
|
|
|
return $userInfo;
|
|
}
|
|
|
|
}
|