From 2de43c76b8107c0686c3b9ee9a812e67d03ddd68 Mon Sep 17 00:00:00 2001 From: tpingzhang <635929049@qq.com> Date: Thu, 21 Nov 2019 22:41:11 +0800 Subject: [PATCH] =?UTF-8?q?user=5Finfo=20=E9=AA=8C=E8=AF=81user=5Ftoken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sdk/Controller/BaseController.class.php | 43 ++++++++++++------- .../GameGiftPageController.class.php | 2 +- .../Sdk/Controller/UserController.class.php | 15 +------ .../Sdk/Controller/UserHController.class.php | 2 +- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Application/Sdk/Controller/BaseController.class.php b/Application/Sdk/Controller/BaseController.class.php index 5bb184b6..c5ff7462 100644 --- a/Application/Sdk/Controller/BaseController.class.php +++ b/Application/Sdk/Controller/BaseController.class.php @@ -18,7 +18,7 @@ class BaseController extends RestController{ protected $noToken = [ 'user_login', 'send_sms', 'verify_sms', 'forget_password', 'init_sdk', 'device_record', 'force_update', 'thirdparty', 'get_customer_question', - 'get_down_time', 'customer_contact' + 'get_down_time', 'customer_contact', 'user_info' ]; // 不需要验证TOKEN的接口 protected $noNeedToken = [ @@ -49,19 +49,7 @@ class BaseController extends RestController{ || in_array($c.".".$a, $this->noToken))) { if ($data['api_ver'] == 2) { - $userToken = M('user_token', 'tab_')->where([ - 'user_id' => $data['user_id'], - 'game_id' => $data['game_id'] - ])->getField('user_token'); - if (!$userToken || $userToken != $data['user_token']) { - echo base64_encode (json_encode(array( - "code" => 9999, - "msg" => "您已下线,请重新登入", - "data" => "" - ))); - exit (); - // 退出 - } + self::apiverify($data['user_id'], $data['game_id'], $data['user_token']); } } @@ -108,7 +96,7 @@ class BaseController extends RestController{ if (I('request.api_ver') == 2) { if (!(in_array($c, $this->noNeedToken) || in_array($a, $this->noNeedToken) || in_array($c.".".$a, $this->noNeedToken))) { - $user = self::webH5Vetify(); + $user = self::webH5Verify(); $this->userId = $user['userId']; $this->userToken = $user['userToken']; } @@ -116,7 +104,30 @@ class BaseController extends RestController{ } - public static function webH5Vetify() { + /* + * api接口 user_token 验证 + */ + public static function apiverify($userId, $gameId, $userToken) { + $token = M('user_token', 'tab_')->where([ + 'user_id' => $userId, + 'game_id' => $gameId + ])->getField('user_token'); + + if (!$token || $token != $userToken) { + echo base64_encode (json_encode(array( + "code" => 9999, + "msg" => "您已下线,请重新登入", + "data" => "" + ))); + exit (); + // 退出 + } + } + + /* + * webH5 user_token 验证 + */ + public static function webH5Verify() { $userToken = I("request.user_token"); if (!$userToken) { echo "token not found!!!"; diff --git a/Application/Sdk/Controller/GameGiftPageController.class.php b/Application/Sdk/Controller/GameGiftPageController.class.php index c45c579e..a5026934 100644 --- a/Application/Sdk/Controller/GameGiftPageController.class.php +++ b/Application/Sdk/Controller/GameGiftPageController.class.php @@ -10,7 +10,7 @@ class GameGiftPageController extends Controller{ public function _initialize() { // if (I("request.api_ver") == 2) { - $user = BaseController::webH5Vetify(); + $user = BaseController::webH5Verify(); $this->userId = $user['userId']; $this->userToken = $user['userToken']; // } diff --git a/Application/Sdk/Controller/UserController.class.php b/Application/Sdk/Controller/UserController.class.php index 0979b12e..ff261f47 100644 --- a/Application/Sdk/Controller/UserController.class.php +++ b/Application/Sdk/Controller/UserController.class.php @@ -11,6 +11,7 @@ use App\Model\UserModel; use App\Model\PointShopRecordModel; use Qiniu\json_decode; use Think\Log; +use App\Controller\BaseController; class UserController extends BaseController { @@ -1525,19 +1526,7 @@ class UserController extends BaseController $data = array(); //type为0需要验证user_token if($user['type'] == 0) { if ($user['api_ver'] == 2) { - $userToken = M('user_token', 'tab_')->where([ - 'user_id' => $user['user_id'], - 'game_id' => $user['game_id'] - ])->getField('user_token'); - if (!$userToken || $userToken != $user['user_token']) { - echo base64_encode (json_encode(array( - "code" => 9999, - "msg" => "您已下线,请重新登入", - "data" => "" - ))); - exit (); - // 退出 - } + self::apiverify($user['user_id'], $user['game_id'], $user['user_token']); } } switch ($user['type']) { diff --git a/Application/Sdk/Controller/UserHController.class.php b/Application/Sdk/Controller/UserHController.class.php index f2f0847a..c47d1a4e 100644 --- a/Application/Sdk/Controller/UserHController.class.php +++ b/Application/Sdk/Controller/UserHController.class.php @@ -11,7 +11,7 @@ class UserHController extends Controller public $userToken; public function _initialize() { - $user = BaseController::webH5Vetify(); + $user = BaseController::webH5Verify(); $this->userId = $user['userId']; $this->userToken = $user['userToken']; }