Oauth.class.php
5.2 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/**
* 使用第三方合作账号互联
*
* @name Controller_Oauth
* @package controller
* @copyright yoho.inc
* @version 5.0 (2014-2-12 13:42:44)
* @author fei.hong <fei.hong@yoho.cn>
*/
class Controller_Oauth extends Controller_Abstract
{
const API_NAME_QQ = 'qqconnect';
const API_NAME_SINA = 'sinaweibo';
const API_NAME_RENREN = 'renren';
const API_NAME_DOUBAN = 'douban';
const API_NAME_ALIPAY = 'alipay';
const API_NAME_FACEBOOK = 'facebook';
const API_NAME_INSTAGRAM = 'instagram';
/**
* 初始化
*/
protected function init() {}
/**
* 统一入口
*/
public function indexAction()
{
$t = strtolower(trim($this->_request->t)) ;
if($t == '')
{
return 'Missing Parameter';
}
$fun = $t.'Action';
if (method_exists($this, $fun))
{
return $this->$fun();
}
return 'System Error';
}
/**
* QQ互联: 授权
*/
public function qqAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_QQ);
$apiObj->getAuthorizeUrl();
exit;
}
/**
* QQ互联: 回调
*
* @todo test interface
*/
public function qqcallbackAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_QQ);
$token = $apiObj->getAccessToken();
var_dump($token); exit;
}
/**
* 新浪微博: 授权
*/
public function sinaAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_SINA);
$authorizeUrl = $apiObj->getAuthorizeUrl();
header('Location:' . $authorizeUrl); exit;
}
/**
* 新浪微博:回调
*
* @todo test interface
*/
public function sinacallbackAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_SINA);
$token = $apiObj->getAccessToken();
var_dump($token); exit;
}
/**
* 人人网: 授权
*/
public function renrenAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_RENREN);
$authorizeUrl = $apiObj->getAuthorizeUrl();
header('Location:' . $authorizeUrl); exit;
}
/**
* 人人网: 回调
*
* @todo test interface
*/
public function renrencallbackAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_RENREN);
// 返回object
$token = $apiObj->getAccessToken();
// 返回array, 所括user信息
$tokens = $apiObj->getTokens();
var_dump($token, $tokens); exit;
}
/**
* 豆瓣网: 授权
*/
public function doubanAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_DOUBAN);
$authorizeUrl = $apiObj->getAuthorizeUrl();
header('Location:' . $authorizeUrl); exit;
}
/**
* 豆瓣网: 回调
*
* @todo test interface
*/
public function doubancallbackAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_DOUBAN);
$token = $apiObj->getAccessToken();
var_dump($token); exit;
}
/**
* Facebook: 授权
*/
public function facebookAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_FACEBOOK);
$authorizeUrl = $apiObj->getAuthorizeUrl();
header('Location:' . $authorizeUrl); exit;
}
/**
* Facebook: 回调
*
* @todo test interface
*/
public function facebookcallbackAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_FACEBOOK);
$token = $apiObj->getAccessToken();
var_dump($token); exit;
}
/**
* Instagram: 授权
*/
public function instagramAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_INSTAGRAM);
$authorizeUrl = $apiObj->getAuthorizeUrl();
header('Location:' . $authorizeUrl); exit;
}
/**
* Instagram: 回调
*
* @todo test interface
*/
public function instagramcallbackAction()
{
$apiObj = Lib_Partner_Factory::create(self::API_NAME_INSTAGRAM);
$token = $apiObj->getAccessToken();
$userInfo = $apiObj->getUserInfo($token);
var_dump($token, $userInfo); exit;
}
/**
* 支付宝快捷登录
*/
public function alipayAction()
{
Lib_Partner_Factory::create(self::API_NAME_ALIPAY)->getAuthorizeUrl();
}
/**
* 支付宝快捷登录:回调
*
* @todo test interface
*/
public function alipaycallbackAction()
{
var_dump($this->_request->pathinfo());
if (isset($_GET['oauth/alipaycallback']))
{
unset($_GET['oauth/alipaycallback']);
}
unset($_GET['module'], $_GET['namespace'], $_GET['controller'], $_GET['action']);
$token = Lib_Partner_Factory::create(self::API_NAME_ALIPAY)->getAccessToken();
var_dump($token); exit;
}
}