fix(payment): recognize bounded large cashier QR and clarify channel alerts
Docker Build and Publish / build (push) Waiting to run

This commit is contained in:
hellcat committed 2026-10-31 19:43:17 +08:00
1 parent 7e297b47a3
commit eb85f2a1a9
4 files changed
+87 -2

No files matched your search

+16 -1
View File
@@ -59,6 +59,7 @@ class Monitor
if($changed){$current['managed_disabled']=!$target;$current['expected_updated_at']=(string)$changed->getRawOriginal('updated_at');$current['phase']='applied';$current['action']=$target?'enabled':'disabled';}
else{$current['status']='manual_override';$current['managed_disabled']=false;$current['phase']='skipped';}
}
$current['enabled']=(bool)Payment::find($p->id)?->enable;
if(($old['status']??null)!==$current['status']||$target!==null){
// Healthy first checks are quiet. Emit only useful failures, transitions, and recoveries.
if($current['status']!=='healthy'||!empty($old['status']))$this->event($state,$p,$current,$instance,$now);
@@ -88,7 +89,21 @@ class Monitor
$recovered=$c['status']==='healthy';$label=mb_substr((string)(config('payment_health.site_label')?:admin_setting('app_name','XB')),0,80);
// Channel labels are administrative text. No URLs, signatures, order IDs or user data are sent.
$name=mb_substr(preg_replace('/[\r\n]/u',' ',(string)$p->name),0,80);
$text='【'.$label.' - 支付通道'.($recovered?'恢复':'异常').'】'."\n通道:".$name.'('.$p->id.')'."\n时间:".$now->format('Y-m-d H:i:s T')."\n检测:".$c['reason']."\n处理:".($c['action']??'保持现状,需检查')."\n范围:仅收银可用性,未实际付款";
$reason=[
'fresh_cashier_qr'=>'已确认有效收银二维码',
'mapi_payment_qr'=>'网关返回有效支付二维码',
'network_timeout'=>'收银请求超时',
'cashier_not_found'=>'收银入口返回404或410',
'cashier_business_error'=>'收银台返回业务错误',
'cashier_transient'=>'收银服务暂时异常',
'unexpected_form'=>'收银表单暂未识别',
'no_verified_qr'=>'尚未确认有效收银二维码',
'mapi_rejected'=>'支付网关未受理请求',
'mapi_response_invalid'=>'支付网关响应不完整',
][$c['reason']]??'检测未通过';
$enabled=(bool)($c['enabled']??$p->fresh()?->enable);
$action=match($c['action']??null){'enabled'=>'已自动开启','disabled'=>'已自动关闭',default=>$enabled?'保持开启':'保持关闭'};
$text='【'.$label.' - 支付通道'.($recovered?'恢复':'异常').'】'."\n通道:".$name.'('.$p->id.')'."\n时间:".$now->format('Y-m-d H:i:s T')."\n检测:".$reason.'('.$c['reason'].')'."\n当前状态:".($enabled?'已开启':'已关闭')."\n处理:".$action."\n范围:仅收银可用性,未实际付款";
$state['events'][$key]=['key'=>$key,'bot'=>$recovered?'notification':'error','text'=>$text];
}
}
+10 -1
View File
@@ -22,9 +22,18 @@ class QrEvidence
public function hasFinders(string $png): bool
{
if(!function_exists('imagecreatefromstring'))return false;
if(strlen($png)>524288)return false;
$size=@getimagesizefromstring($png);if(!$size)return false;
[$w,$h]=$size;
if(($size[2]??null)!==IMAGETYPE_PNG||$w<21||$h<21||$w>2048||$h>2048||abs($w-$h)>2)return false;
$im=@imagecreatefromstring($png);if(!$im)return false;
try{
$w=imagesx($im);$h=imagesy($im);if($w<21||$w>600||abs($w-$h)>2)return false;
if($w>600){
$factor=(int)ceil($w/600);$nw=(int)floor($w/$factor);$nh=(int)floor($h/$factor);
$normalized=imagecreatetruecolor($nw,$nh);if(!$normalized)return false;
imagecopyresized($normalized,$im,0,0,0,0,$nw,$nh,$w,$h);
imagedestroy($im);$im=$normalized;$w=$nw;$h=$nh;
}
$black=static function(int $x,int $y)use($im):bool{$c=imagecolorat($im,$x,$y);$rgb=imagecolorsforindex($im,$c);return ($rgb['red']+$rgb['green']+$rgb['blue'])<384;};
$points=[];
for($y=0;$y<$h;$y+=2){$runs=[];$last=false;$len=0;
+28
View File
@@ -67,3 +67,31 @@ TeleHub已分别建立最小权限调用方:DPL xb-dpl-payment-health-prod(I
微信两站最新18:00均cashier_not_found,HTTP404、api.shangri-la.vc;首轮2026-10-30 16:56已自动关闭并分别有sent告警。之后故障状态相同,按状态变化去重不每6小时重复报警,不是停止检测或恢复。
支付宝2026-10-30 18:00及10-31 00:00连续网络超时后自动关闭;当前18:00状态indeterminate/unexpected_form,HTTP200最后主机auth.alipay.com。实现中unexpected_form表示解析表单字段超过30个,不能证明支付商或支付宝平台确定故障,也不能算有效收银/二维码通过。HN期间soft_failure与indeterminate变化产生额外告警,DPL持续同一状态静默。告警“保持现状,需检查”实际指仍保持关闭,文案未明确当前开关,容易误解;本次只识别问题,不修改核心告警/检测逻辑。最新HN18:00事件本地仍显示queued,既有微信故障事件sent。本核对是服务器侧状态,不是真实付款或页面验收。
## 2026-10-31人工复查与FUC只读对比
用户明确批准额外4笔32元待支付复查、不付款;在原每日8笔预算已满的情况下独立记录人工授权,不修改自动账本。任务目录sitejp02 /root/codex-backups/xb-payment-health/manual-20261031-user-recheck-1/。用户随后说明同平台只查HN;停止检查时任务已完成,DPL两笔在该补充前均已发出,本次没有再请求DPL。以后这项共用商户的人工复查只检查HN,不能自动扩大成其它站点新订单。两站业务用户/订单/通道及自动状态哈希保持,无应用订单新增、无实付。
HN复查2026-10-31 19:01:44 +08:00:
- 支付宝:pay.airspay.top受理,q.jianzhewl.cn返回HTTP200、32.00元、alipays支付URI和内嵌PNG二维码,无过期/业务错误。原PNG 650×650,QrEvidence的600上限直接拒绝;仅在内存缩为325×325后,三个定位图形识别和同一HTML完整valid(alipay,3200)均通过,确认尺寸限制导致健康漏判。离线验证没有新HTTP请求,收据hn/qr-size-validation.json。不能把随后被探测器继续跟随到Alipay授权页的结果当成原收银页不可用。仅证明本次可生成有效金额收银二维码,未付款或验证到账。
- 微信:同笔新测试最终POST api.shangri-la.vc返回404,扫码收银不通过。
- 本次诊断采集器在空跳转响应DOM分析时还发生中断,原始trace显示probe_error;最终支付宝结论来自已保存的收银页及离线尺寸控制验证,不把采集器错误当作支付业务失败。没有将原始二维码、完整URL或签名输出到普通文档。
- 未改通道开关;当前支付宝、微信仍保持监测关闭。QrEvidence尺寸支持与告警当前状态文案尚未修改。
用户再要求参考FUC正常路径。只读对比FUC生产sitejp01 /www/wwwroot/fuuuu.cloud HEAD 4eff00023420175662792769d1d2ee1c16d9bb68,与HN实际运行配置,通过临时随机HMAC在内存比较后只输出相同与否:网关https://pay.airspay.top、商户号、密钥及MD5签名均一致。FUC普通用户POST mapi.php并传clientip/sitename,HN现有EPay插件走submit.php浏览器签名跳转;两种入口不同本身不能证明实现错误,尚未按FUC相同入口重新提交微信测试,不能直接认定整个支付平台微信不可用。FUC线上源码保留is_loc或管理员购买直接postPayment分支,生产is_loc=false;若用管理员下单,则成功页面不能作为支付网关实际成功证据。本次未调用FUC购买入口或创建FUC订单,未改FUC配置。
后续修复建议须按XB核心边界确认范围:二维码尺寸应先在受限像素/字节范围内归一化再识别,保留金额/URI/定位图形验证;告警明确当前enable和检测结果,避免“保持现状”掩盖仍关闭。不要仅放宽form字段数就跟随登录页,也不复制FUC管理员直接成功分支。微信与FUC入口对照仍须单独有边界地验收,不实际付款。
## 2026-10-31已批准的二维码与告警修复
批准依据:用户对“修正二维码尺寸漏判、明确告警当前状态、HN一笔32元微信mapi对照;验证成功才启用可选mapi,Git发布且不改FUC/不再重复DPL订单”的具体方案回复“弄”。不扩大到新通道、更多检测单或真实付款。
二维码在解码前限制PNG、512KiB、21~2048像素及近似正方形;超过600像素时按整数因子最近邻归一化,随后沿用三定位图形校验。金额与支付URI/结构化二维码校验不变,不因HTTP200直接判成功。告警增加中文检测原因和原始代码、当前已开启/已关闭、已自动开关/保持开关;不重发已发送旧告警。
HN额外微信mapi对照任务:sitejp02 /root/codex-backups/xb-payment-health/mapi-20261031-hn-wx-1/。仅POST网关一次;HTTP200、code=1、返回payurl,只表示受理。原单沿收银表单POST api.shangri-la.vc仍404;同单补齐浏览器User-Agent、Cookie和Referer/Origin后仍404。没有新应用订单、实付或重置自动预算;未实现或启用mapi切换,未重开微信。单纯把submit改为mapi无法解决本次HN32元路径,不把该结果扩大为FUC或整个平台故障。
FUC只读聚合验证:生产当前启用epay,最近30日非管理员EPay WeChat状态1记录70条,最近一条2026-10-29 14:37:59 UTC。此证据支持确有普通用户微信成功记录,不以管理员直成功分支否定用户反馈;仍不等于本次实时收银/结算验收。FUC源码、配置和订单均未修改。尚未确定HN本次路由404与FUC历史成功之间的原因,不伪造clientip或替换FUC回调域名来绕过。
本次修改在统一XB后端上,HN/DPL共用修复,实例通道、账本和运行状态独立。生产既有theme/Stellar/dashboard.blade.php修改须保留;不从已退出的HN工作树发布。发布/恢复和当次服务器验收按完成后记录补齐,未实际付款或做线上页面验收。
验证:支付健康/回调33项160断言通过;统一主题、实例隔离、管理员套餐和注册日报26项98断言通过。全部为隔离测试,包含650像素收银识别后不继续追踪授权登录页、错误金额/URI/空白或过大图片拒绝、告警关闭/保持关闭/恢复开启、人工停用和旧订单验签回调保护。
@@ -134,6 +134,39 @@ class PaymentHealthTest extends TestCase
$q=new QrEvidence;$body='<p>32.00</p><div id="qr"></div><script>new QRCode(document.getElementById("qr"),"weixin://wxpay/bizpayurl?pr=fixture-only")</script>';
$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));
}
private function qrPng(int $pixels):string
{
$matrix=\BaconQrCode\Encoder\Encoder::encode('alipays://platformapi/startapp?appId=fixture-only',\BaconQrCode\Common\ErrorCorrectionLevel::M())->getMatrix();
$n=$matrix->getWidth();$src=imagecreatetruecolor($n+8,$n+8);$white=imagecolorallocate($src,255,255,255);$black=imagecolorallocate($src,0,0,0);imagefill($src,0,0,$white);
for($y=0;$y<$n;$y++)for($x=0;$x<$n;$x++)if($matrix->get($x,$y)===1)imagesetpixel($src,$x+4,$y+4,$black);
$out=imagecreatetruecolor($pixels,$pixels);imagecopyresized($out,$src,0,0,0,0,$pixels,$pixels,$n+8,$n+8);ob_start();imagepng($out);$png=ob_get_clean();imagedestroy($src);imagedestroy($out);return $png;
}
public function test_large_real_qr_is_normalized_without_weakening_amount_or_uri_checks():void
{
$q=new QrEvidence;$png=$this->qrPng(650);
$html='32.00 <a href="alipays://platformapi/startapp?appId=fixture-only">支付</a><img src="data:image/png;base64,'.base64_encode($png).'">';
$this->assertTrue($q->hasFinders($png));$this->assertTrue($q->valid($html,'alipay',3200));
$this->assertFalse($q->valid($html,'alipay',1600));$this->assertFalse($q->valid(str_replace('alipays://','https://not-a-payment.invalid/',$html),'alipay',3200));
$this->assertTrue($q->hasFinders($this->qrPng(325)));
$oversized=substr($png,0,16).pack('NN',4096,4096).substr($png,24);
$this->assertFalse($q->hasFinders($oversized));$this->assertFalse($q->hasFinders(str_repeat('x',524289)));
$blank=imagecreatetruecolor(650,650);ob_start();imagepng($blank);$bytes=ob_get_clean();imagedestroy($blank);$this->assertFalse($q->hasFinders($bytes));
}
public function test_large_cashier_qr_stops_before_alipay_login_redirect():void
{
$p=Payment::find(1);$p->config=array_replace($p->config,['type'=>'alipay']);$p->save();
$html='<span>32.00</span><a href="alipays://platformapi/startapp?appId=fixture-only">Pay</a><img src="data:image/png;base64,'.base64_encode($this->qrPng(650)).'"><script>location.href="https://auth.alipay.com/login"</script>';
$t=new QueueTransport;$t->responses=[[200,$html]];$probe=new TestEpayProbe($t,new QrEvidence);
$out=$probe->probe($p,'fixture-trade');$this->assertSame('healthy',$out['status']);$this->assertSame('fresh_cashier_qr',$out['reason']);$this->assertCount(1,$t->calls);
}
public function test_alerts_distinguish_current_state_from_action():void
{
$this->probe->outcomes=[['status'=>'hard_failure','reason'=>'cashier_not_found']];$this->runMonitor();
$this->assertStringContainsString('当前状态:已关闭',$this->reporter->sent[0]['text']);$this->assertStringContainsString('已自动关闭',$this->reporter->sent[0]['text']);
$this->nextSlot();$this->probe->outcomes=[['status'=>'indeterminate','reason'=>'unexpected_form']];$this->runMonitor();
$this->assertStringContainsString('当前状态:已关闭',$this->reporter->sent[1]['text']);$this->assertStringContainsString('处理:保持关闭',$this->reporter->sent[1]['text']);
$this->nextSlot();$this->runMonitor();$this->assertStringContainsString('当前状态:已开启',$this->reporter->sent[2]['text']);$this->assertStringContainsString('已自动开启',$this->reporter->sent[2]['text']);
}
private function callbackFixture():array
{
Schema::create('v2_order',function(Blueprint $t){$t->id();$t->string('trade_no');$t->integer('payment_id');$t->integer('total_amount');$t->integer('handling_amount')->nullable();$t->integer('status');$t->string('callback_no')->nullable();$t->integer('paid_at')->nullable();$t->integer('created_at')->nullable();$t->integer('updated_at')->nullable();});