| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 | 
							- <?php
 
- /**
 
-  * OauthController.php UTF-8
 
-  * 第三方登陆
 
-  *
 
-  * @date    : 2018/4/25 21:21
 
-  *
 
-  * @license 这不是一个自由软件,未经授权不许任何使用和传播。
 
-  * @author  : wuyonghong <wyh@huosdk.com>
 
-  * @version : HUOSDK 8.0
 
-  */
 
- namespace api\apple\controller;
 
- use api\common\controller\AppleApiBaseController;
 
- use huo\controller\app\FloatPoint;
 
- use huo\controller\member\OauthOut;
 
- use huo\controller\request\Channel;
 
- use huo\controller\request\Device;
 
- use huo\controller\request\Game;
 
- use huo\controller\request\Mem;
 
- use huolib\constant\FromConst;
 
- use huolib\constant\OauthConst;
 
- use huolib\oauth\OAuth as OAuthLib;
 
- use huolib\status\MemberStatus;
 
- use huolib\tool\SimpleSec;
 
- use huolib\tool\StrUtils;
 
- use think\Config;
 
- use think\Log;
 
- class OauthController extends AppleApiBaseController {
 
-     function _initialize() {
 
-         parent::_initialize();
 
-         Log::write($this->request->getContent(), Log::LOG);
 
-         Config::set('default_return_type', 'html');
 
-     }
 
-     /**
 
-      * http://doc.1tsdk.com/138?page_id=3105
 
-      * 第三方登陆网页入口
 
-      * 【域名】/oauth/index
 
-      */
 
-     public function index() {
 
-         $_type = get_val($this->rq_data, 'type');
 
-         $_url = get_val($this->rq_data, 'url');
 
-         $_from = $this->getFrom();
 
-         $_oauth_class = new OauthOut();
 
-         $_rdata = $_oauth_class->getRequestCodeUrl($_type, $_from, $_url);
 
-         if (MemberStatus::NO_ERROR != $_rdata['code']) {
 
-             $this->error($_rdata['msg']);
 
-         }
 
-         $_url = $_rdata['data']['url'];
 
-         $this->redirect($_url);
 
-     }
 
-     public function getReturn($mem_data, $app_id = 0) {
 
-         $_rdata = (new FloatPoint())->getFloat($app_id);
 
-         $_rdata['mem_id'] = $mem_data['mem_id'];
 
-         $_rdata['agentgame'] = $mem_data['agent_game'];
 
-         $_rdata['user_token'] = session_id();
 
-         $_rdata['is_bind'] = $mem_data['is_bind'];
 
-         $_rdata['cp_user_token'] = SimpleSec::encode(session_id(), config('CPAUTHCODE'));
 
-         $_rdata['url'] = $mem_data['url'];
 
-         return $_rdata;
 
-     }
 
-     /**
 
-      * @param $_type
 
-      * @param $_code
 
-      * @param $_state
 
-      *
 
-      * @return mixed
 
-      */
 
-     protected function callback($_type, $_code, $_state) {
 
-         $_url = get_val($this->rq_data, 'back_url');
 
-         $_url_arr = parse_url($_url);
 
-         if (!empty($_url_arr['query'])) {
 
-             parse_str($_url_arr['query'], $_query_arr);
 
-             if (!empty($_query_arr['game_id'])) {
 
-                 $this->rq_data['app_id'] = $_query_arr['game_id'];
 
-             }
 
-         }
 
-         $_url = StrUtils::getUrl($_url).'token='.session_id();
 
-         $_oauth_class = new OauthOut();
 
-         if (empty($_code) || empty($_state)) {
 
-             $_code = MemberStatus::INVALID_PARAMS;
 
-             $this->error(MemberStatus::getMsg($_code), '', $_code, [], $_url);
 
-         }
 
-         $_oauth_lib_class = OAuthLib::ins($_type);
 
-         $_cmp_rs = $_oauth_lib_class->compareState($_state);
 
-         if (false == $_cmp_rs) {
 
-             $_code = MemberStatus::INVALID_PARAMS;
 
-             $this->error(MemberStatus::getMsg($_code).'2', '', $_code, [], $_url);
 
-         }
 
-         $_game_rq = $this->setGameData();
 
-         $_channel_rq = $this->setChannelData();
 
-         $_device_rq = $this->setDeviceData();
 
-         $_mem_rq = $this->setMemData();
 
-         $_from = $this->getFrom();
 
-         $_rs = $_oauth_class->oauthLoginByCode(
 
-             $_type, $_code, $_from, $_game_rq, $_channel_rq, $_device_rq, $_mem_rq
 
-         );
 
-         if (MemberStatus::NO_ERROR != $_rs['code']) {
 
-             $this->error($_rs['msg']);
 
-         }
 
-         $_mem_data = $_rs['data'];
 
-         if (!empty($_url)) {
 
-             $_mem_data['url'] = $_url;
 
-         }
 
-         $_rdata = $this->getReturn($_mem_data);
 
-         $this->assign($_rdata);
 
-         return $this->fetch('oauth/callback');
 
-     }
 
-     /**
 
-      * 回调地址
 
-      */
 
-     function callbackWeixin() {
 
-         $_code = get_val($this->rq_data, 'code');
 
-         $_state = get_val($this->rq_data, 'state');
 
-         $_type = OauthConst::OAUTH_WXQRCODE;
 
-         if ($this->request->isWeixin()) {
 
-             $_type = OauthConst::OAUTH_WEIXIN;
 
-         }
 
-         return $this->callback($_type, $_code, $_state);
 
-     }
 
-     /**
 
-      * 回调地址
 
-      */
 
-     function callbackWeibo() {
 
-         $_code = get_val($this->rq_data, 'code');
 
-         $_state = get_val($this->rq_data, 'state');
 
-         $_type = OauthConst::OAUTH_WEIBO;
 
-         return $this->callback($_type, $_code, $_state);
 
-     }
 
-     /**
 
-      * 回调地址
 
-      */
 
-     function callbackQq() {
 
-         $_code = get_val($this->rq_data, 'code');
 
-         $_state = get_val($this->rq_data, 'state');
 
-         $_type = OauthConst::OAUTH_QQ;
 
-         return $this->callback($_type, $_code, $_state);
 
-     }
 
-     /**
 
-      * 获取来源
 
-      *
 
-      * @return string
 
-      */
 
-     private function getFrom() {
 
-         $_from = FromConst::FROM_PC;
 
-         if ($this->request->isMobile()) {
 
-             $_from = FromConst::FROM_MOBILE;
 
-         }
 
-         if ($this->request->isWeixin()) {
 
-             $_from = FromConst::FROM_WEIXIN;
 
-         }
 
-         return $_from;
 
-     }
 
- }
 
 
  |