123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace App\Http\Middleware;
- use App\Exceptions\CommonException;
- use App\Http\Enum\ErrorEnum;
- use App\Http\Utils\BaseUtil;
- 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)
- {
- $token = $request->header("wechatToken");
- //判断tocken是否存在
- if(!$token){
- throw new CommonException(ErrorEnum::VALIDATE_TOKEN);
- }
- //判断缓存中是否存在
- $userId = BaseUtil::getCacheFromRedis($token);
- if(!$userId){
- throw new CommonException(ErrorEnum::VALIDATE_TOKEN);
- }
- $request->headers->set("user_id",$userId);
- return $next($request);
- }
- }
|