From ce2a2ad578ebcda187930c2bed0edece181df368 Mon Sep 17 00:00:00 2001 From: hellcat Date: Wed, 4 Nov 2026 19:03:24 +0800 Subject: [PATCH] test(fuc-xb): cashier acceptance\n --- scripts/fuc-xb-acceptance/cashier.py | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scripts/fuc-xb-acceptance/cashier.py diff --git a/scripts/fuc-xb-acceptance/cashier.py b/scripts/fuc-xb-acceptance/cashier.py new file mode 100644 index 00000000..d8c76b59 --- /dev/null +++ b/scripts/fuc-xb-acceptance/cashier.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +"""Follow only the observed gateway's unpaid auto-POST. Never authorize payment.""" +from html.parser import HTMLParser +from pathlib import Path +from decimal import Decimal +import hashlib,json,ssl,urllib.parse,urllib.request,urllib.error +ROOT=Path('/var/www/wwwroot/fuc-xb-test/private/live-acceptance-20261104') +class Form(HTMLParser): + def __init__(self):super().__init__();self.forms=[];self.title=False;self.titles=[] + def handle_starttag(self,t,a): + a=dict(a) + if t=='form':self.forms.append({'action':a.get('action'),'method':a.get('method','get').lower(),'fields':{}}) + if t=='input' and self.forms and a.get('name'):self.forms[-1]['fields'][a['name']]=a.get('value','') + if t=='title':self.title=True + def handle_endtag(self,t): + if t=='title':self.title=False + def handle_data(self,s): + if self.title:self.titles.append(s.strip()) +class NoRedirect(urllib.request.HTTPRedirectHandler): + def redirect_request(self,*a,**kw):return None +opener=urllib.request.build_opener(urllib.request.HTTPSHandler(context=ssl.create_default_context()),NoRedirect()) +out=[] +for kind in ['alipay','wxpay']: + p=Form();p.feed((ROOT/('cashier-'+kind+'.html')).read_text());assert len(p.forms)==1 + f=p.forms[0];v=f['fields'];assert f['action']=='https://api.shangri-la.vc/submit.php' and f['method']=='post' + assert set(v).issubset({'pid','type','notify_url','return_url','out_trade_no','name','money','sign','sign_type'}) + assert v['type']==kind and Decimal(v['money'])==Decimal('1') and v['sign_type']=='MD5' + req=urllib.request.Request(f['action'],data=urllib.parse.urlencode(v).encode(),headers={'Content-Type':'application/x-www-form-urlencoded','User-Agent':'FUC-XB-Isolated-Acceptance/1.0'},method='POST') + try:res=opener.open(req,timeout=25) + except urllib.error.HTTPError as e:res=e + with res: + status=res.status;b=res.read(2097152);location=res.headers.get('Location','') + (ROOT/('cashier-final-'+kind+'.html')).write_bytes(b) + parsed=Form();parsed.feed(b.decode('utf-8',errors='replace')) + failures=[x for x in ['签名验证失败','商户不存在','商户已被封禁','商户未开启','支付金额不能','参数错误'] if x in b.decode('utf-8',errors='replace')] + out.append({'type':kind,'observed_processor_host':'api.shangri-la.vc','http_status':status,'tls_verified':True,'title':' '.join(parsed.titles)[:120],'redirect_host':urllib.parse.urlsplit(location).hostname,'error_indicators':failures,'response_bytes':len(b),'body_sha256':hashlib.sha256(b).hexdigest(),'payment_authorization_attempted':False}) +result={'processor_unpaid_auto_post_only':True,'real_money_paid':0,'cases':out,'actual_paid_callback_not_tested':True} +(ROOT/'cashier-final-result.json').write_text(json.dumps(result,ensure_ascii=False,indent=2));print(json.dumps(result,ensure_ascii=False))