diff --git a/app/Http/Controllers/Remote/ModuleController.php b/app/Http/Controllers/Remote/ModuleController.php index 9ea6bcb..b8f00a4 100644 --- a/app/Http/Controllers/Remote/ModuleController.php +++ b/app/Http/Controllers/Remote/ModuleController.php @@ -17,24 +17,26 @@ public function index() public function call(Request $request, Module $module) { - $this->validate($request, [ - 'func' => 'required|string' - ]); + // $this->validate($request, [ + // 'func' => 'required|string' + // ]); - $func = $request->func; + // $func = $request->func; - // 不能让 func 的首个字符为 / - if (Str::startsWith($func, '/')) { - $func = substr($func, 1); - } + // // 不能让 func 的首个字符为 / + // if (Str::startsWith($func, '/')) { + // $func = substr($func, 1); + // } + + $path = request()->path(); + + // 删除 modules/{module} 的部分 + $path = substr($path, strlen('/api/modules/' . $module->id)); // 过滤除了 "/" 以外的特殊字符 - $func = preg_replace('/[^a-zA-Z0-9\/]/', '', $func); + $path = preg_replace('/[^a-zA-Z0-9\/]/', '', $path); - - // dd($func); - $method = Str::lower($request->method()); // 如果 method 为 post, 检查用户余额 @@ -47,7 +49,7 @@ public function call(Request $request, Module $module) } - $response = $module->remoteRequest($method, $func, $request->all()); + $response = $module->remoteRequest($method, $path, $request->all()); if ($response['json'] === null && $response['body'] !== null) { return response($response['body'], $response['status']); diff --git a/app/Models/Module/Module.php b/app/Models/Module/Module.php index 3b1029b..61506af 100644 --- a/app/Models/Module/Module.php +++ b/app/Models/Module/Module.php @@ -53,12 +53,10 @@ public function remote($func, $requests) // post, get, patch, delete 等请求 - public function remoteRequest($method, $func, $requests) + public function remoteRequest($method, $path, $requests) { $http = Http::remote($this->api_token, $this->url) - ->accept('application/json') - ->withHeaders(['X-Func' => $func]); - + ->accept('application/json'); unset($requests['func']); @@ -73,7 +71,7 @@ public function remoteRequest($method, $func, $requests) $requests['user_id'] = $user['id']; - $response = $http->{$method}("functions/{$func}", $requests); + $response = $http->{$method}("functions/{$path}", $requests); $json = $response->json();