header('X-Token'); if(!$XToken) throw new AuthException('token不存在'); $token = trim($request->header('X-Token')); if (!$token) throw new AuthException('无效的token'); $data = Auth::checkToken($token,$request->param()); if(!$data) throw new AuthException('无效的token!'); if(isset($data['code']) && $data['code'] == 101) throw new AuthException('用户不存在'); if(isset($data['code']) && $data['code'] == 500) throw new AuthException('系统错误'); $request->macro('token', function () use (&$token) { return $token; }); $request->macro('userInfo', function () use (&$data) { return $data['userInfo']; }); $request->macro('uid', function () use (&$data) { return $data['userInfo']['uid']; }); return $next($request); } public function after(Response $response) { // TODO: Implement after() method. } }