Authored by xiaowei

第三方手机登录

... ... @@ -20,16 +20,16 @@ class BindData
/**
* 绑定前检查
* @param string $openId 第三方唯一识别码
* @param string $sourceType 登录方式
* @param string $clientType 所属客户端类型
* @param string $sourceType 登录方式 qq,sina,alipay,wechat
* @param string $mobile 绑定输入手机号
* @return array 登录返回结果
*/
public static function bindCheck($openId, $sourceType)
public static function bindCheck($mobile, $openId, $sourceType)
{
$param = Yohobuy::param();
$param['v'] = '7';
$param['method'] = 'app.passport.check';
$param['mobile'] = $mobile;
$param['open_id'] = $openId;
$param['source_type'] = $sourceType;
$param['client_secret'] = Sign::getSign($param);
... ... @@ -46,7 +46,6 @@ class BindData
{
$param = Yohobuy::param();
$param['v'] = '7';
$param['method'] = 'app.passport.smsbind';
$param['mobile'] = $mobile;
$param['client_secret'] = Sign::getSign($param);
... ... @@ -62,7 +61,6 @@ class BindData
{
$param = Yohobuy::param();
$param['v'] = '7';
$param['method'] = 'app.register.validRegCode';
$param['mobile'] = $mobile;
$param['code'] = $code;
... ... @@ -77,19 +75,23 @@ class BindData
* @param string $openId 第三方唯一识别码
* @param string $sourceType 登录方式
* @param string $mobile 手机号
* @param string $area 国别码
* @param string $password 密码
*/
public static function bindMobile($openId, $nickname, $sourceType, $mobile, $password)
public static function bindMobile($openId, $nickname, $sourceType, $mobile, $area, $password = '')
{
$param = Yohobuy::param();
$param['v'] = '7';
$param['method'] = 'app.passport.bind';
$param['mobile'] = $mobile;
$param['passport'] = $password;
$param['open_id'] = $openId;
$param['nickname'] = $nickname;
$param['source_type'] = $sourceType;
$param['area'] = $area;
if (!empty($password))
{
$param['passport'] = $password;
}
$param['client_secret'] = Sign::getSign($param);
... ...
... ... @@ -66,7 +66,6 @@ class LoginData
// 构建必传参数
$param = Yohobuy::param();
$param['v'] = '7'; // 只有早期的V4版本才有直接生成UID
$param['method'] = 'app.passport.signinByOpenID';
$param['openId'] = $openId;
$param['source_type'] = $sourceType;
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Passport\LoginData;
use LibModels\Wap\Passport\RegData;
use LibModels\Wap\Passport\BindData;
use Plugin\Helpers;
use Plugin\Partner\Factory;
/**
* 登录的控制器
... ... @@ -17,61 +15,233 @@ class BindController extends AbstractAction
*/
public function indexAction()
{
$this->setTitle('绑定手机号');
$openId = $this->get('openId');
$sourceType = $this->get('sourceType');
$nickName = $this->get('nickName');
$data = array(
'loginIndex' => true, // 模板中使用JS的标识
'backUrl' => '/', // 返回的URL链接
'showHeaderImg' => true, // 控制显示头部图片
'isPassportPage' => true, // 模板中模块标识
'registerUrl' => '/reg.html', // 注册的URL链接
'aliLoginUrl' => '/passport/login/alipay', // 支付宝快捷登录的URL链接
'weiboLoginUrl' => '/passport/login/sina', // 微博登录的URL链接
'qqLoginUrl' => '/passport/login/qq', // 腾讯QQ登录的URL链接
'internationalUrl' => '/login.html', // 国际号登录的URL链接
'phoneRetriveUrl' => '/passport/back/mobile', // 通过手机号找回密码的URL链接
'emailRetriveUrl' => '/passport/back/email', // 通过邮箱找回密码的URL链接
'sourceType' => $sourceType, // 第三方登录来源
'openId' => $openId, // openId
'nickname' => $nickName, //昵称
);
// 渲染模板
$this->_view->display('index', $data);
}
/**
* 手机验证码页面
*/
public function codeAction()
{
$this->setTitle('验证手机');
$openId = $this->get('openId');
$sourceType = $this->get('sourceType');
$nickName = $this->get('nickName');
$area = $this->get('areaCode', '86');
$isReg = $this->get('isReg');
$data = array(
'sourceType' => $sourceType, // 第三方登录来源
'openId' => $openId, // openId
'nickname' => $nickName, //昵称
'isReg' => $isReg, //是否是已注册过的手机号
'area' => $area //国别码
);
// 渲染模板
$this->_view->display('code', $data);
}
/**
* 设置登录密码页面
*/
public function passwordAction()
{
$this->setTitle('重新设置登录密码');
$openId = $this->get('openId');
$sourceType = $this->get('sourceType');
$nickName = $this->get('nickName');
$area = $this->get('areaCode', '86');
$data = array(
'sourceType' => $sourceType, // 第三方登录来源
'openId' => $openId, // openId
'nickname' => $nickName, //昵称
'area' => $area //国别码
);
// 渲染模板
$this->_view->display('password', $data);
}
//绑定前手机号校验
public function bindCheckAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do
{
/* 判断是不是AJAX请求 */
if (!$this->isAjax())
{
break;
}
$mobile = $this->post('mobile');
$openId = $this->post('openId');
$area = $this->post('areaCode', '86');
$sourceType = $this->post('sourceType');
$nickName = $this->post('nickName');
if (!is_numeric($mobile) || !$openId || !$area || !$sourceType)
{
break;
}
$res = BindData::bindCheck($mobile, $openId, $sourceType);
if (!isset($res['code']))
{
break;
}
if ($res['code'] == 200)
{
$next = Helpers::url('/passport/bind/code', array('isReg' => $res['data']['is_register'], 'openId' => $openId, 'sourceType' => $sourceType, 'nickName' => $nickName, 'areaCode' => $area, 'mobile' => $mobile));
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('is_register' => $res['data']['is_register'], 'next' => $next));
}
else
{
$data = array('code' => 500, 'message' => $res['message'], 'data' => $res['data']);
}
}
while (false);
$this->echoJson($data);
}
//发送验证码
public function sendBindMsgAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do
{
/* 判断是不是AJAX请求 */
if (!$this->isAjax())
{
break;
}
$mobile = $this->post('mobile');
if (!is_numeric($mobile))
{
break;
}
$data = BindData::sendBindMsg($mobile);
if (!isset($data['code']))
{
break;
}
}
while (false);
$this->echoJson($data);
}
//校验短信验证码
public function checkBindMsgAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do
{
/* 判断是不是AJAX请求 */
if (!$this->isAjax())
{
break;
}
$mobile = $this->post('mobile');
$msgCode = $this->post('msgCode');
if (!is_numeric($mobile) || !$msgCode)
{
break;
}
$data = BindData::checkBindCode($mobile, $msgCode);
if (!isset($data['code']))
{
break;
}
}
while (false);
$this->echoJson($data);
}
//绑定手机号
public function bindMobileAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do
{
/* 判断是不是AJAX请求 */
if (!$this->isAjax())
{
break;
}
$mobile = $this->post('mobile');
$openId = $this->post('openId');
$area = $this->post('areaCode', '86');
$sourceType = $this->post('sourceType');
$nickName = $this->post('nickName');
$password = $this->post('password');
if (!is_numeric($mobile) || !$openId || !$sourceType || !$area)
{
break;
}
$res = BindData::bindMobile($openId, $nickName, $sourceType, $mobile, $area, $password);
if (!isset($res['code']))
{
break;
}
// /**
// * 支付宝账号登录:回调方法
// */
// public function alipaycallbackAction()
// {
// $realName = $this->_request->get('real_name');
// $email = $this->_request->get('email');
// $userId = $this->_request->get('user_id');
//
// $result = array();
// if (isset($realName, $email, $userId)) {
// $result = LoginData::signinByOpenID($realName, $userId, 'alipay');
// }
//
// $refer = $this->getCookie('refer');
// if (empty($refer)) {
// $refer = SITE_MAIN . '/?go=1';
// } else {
// $refer = rawurldecode($refer);
// }
//
// if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
// $token = Helpers::makeToken($result['data']['uid']);
// $this->setCookie('_TOKEN', $token);
// $this->setSession('_TOKEN', $token);
// $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
// } else {
// $this->go($refer);
// }
// }
//绑定成功,跳转页面
$refer = $this->getCookie('refer');
if (empty($refer))
{
$refer = SITE_MAIN . '/?go=1';
}
else
{
$refer = rawurldecode($refer);
}
if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid']))
{
$token = Helpers::makeToken($res['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->setSession('_TOKEN', $token);
$refer = Helpers::syncUserSession($data['data']['uid'], $refer);
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
}
else
{
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
}
}
while (false);
$this->echoJson($data);
}
}
... ...
... ... @@ -183,6 +183,13 @@ class LoginController extends AbstractAction
$result = LoginData::signinByOpenID($realName, $userId, 'alipay');
}
//判定是否需要绑定手机号
$isBind = $result['data']['is_bind'];
if ($isBind == 'N')
{
$this->go(Helpers::url('/passport/bind/index',array('openId'=>$userId,'sourceType'=>'alipay','nickName'=>$realName)));
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
... ... @@ -219,7 +226,7 @@ class LoginController extends AbstractAction
$isBind = $result['data']['is_bind'];
if ($isBind == 'N')
{
$this->go(Helpers::url('/passport/bind/index'));
$this->go(Helpers::url('/passport/bind/index',array('openId'=>$access['openid'],'sourceType'=>'qq','nickName'=>$partnerInfo['nickname'])));
}
$refer = $this->getCookie('refer');
... ... @@ -259,6 +266,12 @@ class LoginController extends AbstractAction
if ($partnerInfo && is_array($partnerInfo)) {
$result = LoginData::signinByOpenID($partnerInfo['screen_name'], $access['uid'], 'sina');
}
//判定是否需要绑定手机号
$isBind = $result['data']['is_bind'];
if ($isBind == 'N')
{
$this->go(Helpers::url('/passport/bind/index',array('openId'=>$access['uid'],'sourceType'=>'sina','nickName'=>$partnerInfo['screen_name'])));
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
... ...