RegData.php 4.72 KB
<?php

namespace LibModels\Wap\Passport;

use Api\Sign;
use Api\Yohobuy;

/**
 * 注册的数据模型
 * 
 * @name RegData
 * @package LibModels/Wap/Passport
 * @copyright yoho.inc
 * @version 1.0 (2015-10-12 14:04:55)
 * @author fei.hong <fei.hong@yoho.cn>
 */
class RegData
{

    /**
     * 获取地区数据
     * 
     * 备注:
     * 考虑到该接口数据很少发生变化,改成静态配置,不调用接口.
     * 以后有需要,可以打开注释,改成调用接口. 
     * 
     * @return array 地区数据
     */
    public static function getAreasData()
    {
//        $param = Yohobuy::param();
//        $param['method'] = 'app.passport.getArea';
//        $param['client_secret'] = Sign::getSign($param);
//        $data = Yohobuy::get(Yohobuy::API_URL, $param);
//        $result = array();
//        if (!empty($data['data'])) {
//            $build = array();
//            foreach ($data['data'] as $value) {
//                $build = array();
//                $build['areaCode'] = '+' . $value['area'];
//                $build['selected'] = ($value['area'] === '86');
//                $build['name'] = $value['name'];
//                $result[] = $build;
//            }
//            $data = array();
//        }
//        return $result;

        return array(
            0 => array(
                'areaCode' => '+61',
                'selected' => false,
                'name' => '澳大利亚',
            ),
            1 => array(
                'areaCode' => '+82',
                'selected' => false,
                'name' => '韩国',
            ),
            2 => array(
                'areaCode' => '+1',
                'selected' => false,
                'name' => '加拿大',
            ),
            3 => array(
                'areaCode' => '+60',
                'selected' => false,
                'name' => '马来西亚',
            ),
            4 => array(
                'areaCode' => '+1',
                'selected' => false,
                'name' => '美国',
            ),
            5 => array(
                'areaCode' => '+81',
                'selected' => false,
                'name' => '日本',
            ),
            6 => array(
                'areaCode' => '+65',
                'selected' => false,
                'name' => '新加坡',
            ),
            7 => array(
                'areaCode' => '+44',
                'selected' => false,
                'name' => '英国',
            ),
            8 => array(
                'areaCode' => '+86',
                'selected' => true,
                'name' => '中国',
            ),
            9 => array(
                'areaCode' => '+853',
                'selected' => false,
                'name' => '中国澳门',
            ),
            10 => array(
                'areaCode' => '+886',
                'selected' => false,
                'name' => '中国台湾',
            ),
            11 => array(
                'areaCode' => '+852',
                'selected' => false,
                'name' => '中国香港',
            ),
        );
    }

    /**
     * 发送手机注册验证码
     * 
     * @param string $area 地区号 如"86"
     * @param string $mobile 手机号
     * @return array
     */
    public static function sendCodeToMobile($area, $mobile)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.register.sendRegCodeToMobile';
        $param['area'] = $area;
        $param['mobile'] = $mobile;
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 验证手机注册的识别码
     * 
     * @param string $area 地区号 如"86"
     * @param string $mobile 手机号
     * @param string $code 验证码
     * @return array
     */
    public static function validMobileCode($area, $mobile, $code)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.register.validRegCode';
        $param['area'] = $area;
        $param['mobile'] = $mobile;
        $param['code'] = $code;
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 通过手机注册
     * 
     * @param string $area 地区号 如"86"
     * @param string $mobile 手机号
     * @param string $password 登录密码
     * @return array
     */
    public static function regMobile($area, $mobile, $password)
    {
        $param['client_type'] = Yohobuy::clientType();
        $param['area'] = $area;
        $param['profile'] = $mobile;
        $param['password'] = $password;
        $param['ip'] = Yohobuy::ip();

        return Yohobuy::jsonPost(Yohobuy::API_URL_MYCENTER . 'RegisterRest/register', $param);
    }

}