From ca919e4a48a7b1c91533af42990c418c36b480ea Mon Sep 17 00:00:00 2001 From: liufumingren Date: Mon, 21 Sep 2026 17:03:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Authorization=20=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E5=8E=9F=E6=96=87(=E5=90=ABGET=E5=8F=82=E6=95=B0)=E8=BD=AC?= =?UTF-8?q?=E5=8F=91=E5=88=B0=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/controller/Index.php | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index 1eaa5d9..1ef05a8 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -99,6 +99,9 @@ class Index extends Frontend // 获取原始POST数据 $from_xml = file_get_contents('php://input'); + // 原文(含GET参数)转发一份到测试环境 + $this->forwardToTest('/Authorization', $from_xml); + // 记录日志用于调试 \think\Log::info('微信回调参数: ' . json_encode([ 'signature' => $signature, @@ -654,6 +657,51 @@ class Index extends Frontend } } + /** + * 转发原始请求到测试环境 + * @param string $path 目标路径 + * @param string $rawBody 原始报文(POST body) + * @param string $host 目标域名 + * @return bool + */ + private function forwardToTest($path, $rawBody = '', $host = 'http://test.wms.gztbyc.com') + { + try { + // 拼装目标地址:域名 + 路径 + 原始GET参数 + $url = rtrim($host, '/') . '/' . ltrim($path, '/'); + $query = $this->request->get(); + if (!empty($query)) { + $url .= (stripos($url, '?') !== false ? '&' : '?') . http_build_query($query); + } + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $rawBody); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:', 'Content-Type: text/xml']); + + $response = curl_exec($ch); + $error = curl_error($ch); + curl_close($ch); + + if ($error) { + \think\Log::error('转发到测试环境失败: ' . $url . ' 错误: ' . $error); + return false; + } + + \think\Log::info('转发到测试环境成功: ' . $url . ' 返回: ' . $response); + return true; + } catch (\Exception $e) { + \think\Log::error('转发到测试环境异常: ' . $e->getMessage()); + return false; + } + } + + /** * 修复XML编码问题 */