BackData.php 4.35 KB
<?php
namespace LibModels\Web\Passport;

use Api\Sign;
use Api\Yohobuy;

class BackData
{
    
    /**
     * 获取地区数据
     * 
     * @return array 地区数据
     */
    public static function getAreasData()
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['method'] = 'app.passport.getArea';
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 通过邮箱找回密码
     * 
     * @param  string  $email  邮箱地址
     * @return array           返回状态数据
     */
    public static function sendCodeToEmail($email)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['email'] = $email;
        $param['method'] = 'app.register.backpwdByEmail';
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 根据邮箱验证码修改密码(调用www.yohobuy.com接口)
     * 
     * @param  string  $pwd 	新密码
     * @param  string  $code   邮箱验证码
     * @return array           返回状态数据
     */
    public static function modifyPasswordByEmail($pwd, $code)
    {
        $param['pwd'] = $pwd;
        $param['re-input'] = $pwd;
        $param['code'] = $code;

        // 默认返回的不是json类型数据,是html
        return Yohobuy::get(Yohobuy::YOHOBUY_URL . 'passport/back/update', $param, true);
    }

    /**
     * 通过手机找回密码
     * 
     * @param  string  $mobile 手机号
     * @param  integer $area   地区码ID
     * @return array           返回状态数据
     */
    public static function sendCodeToMobile($mobile, $area = 86)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['mobile'] = $mobile;
        $param['area'] = $area;
        $param['method'] = 'app.register.sendBackpwdCodeToMobile';
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 校验密码修改手机验证码
     * 
     * @param  string  $mobile 手机号
     * @param  string  $code   验证码
     * @param  integer $area   地区码ID
     * @return array           返回状态数据(token)
     */
    public static function validateMobileCode($mobile, $code, $area = 86)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['mobile'] = $mobile;
        $param['code'] = $code;
        $param['area'] = $area;
        $param['method'] = 'app.register.validBackpwdCode';
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 根据手机验证码修改密码
     * 
     * @param  string  $mobile 手机号
     * @param  string  $token   验证手机验证码返回的token
     * @param  integer $area   地区码ID
     * @return array           返回状态数据
     */
    public static function modifyPasswordByMobile($mobile, $token, $newpwd, $area = 86)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['mobile'] = $mobile;
        $param['token'] = $token;
        $param['newpwd'] = $newpwd;
        $param['area'] = $area;
        $param['method'] = 'app.register.changepwdByMobileCode';
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }
    
    /**
     * 验证找回邮件code
     * 
     * @param string $code
     * @return array
     */
    public static function checkEmailCode($code)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.register.checkCodeValid';
        $param['code'] = $code;
        $param['client_secret'] = Sign::getSign($param);
        
        return Yohobuy::get(Yohobuy::API_URL, $param, 3600); // 缓存1小时
    }
    
    /**
     * 根据邮箱code修改密码
     * 
     * @param string $code
     * @param string $password
     * @return array
     */
    public static function modifyPasswordByEmailCode($code, $password)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.register.resetPwdByCode';
        $param['code'] = $code;
        $param['newPwd'] = $password;
        $param['client_secret'] = Sign::getSign($param);
        
        return Yohobuy::post(Yohobuy::API_URL, $param);
    }
    
}