Authored by xiaowei

跳转绑定手机号

<?php
namespace LibModels\Wap\Passport;
use Api\Sign;
use Api\Yohobuy;
/**
* 绑定手机号 数据模型
*
* @name BindData
* @package LibModels/Wap/Passport
* @copyright yoho.inc
* @version 1.0 (2015-12-14 10:00:00)
* @author xiaowei
*/
class BindData
{
/**
* 绑定前检查
* @param string $openId 第三方唯一识别码
* @param string $sourceType 登录方式
* @param string $clientType 所属客户端类型
* @return array 登录返回结果
*/
public static function bindCheck($openId, $sourceType)
{
$param = Yohobuy::param();
$param['v'] = '7';
$param['method'] = 'app.passport.check';
$param['open_id'] = $openId;
$param['source_type'] = $sourceType;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 发送、重发送验证码
* @param string $mobile 手机号
*
*/
public static function sendBindMsg($mobile)
{
$param = Yohobuy::param();
$param['v'] = '7';
$param['method'] = 'app.passport.smsbind';
$param['mobile'] = $mobile;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 验证验证码是否正确
*
*/
public static function checkBindCode($mobile, $code)
{
$param = Yohobuy::param();
$param['v'] = '7';
$param['method'] = 'app.register.validRegCode';
$param['mobile'] = $mobile;
$param['code'] = $code;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 第三方绑定手机号
* @param string $nickname 姓名
* @param string $openId 第三方唯一识别码
* @param string $sourceType 登录方式
* @param string $mobile 手机号
* @param string $password 密码
*/
public static function bindMobile($openId, $nickname, $sourceType, $mobile, $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['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -66,7 +66,7 @@ class LoginData
// 构建必传参数
$param = Yohobuy::param();
$param['v'] = '4'; // 只有早期的V4版本才有直接生成UID
$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 Plugin\Helpers;
use Plugin\Partner\Factory;
/**
* 登录的控制器
*/
class BindController extends AbstractAction
{
/**
* 登录到bind页面
*/
public function indexAction()
{
$this->setTitle('绑定手机号');
$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链接
);
// 渲染模板
$this->_view->display('index', $data);
}
// /**
// * 支付宝账号登录:回调方法
// */
// 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);
// }
// }
}
... ...
... ... @@ -210,23 +210,37 @@ class LoginController extends AbstractAction
/* 获取QQ腾讯用户的详细信息 */
$partnerInfo = $qqconnect->getUserInfo($access);
$result = array();
if (!empty($partnerInfo) && isset($partnerInfo['nickname'])) {
if (!empty($partnerInfo) && isset($partnerInfo['nickname']))
{
$result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['openid'], 'qq');
}
//判定是否需要绑定手机号
$isBind = $result['data']['is_bind'];
if ($isBind == 'N')
{
$this->go(Helpers::url('/passport/bind/index'));
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
if (empty($refer))
{
$refer = SITE_MAIN . '/?go=1';
} else {
}
else
{
$refer = rawurldecode($refer);
}
if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
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 {
}
else
{
$this->go($refer);
}
}
... ...