fix(wechat): revert to H5 payment — h5_url is directly browser-openable, no tenpay conversion needed

This commit is contained in:
yumoqing 2026-07-16 17:49:29 +08:00
parent d4c9568673
commit 2cac8fe4be
2 changed files with 13 additions and 11 deletions

View File

@ -155,7 +155,7 @@ class WechatGateway(Gateway):
# -----------------------------------------------------
async def create_payment(self, payload: Dict[str, Any]) -> str:
"""
Native 下单扫码支付
H5 下单返回浏览器可打开的支付页面 URL
"""
body = {
"appid": self.appid,
@ -166,11 +166,15 @@ class WechatGateway(Gateway):
"amount": {
"total": int(payload["amount"] * 100),
"currency": payload.get("currency", "CNY")
},
"scene_info": {
"payer_client_ip": payload.get("client_ip", "127.0.0.1"),
"h5_info": {"type": "Wap"}
}
}
body_str = json.dumps(body, ensure_ascii=False)
url_path = "/v3/pay/transactions/native"
url_path = "/v3/pay/transactions/h5"
url = WECHAT_API_BASE + url_path
auth = self._sign("POST", url_path, body_str)
@ -184,10 +188,10 @@ class WechatGateway(Gateway):
err_code = ret.get("code", "UNKNOWN")
err_msg = ret.get("message", str(ret))
raise Exception(f"WeChat API error (HTTP {resp.status}): [{err_code}] {err_msg}")
code_url = ret.get("code_url")
if not code_url:
raise Exception(f"WeChat Native API response missing code_url: {json.dumps(ret, ensure_ascii=False)}")
return code_url
h5_url = ret.get("h5_url")
if not h5_url:
raise Exception(f"WeChat API response missing h5_url: {json.dumps(ret, ensure_ascii=False)}")
return h5_url
# -----------------------------------------------------
async def refund(self, payload: Dict[str, Any]) -> Dict[str, Any]:

View File

@ -1,20 +1,18 @@
params_kw.amount = float(params_kw.amount)
debug(f'recharge.dspy: {params_kw=}')
try:
code_url = await create_payment(request, params_kw)
url = await create_payment(request, params_kw)
if params_kw.provider == 'transfer':
return {
"widgettype":"urlwidget",
"mode":"replace",
"target":"app.sage_main_content",
"options":{"url": code_url}
"options":{"url": url}
}
# weixin://wxpay/bizpayurl?pr=xxx → https://wx.tenpay.com/f2f?pr=xxx
pay_url = code_url.replace('weixin://wxpay/bizpayurl', 'https://wx.tenpay.com/f2f')
return {
"widgettype":"NewWindow",
"options":{
"url": pay_url,
"url": url,
"height": "100%",
"width":"100%"
}