BindData.php 5.35 KB
<?php

namespace LibModels\Web\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 $mobile     绑定输入手机号 
     * @param  string $openId     第三方唯一识别码
     * @param  string $sourceType 登录方式 qq,sina,alipay,wechat
     * @param  int $area   所在地区
     * @return array 登录返回结果
     */
    public static function bindCheck($mobile, $openId, $sourceType, $area, $clientType = 'web')
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.passport.signCheck'; //app.passport.check
        $param['area'] = $area;
        $param['mobile'] = $mobile;
        $param['open_id'] = $openId;
        $param['source_type'] = $sourceType;
        $param['client_type'] = $clientType;
        $param['private_key'] = Yohobuy::$privateKeyList[$clientType];
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 发送、重发送验证码
     * @param  string $mobile   手机号
     * 
     */
    public static function sendBindMsg($area, $mobile, $clientType = 'web')
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.passport.smsbind';
        $param['mobile'] = $mobile;
        $param['area'] = $area;
        $param['client_type'] = $clientType;
        $param['private_key'] = Yohobuy::$privateKeyList[$clientType];
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 验证验证码是否正确
     * 
     */
    public static function checkBindCode($area, $mobile, $code, $clientType = 'web')
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.register.validRegCode';
        $param['mobile'] = $mobile;
        $param['code'] = $code;
        $param['area'] = $area;
        $param['client_type'] = $clientType;
        $param['private_key'] = Yohobuy::$privateKeyList[$clientType];
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 第三方绑定手机号
     * 
     * @param  string $openId     第三方唯一识别码
     * @param  string $nickname   姓名
     * @param  string $sourceType 登录方式
     * @param  string $mobile     手机号
     * @param  string $area       国别码
     * @param  string $password   密码
     */
    public static function bindMobile($openId, $sourceType, $mobile, $area, $password = '', $nickname = '', $clientType = 'web')
    {
        $param = Yohobuy::param();

        $param['method'] = 'app.passport.bind';
        $param['mobile'] = $mobile;
        $param['open_id'] = $openId;
        $param['source_type'] = $sourceType;
        $param['area'] = $area;
        if (!empty($nickname)) {
            $param['nickname'] = $nickname;
        }
        if (!empty($password)) {
            $param['password'] = $password;
        }
        $param['client_type'] = $clientType;
        $param['private_key'] = Yohobuy::$privateKeyList[$clientType];
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 第三方关联手机号
     * @param type $openId
     * @param type $sourceType
     * @param type $mobile
     * @param type $area
     * @param type $clientType
     */
    public static function relateMobile($openId, $sourceType, $mobile, $area, $clientType = 'web')
    {
        $param = Yohobuy::param();

        $param['method'] = 'app.passport.relatedMobile';
        $param['mobile'] = $mobile;
        $param['openId'] = $openId;
        $param['source_type'] = $sourceType;
        $param['area'] = $area;
        $param['client_type'] = $clientType;
        $param['private_key'] = Yohobuy::$privateKeyList[$clientType];
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 换绑手机检验
     * @param  string $mobile     手机号
     * @param  string $area       国别码
     */
    public static function changeCheck($mobile, $area)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.passport.changeCheck';
        $param['mobile'] = $mobile;
        $param['area'] = $area;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 换绑手机
     * @param  string $uid        用户Id
     * @param  string $mobile     手机号
     * @param  string $area       国别码
     * @param  string $code       验证码
     */
    public static function changeMobile($uid, $mobile, $area, $code)
    {
        $param = Yohobuy::param();

        $param['method'] = 'app.passport.changeMobile';
        $param['mobile'] = $mobile;
        $param['uid'] = $uid;
        $param['code'] = $code;
        $param['area'] = $area;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

}