CheckJwtToken.php 628 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\middleware;
  4. use think\Response;
  5. class CheckJwtToken
  6. {
  7. /**
  8. * 处理请求
  9. *
  10. * @param \think\Request $request
  11. * @param \Closure $next
  12. * @return Response
  13. */
  14. public function handle($request, \Closure $next)
  15. {
  16. $token = $request->header('token') ?? '';
  17. if(! $token) {
  18. return json(['code' => 777 , 'msg' => '请求有误!' , 'data' => null]);
  19. }
  20. $data = checkToken($token);
  21. if (0 != $data['code']){
  22. return json($data);
  23. }
  24. return $next($request);
  25. }
  26. }