toData('400', '请求方法不在支持列表中'); } Log::info("请求URL==".$url." 请求Param==".json_encode($data)); $resBody = []; $client = new Client(); if ($method == 'PUT') { $response = $client->put($url, [ 'json' => $data, ]); } else { $response = $client->post($url, [ 'json' => $data, ]); } $statusCode = $response->getStatusCode(); Log::error("请求聊天服返回:code==".$statusCode." body==". $response->getBody()); if ($statusCode == 200) { $resBody = json_decode($response->getBody(), true); // 转换为数组 } return $resBody; } catch (GuzzleException $e) { Log::error("请求聊天服异常 - guzzle: " . $e->getMessage()); return $this->toData('500', $e->getMessage()); } catch (\Exception $exception) { Log::error("请求聊天服异常 - exc:" . $exception->getMessage()); return $this->toData('500', $exception->getMessage()); } } }