You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
35 lines
1.1 KiB
<?php
|
|
|
|
namespace app\utility;
|
|
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
use think\facade\Log;
|
|
|
|
class RequestChatServer
|
|
{
|
|
public function ReqChatServer(string $url, array $data): array
|
|
{
|
|
try {
|
|
Log::info("请求URL==".$url." 请求Param==".json_encode($data));
|
|
$resBody = [];
|
|
$client = new Client();
|
|
$response = $client->post($url, [
|
|
'json' => $data,
|
|
]);
|
|
$statusCode = $response->getStatusCode();
|
|
Log::error("请求聊天服返回:code==".$statusCode);
|
|
Log::error("请求聊天服返回:body==". $response->getBody());
|
|
if ($statusCode == 200) {
|
|
$resBody = json_decode($response->getBody(), true); // 转换为数组
|
|
}
|
|
return $resBody;
|
|
} catch (GuzzleException $e) {
|
|
Log::error("请求聊天服异常 - guzzle: " . $e->getMessage());
|
|
return [];
|
|
} catch (\Exception $exception) {
|
|
Log::error("请求聊天服异常 - exc:" . $exception->getMessage());
|
|
return [];
|
|
}
|
|
}
|
|
}
|