user()->calculate(); return $this->success($module); } public function call(Request $request, Module $module): Response|JsonResponse { $path = $this->fixPath($request, $module, 'api'); $method = Str::lower($request->method()); try { $response = $module->request($method, $path, $request->all()); } catch (ConnectException $e) { Log::error('在执行 call ' . $method . ' ' . $path . ' 时发生错误: ' . $e->getMessage()); return $this->serviceUnavailable(); } if ($response['json'] === null && $response['body'] !== null) { return response($response['body'], $response['status']); } return $this->moduleResponse($response['json'], $response['status']); } private function fixPath(Request $request, Module $module, $prefix): string { $path = substr($request->path(), strlen("/$prefix/modules/$module->id")); // 只允许最基本的字符,以及 _,- return preg_replace('/[^a-zA-Z0-9_\-\/]/', '', $path); } public function exportCall(Request $request, Module $module): Response|JsonResponse { $path = $this->fixPath($request, $module, 'modules'); $method = Str::lower($request->method()); $response = $module->moduleRequest($method, $path, $request->all()); if ($response['json'] === null && $response['body'] !== null) { return response($response['body'], $response['status']); } return $this->moduleResponse($response['json'], $response['status']); } }