route()->getAction(); $controller = class_basename($action['controller']); list($controller, $action) = explode('@', $controller); $noLoginActs = ['LoginController','TestController','NotifyController','IndexController','TaskController']; $token = $request->headers->get('Authorization'); if (strpos($token, 'Bearer ') !== false) { $token = str_replace("Bearer ", null, $token); if($token == 'app123'){ $userId = ConfigService::make()->getConfigByCode('test_uid'); $userId = $userId? $userId : 0; }else{ // JWT解密token $jwt = new Jwt('jwt_app'); $userId = $jwt->verifyToken($token); } } else { $userId = 0; } // 语言本地化,参数预处理 $locale = session('locale_lang'); if($userId>0){ $locale = RedisService::get("stores:locale:lang_{$userId}"); $locale = $locale? $locale : session('locale_lang'); if($locale){ session('locale_lang', $locale); app()->setLocale($locale); } }else if ($locale){ app()->setLocale($locale); } if (!$userId && !in_array($controller, $noLoginActs)) { // 判断用户未登录就跳转至登录页面 // 在这里可以定制你想要的返回格式, 亦或者是 JSON 编码格式 return response()->json(message(1004, false, null, 403)); } //如果已登录则执行正常的请求 return $response; } }