Autosign.php 9.09 KB
<?php

use Action\AbstractAction;
use LibModels\Web\Passport\RegData;
use LibModels\Web\Passport\LoginData;
use LibModels\Web\Home\IndexData;
use Passport\PassportModel as PassportModel;
use Plugin\Helpers;
use Plugin\Images;
use Plugin\Partner\Factory;

class AutosignController extends AbstractAction
{

    /**
     * 支付宝登录:授权页面
     */
    public function alipayAction()
    {
        $this->setSession('_TOKEN', '');

        Factory::create('alipay')->getAuthorizeUrl();

        exit();
    }

    /**
     * QQ账号登录:授权页面
     */
    public function qqAction()
    {
        $this->setSession('_TOKEN', '');

        Factory::create('qqconnect')->getAuthorizeUrl();

        exit();
    }

    /**
     * 新浪微博账号登录:授权页面
     */
    public function sinaAction()
    {
        $this->setSession('_TOKEN', '');

        $this->go(Factory::create('sinaweibo')->getAuthorizeUrl());
    }

    /**
     * 新浪微博账号登录:授权页面
     */
    public function renrenAction()
    {
        $this->setSession('_TOKEN', '');

        $this->go(Factory::create('renren')->getAuthorizeUrl());
    }

    /**
     * 豆瓣账号登录:授权页面
     */
    public function doubanAction()
    {
        $this->setSession('_TOKEN', '');

        $this->go(Factory::create('douban')->getAuthorizeUrl());
    }

    /**
     * 支付宝账号登录:回调方法
     */
    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)) {
            $shoppingKey = Helpers::getShoppingKeyByCookie();
            $result = LoginData::signinByOpenID($realName, $userId, 'alipay', $shoppingKey);
        }

        //判定是否需要绑定手机号
        if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
            $this->go(Helpers::url('/passport/bind/index', array('openId' => $userId, 'sourceType' => 'alipay', 'nickname' => $realName)));
        }

        $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->setSession('_TOKEN', $token);
            $this->setSession('_LOGIN_UID', $result['data']['uid']);
            $this->setCookie('_TOKEN', $token);
            $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
        }
        else {
            $this->go($refer);
        }
    }

    /**
     * QQ账号登录:回调方法
     */
    public function qqcallbackAction()
    {
        $qqconnect = Factory::create('qqconnect');
        $access = $qqconnect->getAccessToken();
        /* 获取QQ腾讯用户的详细信息 */
        $partnerInfo = $qqconnect->getUserInfo($access);
        $result = array();
        if (!empty($partnerInfo) && isset($partnerInfo['nickname'])) {
            $shoppingKey = Helpers::getShoppingKeyByCookie();
            $result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['openid'], 'qq', $shoppingKey);
        }

        //判定是否需要绑定手机号
        if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
            $this->go(Helpers::url('/passport/autouserinfo/userinfo', array('openId' => $access['openid'], 'sourceType' => 'qq', 'nickname' => $partnerInfo['nickname'])));
        }

        $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->setSession('_TOKEN', $token);
            $this->setSession('_LOGIN_UID', $result['data']['uid']);
            $this->setCookie('_TOKEN', $token);
            $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
        }
        else {
            $this->go($refer);
        }
    }

    /**
     * 新浪微博账号登录:回调方法
     */
    public function sinacallbackAction()
    {
        $sina = Factory::create('sinaweibo');
        $access = $sina->getAccessToken();
        /* 获取用户的详细信息 */
        $partnerInfo = $sina->getUserInfo($access);

        $result = array();
        if ($partnerInfo && is_array($partnerInfo)) {
            $shoppingKey = Helpers::getShoppingKeyByCookie();
            $result = LoginData::signinByOpenID($partnerInfo['screen_name'], $access['uid'], 'sina', $shoppingKey);
        }

        //判定是否需要绑定手机号
        if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
//            $this->go(Helpers::url('/passport/bind/index', array('openId' => $access['uid'], 'sourceType' => 'sina', 'nickname' => $partnerInfo['screen_name'])));
        }

        $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->setSession('_TOKEN', $token);
            $this->setSession('_LOGIN_UID', $result['data']['uid']);
            $this->setCookie('_TOKEN', $token);
            $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
        }
        else {
            $this->go($refer);
        }
    }

    /**
     * renren账号登录:回调方法
     */
    public function renrenbackAction()
    {
        $renren = Factory::create('renren');
        $access = $renren->getAccessToken();
        /* 获取用户的详细信息 */
        $partnerInfo = $renren->getUserInfo($access);

        $result = array();
        if ($partnerInfo && is_array($partnerInfo)) {
            $shoppingKey = Helpers::getShoppingKeyByCookie();
            $result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['uid'], 'renren', $shoppingKey);
        }

        //判定是否需要绑定手机号
        if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
//            $this->go(Helpers::url('/passport/bind/index', array('openId' => $access['uid'], 'sourceType' => 'sina', 'nickname' => $partnerInfo['nick_name'])));
        }

        $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->setSession('_TOKEN', $token);
            $this->setSession('_LOGIN_UID', $result['data']['uid']);
            $this->setCookie('_TOKEN', $token);
            $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
        }
        else {
            $this->go($refer);
        }
    }

    /**
     * douban账号登录:回调方法
     */
    public function doubanbackAction()
    {
        $sina = Factory::create('douban');
        $access = $sina->getAccessToken();
        /* 获取用户的详细信息 */
        $partnerInfo = $sina->getUserInfo($access);

        $result = array();
        if ($partnerInfo && is_array($partnerInfo)) {
            $shoppingKey = Helpers::getShoppingKeyByCookie();
            $result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['uid'], 'douban', $shoppingKey);
        }

        //判定是否需要绑定手机号
        if (isset($result['data']['mobile']) && $result['data']['mobile'] == '') {
//            $this->go(Helpers::url('/passport/bind/index', array('openId' => $access['uid'], 'sourceType' => 'sina', 'nickname' => $partnerInfo['screen_name'])));
        }

        $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->setSession('_TOKEN', $token);
            $this->setSession('_LOGIN_UID', $result['data']['uid']);
            $this->setCookie('_TOKEN', $token);
            $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
        }
        else {
            $this->go($refer);
        }
    }

}