forked from xjflyttp/yii2-oauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeiboAuth.php
58 lines (48 loc) · 1.16 KB
/
WeiboAuth.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace xj\oauth;
use yii\authclient\OAuth2;
/**
* Sina Weibo OAuth
* @author xjflyttp <[email protected]>
*/
class WeiboAuth extends OAuth2 implements IAuth
{
public $authUrl = 'https://api.weibo.com/oauth2/authorize';
public $tokenUrl = 'https://api.weibo.com/oauth2/access_token';
public $apiBaseUrl = 'https://api.weibo.com';
/**
*
* @return []
* @see http://open.weibo.com/wiki/Oauth2/get_token_info
* @see http://open.weibo.com/wiki/2/users/show
*/
protected function initUserAttributes()
{
return $this->api('oauth2/get_token_info', 'POST');
}
/**
* get UserInfo
* @return []
* @see http://open.weibo.com/wiki/2/users/show
*/
public function getUserInfo()
{
return $this->api("2/users/show.json", 'GET', ['uid' => $this->getOpenid()]);
}
/**
* @return int
*/
public function getOpenid()
{
$attributes = $this->getUserAttributes();
return $attributes['uid'];
}
protected function defaultName()
{
return 'Weibo';
}
protected function defaultTitle()
{
return 'Weibo';
}
}