From b1155077ae5e920e4237b865912e67550785d9dd Mon Sep 17 00:00:00 2001 From: wikiboss Date: Sat, 12 Sep 2026 16:57:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B1=87=E4=BB=98?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=90=AF=E7=94=A8=E7=8A=B6=E6=80=81=E3=80=81?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E9=92=A9=E5=AD=90=E6=B3=A8=E5=86=8C=E4=B8=8E?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E8=84=9A=E6=9C=AC=E5=B9=B3=E6=BB=91=E9=87=8D?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/shopro/library/PayService.php | 2 +- addons/shopro_huifu/info.ini | 2 +- application/extra/addons.php | 23 +++++++ deploy.sh | 6 ++ tests/HuifuBridgeTest.php | 93 ++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 tests/HuifuBridgeTest.php diff --git a/addons/shopro/library/PayService.php b/addons/shopro/library/PayService.php index aebea17..d49cfd6 100644 --- a/addons/shopro/library/PayService.php +++ b/addons/shopro/library/PayService.php @@ -154,7 +154,7 @@ class PayService } if ((new \addons\shopro\library\split\Config())->isEnable()) { - $order['settle_info'] = ['profit_sharing' => true]; + $order['profit_sharing'] = 'Y'; } $order['total_fee'] = $order['total_fee'] * 100; diff --git a/addons/shopro_huifu/info.ini b/addons/shopro_huifu/info.ini index 5367357..6a0c550 100644 --- a/addons/shopro_huifu/info.ini +++ b/addons/shopro_huifu/info.ini @@ -4,7 +4,7 @@ intro = 汇付斗拱小程序微信支付与延时分账插件 author = Shopro website = https://paas.huifu.com version = 1.0.0 -state = 0 +state = 1 url = /addons/shopro_huifu first_menu = shopro_huifu/config license = regular diff --git a/application/extra/addons.php b/application/extra/addons.php index 2102e43..18d2328 100644 --- a/application/extra/addons.php +++ b/application/extra/addons.php @@ -29,10 +29,33 @@ return [ ], 'app_init' => [ 'shopro', + 'shopro_huifu', + 'shopro_wechat_trade', ], 'config_init' => [ 'summernote', ], + 'shopro_pay_create' => [ + 'addons\\shopro_huifu\\listener\\PayCreateHook', + ], + 'shopro_pay_refund' => [ + 'addons\\shopro_huifu\\listener\\RefundHook', + ], + 'shopro_split_execute' => [ + 'addons\\shopro_huifu\\listener\\SplitHook', + ], + 'shopro_commission_apply_after' => [ + 'addons\\shopro_huifu\\listener\\CommissionApplyHook', + ], + 'shopro_regional_agent_apply_after' => [ + 'addons\\shopro_huifu\\listener\\RegionalAgentApplyHook', + ], + 'order_send_after' => [ + 'addons\\shopro_wechat_trade\\listener\\ShippingHook', + ], + 'order_confirm_after' => [ + 'addons\\shopro_wechat_trade\\listener\\ConfirmHook', + ], ], 'route' => [], 'priority' => [], diff --git a/deploy.sh b/deploy.sh index a336e59..fa80665 100644 --- a/deploy.sh +++ b/deploy.sh @@ -41,6 +41,12 @@ fi chmod -R 777 runtime 2>/dev/null || true chmod -R 775 public/uploads 2>/dev/null || true +# 平滑重载 PHP-FPM 刷新 OPcache 字节码缓存 +if [ -x "/etc/init.d/php-fpm-73" ]; then + echo "[${DATE}] 平滑重载 PHP-FPM 7.3..." >> "${LOG_FILE}" + /etc/init.d/php-fpm-73 reload >> "${LOG_FILE}" 2>&1 || true +fi + COMMIT_INFO=$(git log -1 --pretty=format:"%h - %s (%an, %cd)") echo "[${DATE}] 当前最新版本: ${COMMIT_INFO}" >> "${LOG_FILE}" echo "[${DATE}] >>> 部署成功完成" >> "${LOG_FILE}" diff --git a/tests/HuifuBridgeTest.php b/tests/HuifuBridgeTest.php new file mode 100644 index 0000000..14f6556 --- /dev/null +++ b/tests/HuifuBridgeTest.php @@ -0,0 +1,93 @@ +testInfoIniStateEnabled(); + $this->testPayServiceProfitSharingParameter(); + $this->testDeployScriptContainsPhpFpmReload(); + $this->testAddonsHooksRegistered(); + + echo "\n测试结果: {$this->passed} 通过, {$this->failed} 失败\n"; + if ($this->failed > 0) { + exit(1); + } + } + + private function assert($condition, $message) + { + if ($condition) { + echo " [PASS] {$message}\n"; + $this->passed++; + } else { + echo " [FAIL] {$message}\n"; + $this->failed++; + } + } + + /** + * 测试 addons/shopro_huifu/info.ini 中 state 必须为 1 + */ + public function testInfoIniStateEnabled() + { + $iniPath = __DIR__ . '/../addons/shopro_huifu/info.ini'; + $this->assert(is_file($iniPath), "info.ini 必须存在: {$iniPath}"); + + $info = parse_ini_file($iniPath); + $state = $info['state'] ?? null; + $this->assert($state === '1' || $state === 1, "shopro_huifu 插件 state 必须为 1 (启用),当前为: " . var_export($state, true)); + } + + /** + * 测试 PayService.php 中不能向 Yansongda v2 传递 settle_info 数组,避免 Array to string conversion 报错 + */ + public function testPayServiceProfitSharingParameter() + { + $payServicePath = __DIR__ . '/../addons/shopro/library/PayService.php'; + $this->assert(is_file($payServicePath), "PayService.php 必须存在"); + + $content = file_get_contents($payServicePath); + $hasSettleInfoArray = strpos($content, "\$order['settle_info'] = ['profit_sharing' => true]") !== false; + $this->assert(!$hasSettleInfoArray, "PayService 中不能包含 settle_info 数组赋值 (会导致 Yansongda v2 XML 序列化报 Array to string conversion)"); + } + + /** + * 测试 deploy.sh 部署脚本中必须包含 php-fpm reload 命令刷新 OPcache + */ + public function testDeployScriptContainsPhpFpmReload() + { + $deployScriptPath = __DIR__ . '/../deploy.sh'; + $this->assert(is_file($deployScriptPath), "deploy.sh 脚本必须存在"); + + $content = file_get_contents($deployScriptPath); + $hasReload = strpos($content, 'php-fpm-73 reload') !== false || strpos($content, 'php-fpm reload') !== false; + $this->assert($hasReload, "deploy.sh 部署脚本必须包含 php-fpm reload 刷新 OPcache"); + } + + /** + * 测试 application/extra/addons.php 中必须注册 shopro_huifu 及 shopro_pay_create 钩子 + */ + public function testAddonsHooksRegistered() + { + $addonsPath = __DIR__ . '/../application/extra/addons.php'; + $this->assert(is_file($addonsPath), "addons.php 必须存在"); + + $addons = require $addonsPath; + $appInit = $addons['hooks']['app_init'] ?? []; + $this->assert(in_array('shopro_huifu', $appInit), "addons.php app_init 必须包含 shopro_huifu"); + + $payCreate = $addons['hooks']['shopro_pay_create'] ?? []; + $this->assert(!empty($payCreate), "addons.php 必须注册 shopro_pay_create 钩子"); + } +} + +$test = new HuifuBridgeTest(); +$test->run();