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
- {
-
- public function handle($request, Closure $next)
- {
- $token = $request->header("wechatToken");
-
- 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);
- }
- }
|