From 296e063e3cb3235e4cdec2e13fd5081785a5da35 Mon Sep 17 00:00:00 2001 From: hellcat Date: Sun, 1 Nov 2026 16:31:14 +0800 Subject: [PATCH] fix(payments): accept HTML cashiers and recognize WeChat HTTPS QR links --- app/Services/PaymentHealth/HttpsTransport.php | 2 +- app/Services/PaymentHealth/QrEvidence.php | 13 +++++++- docs/maintenance/PAYMENT_HEALTH.md | 22 ++++++++++++++ .../PaymentHealth/PaymentHealthTest.php | 30 +++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/app/Services/PaymentHealth/HttpsTransport.php b/app/Services/PaymentHealth/HttpsTransport.php index af25d32a..426dd14e 100644 --- a/app/Services/PaymentHealth/HttpsTransport.php +++ b/app/Services/PaymentHealth/HttpsTransport.php @@ -9,7 +9,7 @@ class HttpsTransport public function request(string $method,string $url,array $fields=[],bool $downstream=false): array { [$host,$ip]=$this->endpoint($url,$downstream); - $client=Http::withoutRedirecting()->connectTimeout(10)->timeout(25)->withUserAgent('XB-PaymentHealth/1.0') + $client=Http::withoutRedirecting()->connectTimeout(10)->timeout(25)->withUserAgent('XB-PaymentHealth/1.0')->accept('text/html') ->withOptions(['verify'=>true,'curl'=>[CURLOPT_RESOLVE=>[$host.':443:'.(str_contains($ip,':')?'['.$ip.']':$ip)]]]); $response=$method==='POST'?$client->asForm()->post($url,$fields):$client->get($url); $body=$response->body();if(strlen($body)>2097152)throw new RuntimeException('oversized_cashier_response'); diff --git a/app/Services/PaymentHealth/QrEvidence.php b/app/Services/PaymentHealth/QrEvidence.php index a129f6c0..7ace8ea2 100644 --- a/app/Services/PaymentHealth/QrEvidence.php +++ b/app/Services/PaymentHealth/QrEvidence.php @@ -11,7 +11,18 @@ class QrEvidence || preg_match('/(?:money|amount|price)["\x27\s:=]+'.preg_quote($amount,'/').'(?![0-9.])/i',$html); if(!$amountSeen)return false; $uri=$type==='wxpay'?'(?:wxpay:\/\/|weixin:\/\/wxpay\/)':'(?:alipays:\/\/|https:\/\/qr\.alipay\.com\/)'; - if(!preg_match('~'.$uri.'[^\s"\x27<>]+~i',$html))return false; + $paymentUriSeen=(bool)preg_match('~'.$uri.'[^\s"\x27<>]+~i',$html); + // This provider renders WeChat QR codes as an HTTPS short link. Inspect the + // complete URL so lookalike hosts or a URL embedded in another URL fail. + if(!$paymentUriSeen&&$type==='wxpay'&&preg_match_all('~https://[^\s"\x27<>\\\\]+~i',html_entity_decode($html,ENT_QUOTES|ENT_HTML5),$links)){ + foreach($links[0] as $link){ + $parts=parse_url($link); + if($parts!==false&&strtolower($parts['scheme']??'')==='https'&&strtolower($parts['host']??'')==='wxmpurl.cn' + &&!isset($parts['user'])&&!isset($parts['pass'])&&!isset($parts['port'])&&!isset($parts['fragment']) + &&($parts['path']??'/')!=='/'){$paymentUriSeen=true;break;} + } + } + if(!$paymentUriSeen)return false; // Structured rendering of a real payment URI, or a QR bitmap with three finder patterns. if(preg_match('~(?:new\s+QRCode|\.qrcode\s*\(|QRCode\.to(?:Canvas|DataURL|String))~i',$html))return true; if(preg_match_all('~data:image/png;base64,([A-Za-z0-9+/=]+)~',$html,$matches))foreach($matches[1]as$data){ diff --git a/docs/maintenance/PAYMENT_HEALTH.md b/docs/maintenance/PAYMENT_HEALTH.md index c25a2aab..37e20f2e 100644 --- a/docs/maintenance/PAYMENT_HEALTH.md +++ b/docs/maintenance/PAYMENT_HEALTH.md @@ -105,3 +105,25 @@ FUC只读聚合验证:生产当前启用epay,最近30日非管理员EPay WeC 19:47:35 +08:00原HN支付宝单已过期,严格拒绝恢复。用户随后明确追加授权仅一笔HN支付宝32元待支付测试单、不付款并在成功后恢复HN支付宝。19:51:29生产原EPay插件和已修复EpayProbe实际运行:网关仅POST一次,随后q.fenjingwl.cn GET HTTP200,fresh_cashier_qr、32元/支付URI/二维码严格验证通过,未误跟到授权登录页。随后只恢复HN支付宝,核对通道身份/配置与有效监测归属,在事务清除归属、保留原slot与每日预算;微信仍关闭。没有新增应用用户/订单、扫码或付款,商户平台有这一笔待支付记录。证据ali-fresh-claim/probe、私有请求/响应与ali-recovery.json均在本批备份目录。HN恢复通知使用稳定事件键经既有TeleHub调用方发送,初次回执queued,随后仅查询该回执确认sent;未重复投递。DPL开关/状态未人工修改,下一自然检测2026-11-01 00:00可用新检测结果自行恢复。微信故障仍未修通,需继续核对商户实际子通道路由;已有同单404证据可交支付平台,尚未对外发送。 本批共59项隔离测试258断言通过;已完成服务器侧发布验收,未做线上页面验收,未扫码、付款或验证到账。二维码漏判、告警文案与HN支付宝收银验收/恢复已完成;微信收银仍未修通,不把代码发布或收银通过写为实际付款/到账成功。 + +## 2026-11-01 FUC与HN微信对照:两处检测误判已定位 + +诊断已完成;用户在解释两项具体修复后明确“弄”,批准本轮核心实现、测试及HN/DPL发布。当前复核生产HEAD为f825c30038723c0c7d5ea0aadc0ce9286f3edc7e;HN/DPL支付宝1、微信2均关闭且具有有效监测归属,最近自动结果为12:00 cashier_not_found,每实例当日预算6。保留生产并行Stellar修改和所有自动账本,不以昨日支付宝恢复记录代替当前状态。 + +FUC生产只读数据及支付商后台已确认今日普通用户微信成功记录(50元/15元),其中15元单已支付且通知成功。FUC成功单与XB未付微信探测均为channel8/subchannel0/version0;当前随机HMAC比较确认网关、商户号、密钥、MD5一致。不能将差异归因为不同商户、管理员捷径或submit.php/mapi.php本身。 + +用户明确批准最多3笔HN微信待支付对照单、不付款。15:57:56至15:58:00已执行全部3笔:32元原32位格式、32元8位短格式、16元8位短格式,各仅一次mapi请求取得支付商成功返回,随后旧检测传输的收银POST均404,响应为相同通用404页面。因此格式或金额不是这次404的充分解释。三笔已用完授权;没有新增FUC/DPL应用订单或修改商户配置,没有扫码或付款;应用用户/订单计数、通道和自动状态保持。私有完整请求/响应保存在sitejp02的/root/codex-backups/xb-payment-health/manual-20261101-format-matrix-1/,不得复跑矩阵创建新单。 + +对上述同一批现有订单进行浏览器收银检查,16元短格式与32元长格式都显示正确金额和微信二维码。捕获浏览器实际POST与服务器原POST逐字段及编码字节比较均相同,目标IP亦相同。继续在同一生产HN服务器、同一32元订单、HTTP/1.1和原XB-PaymentHealth/1.0 User-Agent下控制变量:原请求404;仅添加Accept: text/html后200,出现32.00、二维码渲染器及支付链接;最后验证时间16:14:42 +08。未创建新订单。这定位HttpsTransport缺少HTML Accept头,不推断服务商故意拦截或某种WAF策略。 + +另一独立误判:QrEvidence只接受原生wxpay/weixin URI,实际收银页二维码内容为HTTPS wxmpurl.cn链接。对实际渲染的230px二维码截图使用ZXing离线解码,确认QR Code/valid=true、HTTPS、精确主机wxmpurl.cn;当前检测器仍返回false。二维码未展示、扫码或打开实际付款URI,此证据仅证明收银二维码可用,未完成资金支付或到账验收。脱敏解码结果位于codex/output/payment-format-diagnosis-20261101/browser-qr-decode-redacted.json。 + +本轮最小核心修复:HttpsTransport添加Accept: text/html;QrEvidence仅在微信分支识别精确HTTPS wxmpurl.cn支付链接,同时保持金额、二维码渲染/定位图案和现有TLS/公网DNS/SSRF校验,不泛化接受任意HTTPS链接、不请求二维码URL。回归覆盖请求头、真实页面形状的合成夹具、恶意相似主机、错误金额、无二维码、旧订单回调及人工停用归属。提交/推送/Git部署到HN/DPL和监测归属恢复已获本轮批准;支付宝须另有有效收银证据,不能用微信证明恢复。 + +旧Oct31订单被服务商改回调域名而提示“支付参数有变化”,该证据被排除出本轮控制变量结论。Windows经登记FUC反代仅做只读首页HTTP200,不声称FUC浏览器购买流程验收;服务商验证码由用户完成,VNC/RDP管理员会话发生切换后停止桌面输入。此次本机只访问第三方支付收银台,未访问本机禁访的项目线上入口;测试收银台已关闭以停止状态轮询。 + +### 本轮批准与实现验收 + +批准范围仅HttpsTransport的HTML Accept、QrEvidence的精确HTTPS wxmpurl.cn识别及相关测试/文档/Git发布。实际实现解析完整URL,拒绝子域、后缀相似主机、用户信息、显式端口、片段及嵌入其他URL的伪装;维持原User-Agent,不改变支付插件、签名、回调、数据库结构或每6小时调度。检测不访问二维码链接。 + +支付/EPay/回调隔离测试36项180断言通过,涵盖人工停用、监测归属及既有有效回调。发布前合入生产f825c30038723c0c7d5ea0aadc0ce9286f3edc7e,保留已发布付款汇报。共享主题/管理员套餐/注册及付款汇报回归与生产验收见后续本节发布记录;未实际付款。 diff --git a/tests/Feature/PaymentHealth/PaymentHealthTest.php b/tests/Feature/PaymentHealth/PaymentHealthTest.php index fe5d7a6f..6a0bb9b5 100644 --- a/tests/Feature/PaymentHealth/PaymentHealthTest.php +++ b/tests/Feature/PaymentHealth/PaymentHealthTest.php @@ -134,6 +134,36 @@ class PaymentHealthTest extends TestCase $q=new QrEvidence;$body='

32.00

'; $this->assertTrue($q->valid($body,'wxpay',3200));$this->assertFalse($q->valid(str_replace('32.00','16.00',$body),'wxpay',3200));$this->assertFalse($q->valid('32.00 微信二维码','wxpay',3200)); } + public function test_cashier_requests_explicitly_accept_html_with_the_original_agent():void + { + Http::fake(['https://pay.airspay.top/*'=>Http::response('cashier',200)]); + $transport=new class extends HttpsTransport {protected function publicAddress(string $host):string{return '93.184.216.34';}}; + $transport->request('POST','https://pay.airspay.top/submit.php',['money'=>'32.00']); + Http::assertSent(fn($r)=>$r->hasHeader('Accept','text/html')&&$r->hasHeader('User-Agent','XB-PaymentHealth/1.0')&&$r['money']==='32.00'); + Http::assertSentCount(1); + } + public function test_wechat_https_qr_still_requires_exact_host_amount_and_rendering():void + { + $q=new QrEvidence; + $body='

32.00

'; + $this->assertTrue($q->valid($body,'wxpay',3200)); + $this->assertFalse($q->valid($body,'wxpay',1600)); + $this->assertFalse($q->valid($body,'alipay',3200)); + $this->assertFalse($q->valid('32.00 https://wxmpurl.cn/fixture-only','wxpay',3200)); + foreach(['http://wxmpurl.cn/fixture','https://wxmpurl.cn.evil.invalid/fixture','https://sub.wxmpurl.cn/fixture', + 'https://wxmpurlXcn/fixture','https://wxmpurl.cn@evil.invalid/fixture','https://user@wxmpurl.cn/fixture', + 'https://wxmpurl.cn:8443/fixture','https://evil.invalid/https://wxmpurl.cn/fixture', + 'https://evil.invalid/?next=https://wxmpurl.cn/fixture','https://wxmpurl.cn/','https://wxmpurl.cn/fixture#fragment']as$url){ + $this->assertFalse($q->valid(str_replace('https://wxmpurl.cn/fixture-only',$url,$body),'wxpay',3200),$url); + } + } + public function test_wechat_https_cashier_is_healthy_without_following_the_qr_url():void + { + $body='

32.00

'; + $t=new QueueTransport;$t->responses=[[200,$body]]; + $out=(new TestEpayProbe($t,new QrEvidence))->probe(Payment::find(1),'fixture-trade'); + $this->assertSame('healthy',$out['status']);$this->assertSame('fresh_cashier_qr',$out['reason']);$this->assertCount(1,$t->calls); + } private function qrPng(int $pixels):string { $matrix=\BaconQrCode\Encoder\Encoder::encode('alipays://platformapi/startapp?appId=fixture-only',\BaconQrCode\Common\ErrorCorrectionLevel::M())->getMatrix();