1
This commit is contained in:
parent
a1b5c356ea
commit
6f4b2c46d3
@ -686,22 +686,32 @@ class Index extends Frontend
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转发原始请求到测试环境
|
* 转发原始请求到多个环境(默认:qimen + 测试环境)
|
||||||
* @param string $path 目标路径
|
* @param string $path 目标路径
|
||||||
* @param string $rawBody 原始报文(POST body)
|
* @param string $rawBody 原始报文(POST body)
|
||||||
* @param string $host 目标域名
|
* @param array|string $hosts 目标域名(可传单个字符串)
|
||||||
* @return bool
|
* @return array 每个目标地址的转发结果
|
||||||
*/
|
*/
|
||||||
private function forwardToTest($path, $rawBody = '', $host = 'http://qimen.wms.gztbyc.com')
|
private function forwardToTest($path, $rawBody = '', $hosts = [
|
||||||
|
'http://qimen.wms.gztbyc.com',
|
||||||
|
'http://test_wms.o.gztbyc.com',
|
||||||
|
])
|
||||||
{
|
{
|
||||||
try {
|
if (is_string($hosts)) {
|
||||||
// 拼装目标地址:域名 + 路径 + 原始GET参数
|
$hosts = [$hosts];
|
||||||
$url = rtrim($host, '/') . '/' . ltrim($path, '/');
|
}
|
||||||
|
|
||||||
|
// 原始GET参数(所有环境共用)
|
||||||
$query = $this->request->get();
|
$query = $this->request->get();
|
||||||
|
|
||||||
|
$results = [];
|
||||||
|
foreach ($hosts as $host) {
|
||||||
|
$url = rtrim($host, '/') . '/' . ltrim($path, '/');
|
||||||
if (!empty($query)) {
|
if (!empty($query)) {
|
||||||
$url .= (stripos($url, '?') !== false ? '&' : '?') . http_build_query($query);
|
$url .= (stripos($url, '?') !== false ? '&' : '?') . http_build_query($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
curl_setopt($ch, CURLOPT_POST, 1);
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
@ -717,18 +727,22 @@ class Index extends Frontend
|
|||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
if ($error) {
|
if ($error) {
|
||||||
\think\Log::error('转发到测试环境失败: ' . $url . ' 错误: ' . $error);
|
\think\Log::error('转发失败: ' . $url . ' 错误: ' . $error);
|
||||||
return false;
|
$results[$url] = false;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
\think\Log::info('转发到测试环境成功: ' . $url . ' 返回: ' . $response);
|
\think\Log::info('转发成功: ' . $url . ' 返回: ' . $response);
|
||||||
return true;
|
$results[$url] = true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\think\Log::error('转发到测试环境异常: ' . $e->getMessage());
|
\think\Log::error('转发异常: ' . $url . ' 错误: ' . $e->getMessage());
|
||||||
return false;
|
$results[$url] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修复XML编码问题
|
* 修复XML编码问题
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user