123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- * GameTestController.php UTF-8
- * 游戏测试
- *
- * @date : 2018/5/10 14:02
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace api\sdk\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($_url_data, 'app_id');
- $this->mem_id = get_val($_url_data, 'mem_id');
- $this->user_token = get_val($_url_data, 'user_token');
- $this->sign = get_val($_url_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;
- }
- }
|