* @version : HUOSDK 8.0 */ namespace api\apple\controller; use huo\controller\game\Game; use huolib\tool\StrUtils; use think\Config; use think\Controller; use think\Log; class GameTestController extends Controller { private $mem_id; private $app_id; private $user_token; private $sign; private $app_key; function _initialize() { parent::_initialize(); Config::set('default_return_type', 'html'); } private function cpReturn($status = '0', $msg = '请求参数错误') { $_rdata = array( 'status' => $status, 'msg' => $msg ); echo json_encode($_rdata); exit; } /** * H5-游戏demo地址 * http://doc.1tsdk.com/138?page_id=3216 * 【域名】/game/test */ public function index() { /* 1 查询是否具有访问权限 */ $_rs = $this->checkAuth(); $_url_data = $this->request->param(); Log::write($_url_data, Log::LOG);//记录请求数据 $this->app_id = get_val($this->rq_data, 'app_id'); $this->mem_id = get_val($this->rq_data, 'mem_id'); $this->user_token = get_val($this->rq_data, 'user_token'); $this->sign = get_val($this->rq_data, 'sign'); /* 0 检查参数 */ $this->checkParam(); /* 11 校验APPID */ $this->checkAppid(); /* 12 校验签名 */ $this->verifySign(); $this->assign('app_id', $this->app_id); $this->assign('mem_id', $this->mem_id); return $this->fetch('game/test'); } /** * @return bool */ private function checkAppid() { $_app_key = (new Game())->getAppKey($this->app_id); if (empty($_app_key)) { $this->cpReturn('11', '游戏ID(app_id)错误'); } $this->app_key = $_app_key; return true; } /** * 1 校验参数 */ private function checkParam() { if (empty($this->app_id) || $this->app_id < 0) { $this->cpReturn('0', '请求参数为空 app_id'); } if (empty($this->mem_id) || $this->mem_id < 0) { $this->cpReturn('0', '请求参数为空 mem_id'); } if (empty($this->user_token)) { $this->cpReturn('0', '请求参数为空 user_token'); } if (empty($this->sign)) { $this->cpReturn('0', '请求参数为空 sign'); } } /** * 校验权限 * * @return bool */ private function checkAuth() { // $this->cpReturn('100','没有接口访问权限'); return true; } /*12 校验签名 */ private function verifySign() { $_param['app_id'] = $this->app_id; $_param['mem_id'] = $this->mem_id; $_param['user_token'] = $this->user_token; $_param_str = StrUtils::createLinkString($_param); $_verify_sign = md5($_param_str.'&app_key='.$this->app_key); if ($this->sign != $_verify_sign) { $this->cpReturn('12', '签名校验不通过'); } return true; } }