header('TOKEN'); $request->user = $this->checkUser($token); return $next($request); } /** * 检查数据是否正常 * @param $token */ private function checkUser($token) { try{ list($headb64, $bodyb64, $cryptob64) = explode('.', $token); $payload = JWT::jsonDecode(JWT::urlsafeB64Decode($bodyb64)); $uid = $payload->uid; $member = (new Member)->where('uid',$uid)->find(); if(empty($member)) { throw new AuthException('请重新登录', -99); } return $member->toArray(); }catch (\Throwable $e) { throw new AuthException('请重新登录', -99); } } }