-
Notifications
You must be signed in to change notification settings - Fork 0
/
QQ.php
44 lines (32 loc) · 1.16 KB
/
QQ.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* @author gaobinzhan <gaobinzhan@gmail.com>
*/
class QQ
{
public function index()
{
$config = new \OAuth\QQ\Config();
$config->setAppId('appid');
$config->setState('easyswoole');
$config->setRedirectUri('redirect_uri');
$oauth = new \OAuth\QQ\OAuth($config);
$url = $oauth->getAuthUrl();
return $this->response()->redirect($url);
}
public function callback()
{
$params = $this->request()->getQueryParams();
$config = new \OAuth\QQ\Config();
$config->setAppId('appid');
$config->setAppKey('appkey');
$config->setRedirectUri('redirect_uri');
$oauth = new \OAuth\QQ\OAuth($config);
$accessToken = $oauth->getAccessToken('easyswoole', $params['state'], $params['code']);
$refreshToken = $oauth->getAccessTokenResult()['refresh_token'];
$userInfo = $oauth->getUserInfo($accessToken);
var_dump($userInfo);
if (!$oauth->validateAccessToken($accessToken)) echo 'access_token 验证失败!' . PHP_EOL;
if (!$oauth->refreshToken($refreshToken)) echo 'access_token 续期失败!' . PHP_EOL;
}
}