``` <?php // // AuthToken.php // 请求前身份验证行为 // // Created by lijianlin on 2019-05-31. // Copyright 2019 lijianlin. All rights reserved. // namespace app\saas\behavior; use think\Request; use app\common\model\Merror; use app\common\controller\Nredis; use app\saas\model\User; use Config; class AuthToken { public function run(Request $request) { $token = $request->header('token') ?? ''; $uid = $request->header('uid') ?? ''; $get_user = function () use ($uid, $token) { $user = User::get($uid); $analysis_user = function () use ($uid, $token) { $redis = Nredis::getInstance(); $userInfo = $redis->get(Config::get('saas.session_prix') . $uid . '_' . $token); $check_token = function () use ($token, &$userInfo) { $userData = json_decode($userInfo, true); $userData['data']['token'] != $token ? Merror::getInstance()->jsonApi(40005) : ''; }; $userInfo === false ? Merror::getInstance()->jsonApi(40004) : $check_token(); }; empty($user) ? Merror::getInstance()->jsonApi(40003) : $analysis_user(); }; $uid == '' || $token == '' ? Merror::getInstance()->jsonApi(40000) : $get_user(); } } ```