Authored by xiaowei

第三方手机登录

@@ -20,16 +20,16 @@ class BindData @@ -20,16 +20,16 @@ class BindData
20 /** 20 /**
21 * 绑定前检查 21 * 绑定前检查
22 * @param string $openId 第三方唯一识别码 22 * @param string $openId 第三方唯一识别码
23 - * @param string $sourceType 登录方式  
24 - * @param string $clientType 所属客户端类型 23 + * @param string $sourceType 登录方式 qq,sina,alipay,wechat
  24 + * @param string $mobile 绑定输入手机号
25 * @return array 登录返回结果 25 * @return array 登录返回结果
26 */ 26 */
27 - public static function bindCheck($openId, $sourceType) 27 + public static function bindCheck($mobile, $openId, $sourceType)
28 { 28 {
29 $param = Yohobuy::param(); 29 $param = Yohobuy::param();
30 30
31 - $param['v'] = '7';  
32 $param['method'] = 'app.passport.check'; 31 $param['method'] = 'app.passport.check';
  32 + $param['mobile'] = $mobile;
33 $param['open_id'] = $openId; 33 $param['open_id'] = $openId;
34 $param['source_type'] = $sourceType; 34 $param['source_type'] = $sourceType;
35 $param['client_secret'] = Sign::getSign($param); 35 $param['client_secret'] = Sign::getSign($param);
@@ -46,7 +46,6 @@ class BindData @@ -46,7 +46,6 @@ class BindData
46 { 46 {
47 $param = Yohobuy::param(); 47 $param = Yohobuy::param();
48 48
49 - $param['v'] = '7';  
50 $param['method'] = 'app.passport.smsbind'; 49 $param['method'] = 'app.passport.smsbind';
51 $param['mobile'] = $mobile; 50 $param['mobile'] = $mobile;
52 $param['client_secret'] = Sign::getSign($param); 51 $param['client_secret'] = Sign::getSign($param);
@@ -62,7 +61,6 @@ class BindData @@ -62,7 +61,6 @@ class BindData
62 { 61 {
63 $param = Yohobuy::param(); 62 $param = Yohobuy::param();
64 63
65 - $param['v'] = '7';  
66 $param['method'] = 'app.register.validRegCode'; 64 $param['method'] = 'app.register.validRegCode';
67 $param['mobile'] = $mobile; 65 $param['mobile'] = $mobile;
68 $param['code'] = $code; 66 $param['code'] = $code;
@@ -77,19 +75,23 @@ class BindData @@ -77,19 +75,23 @@ class BindData
77 * @param string $openId 第三方唯一识别码 75 * @param string $openId 第三方唯一识别码
78 * @param string $sourceType 登录方式 76 * @param string $sourceType 登录方式
79 * @param string $mobile 手机号 77 * @param string $mobile 手机号
  78 + * @param string $area 国别码
80 * @param string $password 密码 79 * @param string $password 密码
81 */ 80 */
82 - public static function bindMobile($openId, $nickname, $sourceType, $mobile, $password) 81 + public static function bindMobile($openId, $nickname, $sourceType, $mobile, $area, $password = '')
83 { 82 {
84 $param = Yohobuy::param(); 83 $param = Yohobuy::param();
85 84
86 - $param['v'] = '7';  
87 $param['method'] = 'app.passport.bind'; 85 $param['method'] = 'app.passport.bind';
88 $param['mobile'] = $mobile; 86 $param['mobile'] = $mobile;
89 - $param['passport'] = $password;  
90 $param['open_id'] = $openId; 87 $param['open_id'] = $openId;
91 $param['nickname'] = $nickname; 88 $param['nickname'] = $nickname;
92 $param['source_type'] = $sourceType; 89 $param['source_type'] = $sourceType;
  90 + $param['area'] = $area;
  91 + if (!empty($password))
  92 + {
  93 + $param['passport'] = $password;
  94 + }
93 95
94 $param['client_secret'] = Sign::getSign($param); 96 $param['client_secret'] = Sign::getSign($param);
95 97
@@ -66,7 +66,6 @@ class LoginData @@ -66,7 +66,6 @@ class LoginData
66 // 构建必传参数 66 // 构建必传参数
67 $param = Yohobuy::param(); 67 $param = Yohobuy::param();
68 68
69 - $param['v'] = '7'; // 只有早期的V4版本才有直接生成UID  
70 $param['method'] = 'app.passport.signinByOpenID'; 69 $param['method'] = 'app.passport.signinByOpenID';
71 $param['openId'] = $openId; 70 $param['openId'] = $openId;
72 $param['source_type'] = $sourceType; 71 $param['source_type'] = $sourceType;
1 <?php 1 <?php
2 2
3 use Action\AbstractAction; 3 use Action\AbstractAction;
4 -use LibModels\Wap\Passport\LoginData;  
5 -use LibModels\Wap\Passport\RegData; 4 +use LibModels\Wap\Passport\BindData;
6 use Plugin\Helpers; 5 use Plugin\Helpers;
7 -use Plugin\Partner\Factory;  
8 6
9 /** 7 /**
10 * 登录的控制器 8 * 登录的控制器
@@ -17,61 +15,233 @@ class BindController extends AbstractAction @@ -17,61 +15,233 @@ class BindController extends AbstractAction
17 */ 15 */
18 public function indexAction() 16 public function indexAction()
19 { 17 {
20 -  
21 $this->setTitle('绑定手机号'); 18 $this->setTitle('绑定手机号');
22 - 19 + $openId = $this->get('openId');
  20 + $sourceType = $this->get('sourceType');
  21 + $nickName = $this->get('nickName');
23 $data = array( 22 $data = array(
24 - 'loginIndex' => true, // 模板中使用JS的标识  
25 - 'backUrl' => '/', // 返回的URL链接  
26 - 'showHeaderImg' => true, // 控制显示头部图片  
27 - 'isPassportPage' => true, // 模板中模块标识  
28 - 'registerUrl' => '/reg.html', // 注册的URL链接  
29 - 'aliLoginUrl' => '/passport/login/alipay', // 支付宝快捷登录的URL链接  
30 - 'weiboLoginUrl' => '/passport/login/sina', // 微博登录的URL链接  
31 - 'qqLoginUrl' => '/passport/login/qq', // 腾讯QQ登录的URL链接  
32 - 'internationalUrl' => '/login.html', // 国际号登录的URL链接  
33 - 'phoneRetriveUrl' => '/passport/back/mobile', // 通过手机号找回密码的URL链接  
34 - 'emailRetriveUrl' => '/passport/back/email', // 通过邮箱找回密码的URL链接 23 + 'sourceType' => $sourceType, // 第三方登录来源
  24 + 'openId' => $openId, // openId
  25 + 'nickname' => $nickName, //昵称
35 ); 26 );
36 27
37 // 渲染模板 28 // 渲染模板
38 $this->_view->display('index', $data); 29 $this->_view->display('index', $data);
39 } 30 }
40 31
  32 + /**
  33 + * 手机验证码页面
  34 + */
  35 + public function codeAction()
  36 + {
  37 +
  38 + $this->setTitle('验证手机');
  39 + $openId = $this->get('openId');
  40 + $sourceType = $this->get('sourceType');
  41 + $nickName = $this->get('nickName');
  42 + $area = $this->get('areaCode', '86');
  43 + $isReg = $this->get('isReg');
  44 +
  45 + $data = array(
  46 + 'sourceType' => $sourceType, // 第三方登录来源
  47 + 'openId' => $openId, // openId
  48 + 'nickname' => $nickName, //昵称
  49 + 'isReg' => $isReg, //是否是已注册过的手机号
  50 + 'area' => $area //国别码
  51 + );
  52 +
  53 + // 渲染模板
  54 + $this->_view->display('code', $data);
  55 + }
  56 +
  57 + /**
  58 + * 设置登录密码页面
  59 + */
  60 + public function passwordAction()
  61 + {
  62 +
  63 + $this->setTitle('重新设置登录密码');
  64 + $openId = $this->get('openId');
  65 + $sourceType = $this->get('sourceType');
  66 + $nickName = $this->get('nickName');
  67 + $area = $this->get('areaCode', '86');
  68 + $data = array(
  69 + 'sourceType' => $sourceType, // 第三方登录来源
  70 + 'openId' => $openId, // openId
  71 + 'nickname' => $nickName, //昵称
  72 + 'area' => $area //国别码
  73 + );
  74 +
  75 + // 渲染模板
  76 + $this->_view->display('password', $data);
  77 + }
  78 +
  79 + //绑定前手机号校验
  80 + public function bindCheckAction()
  81 + {
  82 + $data = array('code' => 400, 'message' => '', 'data' => '');
  83 +
  84 + do
  85 + {
  86 + /* 判断是不是AJAX请求 */
  87 + if (!$this->isAjax())
  88 + {
  89 + break;
  90 + }
  91 +
  92 + $mobile = $this->post('mobile');
  93 + $openId = $this->post('openId');
  94 + $area = $this->post('areaCode', '86');
  95 + $sourceType = $this->post('sourceType');
  96 + $nickName = $this->post('nickName');
  97 +
  98 +
  99 + if (!is_numeric($mobile) || !$openId || !$area || !$sourceType)
  100 + {
  101 + break;
  102 + }
  103 +
  104 + $res = BindData::bindCheck($mobile, $openId, $sourceType);
  105 + if (!isset($res['code']))
  106 + {
  107 + break;
  108 + }
  109 + if ($res['code'] == 200)
  110 + {
  111 + $next = Helpers::url('/passport/bind/code', array('isReg' => $res['data']['is_register'], 'openId' => $openId, 'sourceType' => $sourceType, 'nickName' => $nickName, 'areaCode' => $area, 'mobile' => $mobile));
  112 + $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('is_register' => $res['data']['is_register'], 'next' => $next));
  113 + }
  114 + else
  115 + {
  116 + $data = array('code' => 500, 'message' => $res['message'], 'data' => $res['data']);
  117 + }
  118 + }
  119 + while (false);
  120 +
  121 + $this->echoJson($data);
  122 + }
  123 +
  124 + //发送验证码
  125 + public function sendBindMsgAction()
  126 + {
  127 + $data = array('code' => 400, 'message' => '', 'data' => '');
  128 +
  129 + do
  130 + {
  131 + /* 判断是不是AJAX请求 */
  132 + if (!$this->isAjax())
  133 + {
  134 + break;
  135 + }
  136 +
  137 + $mobile = $this->post('mobile');
  138 +
  139 + if (!is_numeric($mobile))
  140 + {
  141 + break;
  142 + }
  143 +
  144 + $data = BindData::sendBindMsg($mobile);
  145 + if (!isset($data['code']))
  146 + {
  147 + break;
  148 + }
  149 + }
  150 + while (false);
  151 +
  152 + $this->echoJson($data);
  153 + }
  154 +
  155 + //校验短信验证码
  156 + public function checkBindMsgAction()
  157 + {
  158 + $data = array('code' => 400, 'message' => '', 'data' => '');
  159 +
  160 + do
  161 + {
  162 + /* 判断是不是AJAX请求 */
  163 + if (!$this->isAjax())
  164 + {
  165 + break;
  166 + }
  167 +
  168 + $mobile = $this->post('mobile');
  169 + $msgCode = $this->post('msgCode');
  170 +
  171 + if (!is_numeric($mobile) || !$msgCode)
  172 + {
  173 + break;
  174 + }
  175 +
  176 + $data = BindData::checkBindCode($mobile, $msgCode);
  177 + if (!isset($data['code']))
  178 + {
  179 + break;
  180 + }
  181 + }
  182 + while (false);
  183 +
  184 + $this->echoJson($data);
  185 + }
  186 +
  187 + //绑定手机号
  188 + public function bindMobileAction()
  189 + {
  190 + $data = array('code' => 400, 'message' => '', 'data' => '');
  191 +
  192 + do
  193 + {
  194 + /* 判断是不是AJAX请求 */
  195 + if (!$this->isAjax())
  196 + {
  197 + break;
  198 + }
  199 +
  200 + $mobile = $this->post('mobile');
  201 + $openId = $this->post('openId');
  202 + $area = $this->post('areaCode', '86');
  203 + $sourceType = $this->post('sourceType');
  204 + $nickName = $this->post('nickName');
  205 + $password = $this->post('password');
41 206
  207 + if (!is_numeric($mobile) || !$openId || !$sourceType || !$area)
  208 + {
  209 + break;
  210 + }
42 211
  212 + $res = BindData::bindMobile($openId, $nickName, $sourceType, $mobile, $area, $password);
  213 + if (!isset($res['code']))
  214 + {
  215 + break;
  216 + }
43 217
44 -// /**  
45 -// * 支付宝账号登录:回调方法  
46 -// */  
47 -// public function alipaycallbackAction()  
48 -// {  
49 -// $realName = $this->_request->get('real_name');  
50 -// $email = $this->_request->get('email');  
51 -// $userId = $this->_request->get('user_id');  
52 -//  
53 -// $result = array();  
54 -// if (isset($realName, $email, $userId)) {  
55 -// $result = LoginData::signinByOpenID($realName, $userId, 'alipay');  
56 -// }  
57 -//  
58 -// $refer = $this->getCookie('refer');  
59 -// if (empty($refer)) {  
60 -// $refer = SITE_MAIN . '/?go=1';  
61 -// } else {  
62 -// $refer = rawurldecode($refer);  
63 -// }  
64 -//  
65 -// if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {  
66 -// $token = Helpers::makeToken($result['data']['uid']);  
67 -// $this->setCookie('_TOKEN', $token);  
68 -// $this->setSession('_TOKEN', $token);  
69 -// $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));  
70 -// } else {  
71 -// $this->go($refer);  
72 -// }  
73 -// } 218 + //绑定成功,跳转页面
  219 + $refer = $this->getCookie('refer');
  220 + if (empty($refer))
  221 + {
  222 + $refer = SITE_MAIN . '/?go=1';
  223 + }
  224 + else
  225 + {
  226 + $refer = rawurldecode($refer);
  227 + }
74 228
  229 + if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid']))
  230 + {
  231 + $token = Helpers::makeToken($res['data']['uid']);
  232 + $this->setCookie('_TOKEN', $token);
  233 + $this->setSession('_TOKEN', $token);
  234 + $refer = Helpers::syncUserSession($data['data']['uid'], $refer);
  235 + $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
  236 + }
  237 + else
  238 + {
  239 + $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
  240 + }
  241 + }
  242 + while (false);
75 243
  244 + $this->echoJson($data);
  245 + }
76 246
77 } 247 }
@@ -183,6 +183,13 @@ class LoginController extends AbstractAction @@ -183,6 +183,13 @@ class LoginController extends AbstractAction
183 $result = LoginData::signinByOpenID($realName, $userId, 'alipay'); 183 $result = LoginData::signinByOpenID($realName, $userId, 'alipay');
184 } 184 }
185 185
  186 + //判定是否需要绑定手机号
  187 + $isBind = $result['data']['is_bind'];
  188 + if ($isBind == 'N')
  189 + {
  190 + $this->go(Helpers::url('/passport/bind/index',array('openId'=>$userId,'sourceType'=>'alipay','nickName'=>$realName)));
  191 + }
  192 +
186 $refer = $this->getCookie('refer'); 193 $refer = $this->getCookie('refer');
187 if (empty($refer)) { 194 if (empty($refer)) {
188 $refer = SITE_MAIN . '/?go=1'; 195 $refer = SITE_MAIN . '/?go=1';
@@ -219,7 +226,7 @@ class LoginController extends AbstractAction @@ -219,7 +226,7 @@ class LoginController extends AbstractAction
219 $isBind = $result['data']['is_bind']; 226 $isBind = $result['data']['is_bind'];
220 if ($isBind == 'N') 227 if ($isBind == 'N')
221 { 228 {
222 - $this->go(Helpers::url('/passport/bind/index')); 229 + $this->go(Helpers::url('/passport/bind/index',array('openId'=>$access['openid'],'sourceType'=>'qq','nickName'=>$partnerInfo['nickname'])));
223 } 230 }
224 231
225 $refer = $this->getCookie('refer'); 232 $refer = $this->getCookie('refer');
@@ -259,6 +266,12 @@ class LoginController extends AbstractAction @@ -259,6 +266,12 @@ class LoginController extends AbstractAction
259 if ($partnerInfo && is_array($partnerInfo)) { 266 if ($partnerInfo && is_array($partnerInfo)) {
260 $result = LoginData::signinByOpenID($partnerInfo['screen_name'], $access['uid'], 'sina'); 267 $result = LoginData::signinByOpenID($partnerInfo['screen_name'], $access['uid'], 'sina');
261 } 268 }
  269 + //判定是否需要绑定手机号
  270 + $isBind = $result['data']['is_bind'];
  271 + if ($isBind == 'N')
  272 + {
  273 + $this->go(Helpers::url('/passport/bind/index',array('openId'=>$access['uid'],'sourceType'=>'sina','nickName'=>$partnerInfo['screen_name'])));
  274 + }
262 275
263 $refer = $this->getCookie('refer'); 276 $refer = $this->getCookie('refer');
264 if (empty($refer)) { 277 if (empty($refer)) {