123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- 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;
- }
-
- public function index() {
-
- $_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');
-
- $this->checkParam();
-
- $this->checkAppid();
-
- $this->verifySign();
- $this->assign('app_id', $this->app_id);
- $this->assign('mem_id', $this->mem_id);
- return $this->fetch('game/test');
- }
-
- 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;
- }
-
- 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');
- }
- }
-
- private function checkAuth() {
-
- return true;
- }
-
- 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;
- }
- }
|