增加调用函数
This commit is contained in:
parent
3a3fac7c55
commit
a006156bb4
@ -2,19 +2,24 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Remote;
|
namespace App\Http\Controllers\Remote;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Models\Host;
|
||||||
use App\Models\Module\Module;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Module\Module;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
class CallController extends Controller
|
class CallController extends Controller
|
||||||
{
|
{
|
||||||
// invoke the remote method
|
// invoke the remote method
|
||||||
public function __invoke(Request $request, Module $module) {
|
public function host(Request $request, Host $host, $func) {
|
||||||
$request->validate([
|
$host->load('module');
|
||||||
'func' => 'required|string|max:255',
|
$response = $host->module->remoteHost($host->id, $func, $request->all());
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $module->remote($request->func, $request->all());
|
return $this->apiResponse($response[0], $response[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function module(Request $request, Module $module, $func)
|
||||||
|
{
|
||||||
|
$response = $module->remote($func, $request->all());
|
||||||
|
|
||||||
return $this->apiResponse($response[0], $response[1]);
|
return $this->apiResponse($response[0], $response[1]);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,17 @@ class Module extends Authenticatable
|
|||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function remoteHost($host_id, $func, $requests)
|
||||||
|
{
|
||||||
|
$http = Http::remote($this->api_token, $this->url);
|
||||||
|
$response = $http->post("hosts/{$host_id}/functions/" . $func, $requests);
|
||||||
|
|
||||||
|
$json = $response->json();
|
||||||
|
$status = $response->status();
|
||||||
|
|
||||||
|
return [$json, $status];
|
||||||
|
}
|
||||||
|
|
||||||
public function remote($func, $requests)
|
public function remote($func, $requests)
|
||||||
{
|
{
|
||||||
$http = Http::remote($this->api_token, $this->url);
|
$http = Http::remote($this->api_token, $this->url);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
Route::apiResource('work-orders.replies', User\WorkOrder\ReplyController::class);
|
Route::apiResource('work-orders.replies', User\WorkOrder\ReplyController::class);
|
||||||
|
|
||||||
// 调用远程 API
|
// 调用远程 API
|
||||||
Route::post('module/{module}', CallController::class)->name('call');
|
Route::post('hosts/{host}/func/{func}', [CallController::class, 'host'])->name('host.call');
|
||||||
|
Route::post('/modules/{module}/func/{func}', [CallController::class, 'module'])->name('module.call');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user