38 lines
800 B
PHP
38 lines
800 B
PHP
<?php
|
|
|
|
namespace App\Clients;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Http\Client\PendingRequest;
|
|
use Illuminate\Http\Client\Response;
|
|
|
|
class AgentClient
|
|
{
|
|
private string $baseUrl;
|
|
private PendingRequest $http;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->baseUrl = config('services.agent.url');
|
|
$this->http = Http::timeout(config('services.agent.timeout', 30))
|
|
->withoutVerifying();
|
|
}
|
|
|
|
/**
|
|
* 分发消息到Agent
|
|
*/
|
|
public function dispatchMessage(array $data): Response
|
|
{
|
|
return $this->http->post($this->baseUrl . '/rpc/dispatchMessage', $data);
|
|
}
|
|
|
|
/**
|
|
* 测试连接
|
|
*/
|
|
public function testConnection(): Response
|
|
{
|
|
return $this->http->get($this->baseUrl . '/health');
|
|
}
|
|
}
|
|
|