GameController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * GameController.php UTF-8
  4. *
  5. *
  6. * @date : 2018/5/2 14:06
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace api\apple\controller;
  13. use api\common\controller\AppleApiBaseController;
  14. use huo\controller\common\HuoSession;
  15. use huo\controller\game\Game;
  16. use huo\controller\member\Member;
  17. use huo\controller\member\MemCache;
  18. use huolib\status\GameStatus;
  19. use huolib\tool\SimpleSec;
  20. use huolib\tool\StrUtils;
  21. use think\Config;
  22. class GameController extends AppleApiBaseController {
  23. function _initialize() {
  24. parent::_initialize();
  25. Config::set('default_return_type', 'html');
  26. }
  27. /**
  28. * 游戏地址 父frame
  29. * http://doc.1tsdk.com/138?page_id=3204
  30. * 【域名】/game/game/:game_id/agent/:agent_id
  31. *
  32. * 【域名】/game
  33. *
  34. * @param int $game_id
  35. * @param int $agent_id
  36. *
  37. * @return mixed
  38. */
  39. public function index($game_id = 0, $agent_id = 0) {
  40. $_game_id = $game_id;
  41. $_agent_id = $agent_id;
  42. if (empty($_game_id)) {
  43. $_game_id = $_agent_id = get_val($this->rq_data, 'game_id', 0);
  44. }
  45. if (empty($_game_id)) {
  46. $_code = GameStatus::GAME_ID_EMPTY;
  47. $this->error(GameStatus::getMsg($_code), [], $_code);
  48. }
  49. if (empty($_agent_id)) {
  50. $_agent_id = get_val($this->rq_data, 'agent_id', 0);
  51. }
  52. if (!empty($_agent_id)) {
  53. (new HuoSession($this->mem_id))->setAgentId($agent_id);
  54. }
  55. $this->assign('game_id', $_game_id);
  56. $this->assign('agent_id', $_agent_id);
  57. /* 判断是否登陆 */
  58. if (empty($this->mem_id)) {
  59. /* 未登陆 显示登陆页面 */
  60. $this->assign('game_id', $_game_id);
  61. $this->assign('agent_id', $_agent_id);
  62. return $this->fetch('game/login');
  63. }
  64. $_map['game_id'] = $_game_id;
  65. $_map['agent_id'] = $_agent_id;
  66. $_play_url = H5ISITE.'/'.'play?'.StrUtils::createLinkString($_map);
  67. $this->assign('play_url', $_play_url);
  68. $_data = (new Member())->getMemInfo($this->mem_id);
  69. $_game_data = (new Game())->getDetail($_game_id);
  70. $this->assign('userinfo', $_data);
  71. $this->assign('game', $_game_data['data']);
  72. return $this->fetch('game/index');
  73. }
  74. /**
  75. * H5-游戏地址校验登陆页
  76. * http://doc.1tsdk.com/138?page_id=3152
  77. * 【域名】/play/game/:game_id/agent/:agent_id
  78. * 【域名】/play
  79. *
  80. * @param int $game_id
  81. * @param int $agent_id
  82. *
  83. * @return mixed
  84. */
  85. public function play($game_id = 0, $agent_id = 0) {
  86. $_game_id = $game_id;
  87. $_agent_id = $agent_id;
  88. if (empty($game_id)) {
  89. $_game_id = get_val($this->rq_data, 'game_id', 0);
  90. }
  91. if (empty($_game_id)) {
  92. $_code = GameStatus::GAME_ID_EMPTY;
  93. $this->error(GameStatus::getMsg($_code), [], $_code);
  94. }
  95. if (empty($agent_id)) {
  96. $_agent_id = get_val($this->rq_data, 'agent_id', 0);
  97. }
  98. if (!empty($_agent_id)) {
  99. (new HuoSession($this->mem_id))->setAgentId($_agent_id);
  100. }
  101. /* 拼接游戏地址 */
  102. $_game_class = new Game();
  103. $_play_url = $_game_class->getPlayUrl($_game_id);
  104. if (is_numeric($_play_url)) {
  105. $this->error(GameStatus::getMsg($_play_url), [], $_play_url);
  106. }
  107. $_app_key = $_game_class->getAppkey($_game_id);
  108. /* 判断是否登陆 */
  109. if (empty($this->mem_id)) {
  110. /* 未登陆 显示登陆页面 */
  111. $this->assign('game_id', $_game_id);
  112. $this->assign('agent_id', $_agent_id);
  113. return $this->fetch('game/login');
  114. }
  115. $_mem_data = MemCache::ins()->getInfoById($this->mem_id);
  116. $_mg_data = (new Member())->memGameLogin($_mem_data, $game_id);
  117. $_param['app_id'] = $game_id;
  118. $_param['mem_id'] = !empty($_mg_data['id']) ? $_mg_data['id'] : $this->mem_id;
  119. $_param['user_token'] = SimpleSec::encode(session_id(),config('CPAUTHCODE'));
  120. $_param_str = StrUtils::createLinkString($_param);
  121. $_sign = md5($_param_str.'&app_key='.$_app_key);
  122. $_param_str = $_param_str.'&sign='.$_sign;
  123. return redirect($_play_url.'?'.$_param_str);
  124. }
  125. }