VerifyToken.php 643 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\common\middleware;
  4. use app\exception\BaseException;
  5. use Jwt;
  6. use think\Exception;
  7. use think\Response;
  8. class VerifyToken
  9. {
  10. /**
  11. * 处理请求
  12. *
  13. * @param \think\Request $request
  14. * @param \Closure $next
  15. * @return Response
  16. */
  17. public function handle($request, \Closure $next)
  18. {
  19. $url = $request->url();
  20. $has_login = strpos($url,'login');
  21. $token = $request->param('token');
  22. if($has_login >= 0 && $has_login !== false) return $next($request);
  23. throw new BaseException('未登录,请重新登录!',403);
  24. }
  25. }