12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace App\Http\Middleware;
- use App\Exceptions\CommonException;
- use App\Http\Enum\ErrorEnum;
- use Closure;
- use Tool\ShanTaoTool\BaseAuth\AdminAuth;
- class CheckAuthMiddleware
- {
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @return mixed
- */
- public function handle($request, Closure $next)
- {
- //判断用户权限
- $path = $request->path();
- $token = $request->header("apiToken");
- //判断tocken是否存在
- if(!$token){
- throw new CommonException(ErrorEnum::VALIDATE_TOKEN);
- }
- $data = AdminAuth::checkUserAuth($path,$token);
- //获取到用户ID塞入header头
- $request->headers->set("userId",$data["id"]);
- $request->headers->set("userAccount",$data["user_name"]);
- return $next($request);
- }
- }
|