From 6d4dace412ab0e28bb30344908285e0cb1e9183d Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 17 Jul 2026 13:33:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(wechat):=20Native=20payment=20=E2=86=92=20?= =?UTF-8?q?generate=20QR=20via=20env.data2qrpath=20=E2=86=92=20show=20Imag?= =?UTF-8?q?e=20for=20scan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unipay/init.py | 3 +++ wwwroot/recharge.dspy | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/unipay/init.py b/unipay/init.py index ca23a3a..6bb57f7 100644 --- a/unipay/init.py +++ b/unipay/init.py @@ -131,6 +131,9 @@ async def create_payment(request, params_kw=None): data.client_ip = client_ip res = await PROVIDERS[provider].create_payment(data) debug(f'{provider=} instance return {res}') + if provider == 'wechat': + qrpath = await env.data2qrpath(res) + res = env.entire_url('/idfile') + '?path=' + env.quote(qrpath) return res raise Exception('write payment_log error') except Exception as e: diff --git a/wwwroot/recharge.dspy b/wwwroot/recharge.dspy index c552677..c41416f 100644 --- a/wwwroot/recharge.dspy +++ b/wwwroot/recharge.dspy @@ -2,6 +2,31 @@ params_kw.amount = float(params_kw.amount) debug(f'recharge.dspy: {params_kw=}') try: url = await create_payment(request, params_kw) + if params_kw.provider == 'wechat': + return { + "widgettype": "VBox", + "options": { + "css": "card", + "padding": "20px", + "width": "320" + }, + "subwidgets": [ + { + "widgettype": "Image", + "options": { + "url": url, + "width": "280" + } + }, + { + "widgettype": "Text", + "options": { + "text": "请使用微信扫描二维码完成支付", + "halign": "center" + } + } + ] + } return { "widgettype":"NewWindow", "options":{