From 3a3fac7c554932d1cfd1ad309272d01bd2def103 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Fri, 19 Aug 2022 18:14:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=9C=E7=A8=8B=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Remote/CallController.php | 21 +++++++++++++++++++ app/Models/Module/Module.php | 13 ++++++++++++ routes/api/client.php | 5 ++++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Remote/CallController.php diff --git a/app/Http/Controllers/Remote/CallController.php b/app/Http/Controllers/Remote/CallController.php new file mode 100644 index 0000000..465d011 --- /dev/null +++ b/app/Http/Controllers/Remote/CallController.php @@ -0,0 +1,21 @@ +validate([ + 'func' => 'required|string|max:255', + ]); + + $response = $module->remote($request->func, $request->all()); + + return $this->apiResponse($response[0], $response[1]); + } +} diff --git a/app/Models/Module/Module.php b/app/Models/Module/Module.php index ec00a6d..a0d6061 100644 --- a/app/Models/Module/Module.php +++ b/app/Models/Module/Module.php @@ -2,6 +2,7 @@ namespace App\Models\Module; +use Http; use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -24,6 +25,18 @@ class Module extends Authenticatable 'api_token' ]; + + public function remote($func, $requests) + { + $http = Http::remote($this->api_token, $this->url); + $response = $http->post('functions/' . $func, $requests); + + $json = $response->json(); + $status = $response->status(); + + return [$json, $status]; + } + protected static function boot() { parent::boot(); diff --git a/routes/api/client.php b/routes/api/client.php index 20ba11e..3286e6f 100644 --- a/routes/api/client.php +++ b/routes/api/client.php @@ -1,7 +1,7 @@ name('call'); + });