Login.php
4.84 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
<?php
use Action\AbstractAction;
use Plugin\Partner\Factory;
use LibModels\Wap\Passport\LoginData;
class LoginController extends AbstractAction
{
public function indexAction()
{
$data = array(
'backUrl' => 'm.yohobuy.com',
'showHeaderImg' => true,
'isPassportPage' => true,
'modulePath' => 'passport/login/login'
);
$this->_view->assign('title', '登录');
$this->_view->display('index', $data);
}
public function interationalAction()
{
$data = array(
'backUrl' => 'm.yohobuy.com',
'headerText' => '登录',
'isPassportPage' => true,
'modulePath' => 'passport/login/interational',
'countrys' => array(
array(
'areaCode' => '+86',
'selected' => true,
'name' => '中国'
),
array(
'areaCode' => '+864',
'name' => '中国香港'
)
),
'countryCode' => '+86'
);
$this->_view->assign('title', '国际账号登录');
$this->_view->display('interational', $data);
}
/**
* 支付宝账号登录:授权页面
*/
public function alipayAction()
{
$redirect = $this->_request->getServer('HTTP_REFERER', '');
if($redirect != '')
{
$this->setCookie('alipay_redirect', $redirect);
}
Factory::create('alipay')->getAuthorizeUrl();
exit();
}
/**
* QQ账号登录:授权页面
*/
public function qqAction()
{
$redirect = $this->_request->getServer('HTTP_REFERER', '');
if($redirect != '')
{
$this->setCookie('qq_redirect', $redirect);
}
Factory::create('qqconnect')->getAuthorizeUrl();
exit();
}
/**
* 新浪微博账号登录:授权页面
*/
public function sinaAction()
{
$redirect = $this->_request->getServer('HTTP_REFERER', '');
if($redirect != '')
{
$this->setCookie('sina_redirect', $redirect);
}
header('Location:' . Factory::create('sinaweibo')->getAuthorizeUrl());
exit();
}
/**
* 支付宝账号登录:回调方法
*/
public function alipaycallbackAction()
{
$nickname = '';
$alipay = Factory::create('alipay');
$access = $alipay->getAccessToken();
if (!isset($_GET['real_name']))
{
/* 获取支付宝用户的详细信息 */
$userInfo = $alipay->getUserInfo($access);
if ($userInfo && $userInfo['is_success'] === 'T' && isset($userInfo['response']['user_info']['user_name']))
{
$nickname = $userInfo['response']['user_info']['user_name'];
$alipayEmail = $userInfo['response']['user_info']['email'];
}
var_dump($userInfo);
}
else
{
$nickname = $_GET['real_name'];
$alipayEmail = isset($_GET['email']) ? $_GET['email'] : '';
}
var_dump($access);
$result = LoginData::signinByOpenID($nickname, $access['user_id'], 'qq');
if($result['code'] == 200)
{
$redirect = $this->_request->getCookie('alipay_redirect');
$redirect && $this->redirect($redirect);
}
$this->redirect('/');
}
/**
* QQ账号登录:回调方法
*/
public function qqcallbackAction()
{
$qqconnect = Factory::create('qqconnect');
$access = $qqconnect->getAccessToken();
/* 获取QQ腾讯用户的详细信息 */
$partnerInfo = $qqconnect->getUserInfo($access);
if ($partnerInfo && is_array($partnerInfo))
{
$result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['openid'], 'qq');
if($result['code'] == 200)
{
$redirect = $this->_request->getCookie('qq_redirect');
$redirect && $this->redirect($redirect);
}
}
$this->redirect('/');
}
/**
* 新浪微博账号登录:回调方法
*/
public function sinacallbackAction()
{
$sina = Factory::create('sina');
$access = $sina->getAccessToken();
/* 获取QQ腾讯用户的详细信息 */
$partnerInfo = $sina->getUserInfo($access);
if ($partnerInfo && is_array($partnerInfo))
{
$result = LoginData::signinByOpenID($partnerInfo['screen_name'], $access['uid'], 'sina');
if($result['code'] == 200)
{
$redirect = $this->_request->getCookie('sina_redirect');
$redirect && $this->redirect($redirect);
}
}
$this->redirect('/');
}
}