public function handle($request, \Closure $next)
{
//路由中间件
// $token = JWT::getRequestToken();
//
// $key = JWT::verifyjwt($token)->getData();
//
// if ($key['code'] !== 200) {
// return fail('非法请求');
// }
// return $next($request);
//全局中间件,后置
$res = $next($request);
//判断当前访问路径是否在定义的当中
if (!in_array($request->pathinfo(), $this->arr)) {
//获取token值
$token = JWT::getRequestToken();
try {
//验证token
JWT::verifyjwt($token)->getData();
}catch (Exception $exception){
return fail($exception->getMessage());
}
}
//放行
return $res;
}
thinkphp全局中间件
最新推荐文章于 2023-09-09 17:13:33 发布