123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- /**
- * GameController.php UTF-8
- *
- *
- * @date : 2018/5/2 14:06
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace api\apple\controller;
- use api\common\controller\AppleApiBaseController;
- use huo\controller\common\HuoSession;
- use huo\controller\game\Game;
- use huo\controller\member\Member;
- use huo\controller\member\MemCache;
- use huolib\status\GameStatus;
- use huolib\tool\SimpleSec;
- use huolib\tool\StrUtils;
- use think\Config;
- class GameController extends AppleApiBaseController {
- function _initialize() {
- parent::_initialize();
- Config::set('default_return_type', 'html');
- }
- /**
- * 游戏地址 父frame
- * http://doc.1tsdk.com/138?page_id=3204
- * 【域名】/game/game/:game_id/agent/:agent_id
- *
- * 【域名】/game
- *
- * @param int $game_id
- * @param int $agent_id
- *
- * @return mixed
- */
- public function index($game_id = 0, $agent_id = 0) {
- $_game_id = $game_id;
- $_agent_id = $agent_id;
- if (empty($_game_id)) {
- $_game_id = $_agent_id = get_val($this->rq_data, 'game_id', 0);
- }
- if (empty($_game_id)) {
- $_code = GameStatus::GAME_ID_EMPTY;
- $this->error(GameStatus::getMsg($_code), [], $_code);
- }
- if (empty($_agent_id)) {
- $_agent_id = get_val($this->rq_data, 'agent_id', 0);
- }
- if (!empty($_agent_id)) {
- (new HuoSession($this->mem_id))->setAgentId($agent_id);
- }
- $this->assign('game_id', $_game_id);
- $this->assign('agent_id', $_agent_id);
- /* 判断是否登陆 */
- if (empty($this->mem_id)) {
- /* 未登陆 显示登陆页面 */
- $this->assign('game_id', $_game_id);
- $this->assign('agent_id', $_agent_id);
- return $this->fetch('game/login');
- }
- $_map['game_id'] = $_game_id;
- $_map['agent_id'] = $_agent_id;
- $_play_url = H5ISITE.'/'.'play?'.StrUtils::createLinkString($_map);
- $this->assign('play_url', $_play_url);
- $_data = (new Member())->getMemInfo($this->mem_id);
- $_game_data = (new Game())->getDetail($_game_id);
- $this->assign('userinfo', $_data);
- $this->assign('game', $_game_data['data']);
- return $this->fetch('game/index');
- }
- /**
- * H5-游戏地址校验登陆页
- * http://doc.1tsdk.com/138?page_id=3152
- * 【域名】/play/game/:game_id/agent/:agent_id
- * 【域名】/play
- *
- * @param int $game_id
- * @param int $agent_id
- *
- * @return mixed
- */
- public function play($game_id = 0, $agent_id = 0) {
- $_game_id = $game_id;
- $_agent_id = $agent_id;
- if (empty($game_id)) {
- $_game_id = get_val($this->rq_data, 'game_id', 0);
- }
- if (empty($_game_id)) {
- $_code = GameStatus::GAME_ID_EMPTY;
- $this->error(GameStatus::getMsg($_code), [], $_code);
- }
- if (empty($agent_id)) {
- $_agent_id = get_val($this->rq_data, 'agent_id', 0);
- }
- if (!empty($_agent_id)) {
- (new HuoSession($this->mem_id))->setAgentId($_agent_id);
- }
- /* 拼接游戏地址 */
- $_game_class = new Game();
- $_play_url = $_game_class->getPlayUrl($_game_id);
- if (is_numeric($_play_url)) {
- $this->error(GameStatus::getMsg($_play_url), [], $_play_url);
- }
- $_app_key = $_game_class->getAppkey($_game_id);
- /* 判断是否登陆 */
- if (empty($this->mem_id)) {
- /* 未登陆 显示登陆页面 */
- $this->assign('game_id', $_game_id);
- $this->assign('agent_id', $_agent_id);
- return $this->fetch('game/login');
- }
- $_mem_data = MemCache::ins()->getInfoById($this->mem_id);
- $_mg_data = (new Member())->memGameLogin($_mem_data, $game_id);
- $_param['app_id'] = $game_id;
- $_param['mem_id'] = !empty($_mg_data['id']) ? $_mg_data['id'] : $this->mem_id;
- $_param['user_token'] = SimpleSec::encode(session_id(),config('CPAUTHCODE'));
- $_param_str = StrUtils::createLinkString($_param);
- $_sign = md5($_param_str.'&app_key='.$_app_key);
- $_param_str = $_param_str.'&sign='.$_sign;
- return redirect($_play_url.'?'.$_param_str);
- }
- }
|