LoginData.php 2.31 KB
<?php

namespace LibModels\Wap\Passport;

use Api\Sign;
use Api\Yohobuy;

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

    /**
     * 登录
     * 
     * @param string $area 地区编号
     * @param string $profile 邮箱或手机号
     * @param string $password 密码
     * @return array
     */
    public static function signin($area, $profile, $password)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.passport.signin';
        $param['area'] = $area;
        $param['profile'] = $profile;
        $param['password'] = $password;
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 用户信息
     * 
     * @param int $uid 用户唯一ID
     * @return array
     */
    public static function profile($uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.passport.profile';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 第三方登录接口(包括alipay,qq,sina)
     * @param  string $nickname   姓名
     * @param  string $openId     第三方唯一识别码
     * @param  string $sourceType 登录方式
     * @return array              登录返回结果
     */
    public static function signinByOpenID($nickname, $openId, $sourceType)
    {
        // 构建必传参数
        $param = Yohobuy::param();

        $param['v'] = '4'; // 只有早期的V4版本才有直接生成UID
        $param['method'] = 'app.passport.signinByOpenID';
        $param['openId'] = $openId;
        $param['source_type'] = $sourceType;
        $param['nickname'] = $nickname;
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 登出SESSION会话
     * 
     * @param int $uid 用户ID
     * @return array
     */
    public static function signoutSession($token)
    {
        $param = array();
        $param['token'] = $token;
        
        return Yohobuy::get(Yohobuy::API_URL_LOGINSESSION . 'Passport/session/logout', $param);
    }

}