From 9117f373d49daee9ed453d37a1925a454cc90a23 Mon Sep 17 00:00:00 2001 From: zzlgreat Date: Fri, 12 Dec 2025 01:22:31 +0800 Subject: [PATCH] update pay ui --- __pycache__/wechat_pay_worker.cpython-310.pyc | Bin 2909 -> 3543 bytes wechat_pay_worker.py | 75 ++++++++++++++---- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/__pycache__/wechat_pay_worker.cpython-310.pyc b/__pycache__/wechat_pay_worker.cpython-310.pyc index e5e7f403011918241de1dc2df7f4425fd76591df..72949414f294dbeef755bbbb23914ea91c71e3f8 100644 GIT binary patch literal 3543 zcma)8TW=f36`q;BaJizWnB5G2>1!A{>t;CX>05uxeDbNcNEAbELOZ&P{1#0T@=?fbqnes8ah;Q8zQ$-?3Rg#IP}bUzmSc@Ey-9!7|wETWi_63$}vC0U}r zT2@nEJ*&f4D;Z@oYhuK3F|lS*%ry8Wm9<&VI))#?h>lU68s~8~MNOJGkFvegqDlCs zSs%6M3I8wahX?}=Onc@LpJs!MtPRl=?WO5evW^>Aj<9xs_N^>wL!=-F{O zA2!Y}Q&=Ockj$WXcG81+4a208a$KX!gRb7I=rT-$*Cf-T>=_15OQtFX<@X;&AhH!&d{TfF$)Zh-6_5jAiJoFAOh_?UA(Gr-VogedxlT@^8Hgy-wVz{DPhzz6 zOjn#&_KQPJ(HABgxY&OM(WDrVJ^)>#_A2R&a1!Q3^?LHvBsGDm%3H*XDAQ9t2zwF3 za}V4VR5@%Bx{jmq7?N%mTnkgr{K8$beJzd1f#o1wXQ81TT1VKRUsQtg}1w;PQC0 zL#_FFIZ;?(u9{C|%$EF|h^#p#7ILL3i;M~c5s?-1JSw$3}SQoVli!9gma%JYa&{Ob?%?%imo6;ntk(nb(QFgjI=K@?SRiP%u2W7d* zSx_yB$d2m^-mD*Cb{+AjW>gwUMLs6YxHL~lGa=1aqHfwlSX1IHcv_K z8(@A2Z}4p}7TJYP8UtVw3NSgqU{mQLwkUN)(ilO9_suk$gM6CMT_cEG?n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;j(;? zfo?S@@D^cOh1n)d8=4aPFmJ)*+h8JG8gYVbf`%CF!c!~j&^QO(W1TfL5TJo3(GfC^0TIwPRb~j_K?1mP z*WrPyiq;DIYBXVV$aaVmmv`^VlsBzDnd|KBy%?dG!Cv`68t zO7nhy_wL@!A`PW9$@{T4U%<_?*J7y2 zqZ`|L$Q$%>qn=&eRhON_J;{#Ha2%R*W!fwFQcfYs`JtLm2ggGlvN_{HXwVE7*)cTI z$9(w(4zw>b1nE*HC8->4L#R@Bp)$lEufnN~L|hO84OMm`6Qqo){|)o2NcDB16nT{k zWrk*V7XB>^u|4AK{g1(@#7vmj#4jtBVs@ATmx7J9Z!8 diff --git a/wechat_pay_worker.py b/wechat_pay_worker.py index a16574a7..239acccb 100644 --- a/wechat_pay_worker.py +++ b/wechat_pay_worker.py @@ -15,12 +15,15 @@ 返回值: 成功返回 0,失败返回 1 - 输出 JSON 格式的结果 + 输出 JSON 格式的结果(到 stdout) + 调试信息输出到 stderr """ import sys import json import os +import io +from contextlib import redirect_stdout # 添加当前目录到路径 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) @@ -28,21 +31,36 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) def create_order(order_no, total_fee, body, product_id=None): """创建微信支付订单""" + # 捕获所有 stdout 输出(wechat_pay.py 的调试信息) + debug_output = io.StringIO() + try: - from wechat_pay import create_wechat_pay_instance + with redirect_stdout(debug_output): + from wechat_pay import create_wechat_pay_instance - wechat_pay = create_wechat_pay_instance() - result = wechat_pay.create_native_order( - order_no=order_no, - total_fee=float(total_fee), - body=body, - product_id=product_id - ) + wechat_pay = create_wechat_pay_instance() + result = wechat_pay.create_native_order( + order_no=order_no, + total_fee=float(total_fee), + body=body, + product_id=product_id + ) + # 调试信息输出到 stderr + debug_info = debug_output.getvalue() + if debug_info: + print(debug_info, file=sys.stderr) + + # JSON 结果输出到 stdout print(json.dumps(result, ensure_ascii=False)) return result.get('success', False) except Exception as e: + # 调试信息输出到 stderr + debug_info = debug_output.getvalue() + if debug_info: + print(debug_info, file=sys.stderr) + print(json.dumps({ 'success': False, 'error': f'{type(e).__name__}: {str(e)}' @@ -52,16 +70,28 @@ def create_order(order_no, total_fee, body, product_id=None): def query_order(order_no): """查询订单状态""" - try: - from wechat_pay import create_wechat_pay_instance + debug_output = io.StringIO() - wechat_pay = create_wechat_pay_instance() - result = wechat_pay.query_order(order_no=order_no) + try: + with redirect_stdout(debug_output): + from wechat_pay import create_wechat_pay_instance + + wechat_pay = create_wechat_pay_instance() + result = wechat_pay.query_order(order_no=order_no) + + # 调试信息输出到 stderr + debug_info = debug_output.getvalue() + if debug_info: + print(debug_info, file=sys.stderr) print(json.dumps(result, ensure_ascii=False)) return result.get('success', False) except Exception as e: + debug_info = debug_output.getvalue() + if debug_info: + print(debug_info, file=sys.stderr) + print(json.dumps({ 'success': False, 'error': f'{type(e).__name__}: {str(e)}' @@ -71,10 +101,19 @@ def query_order(order_no): def check_config(): """检查微信支付配置""" - try: - from wechat_pay import check_wechat_pay_ready + debug_output = io.StringIO() + + try: + with redirect_stdout(debug_output): + from wechat_pay import check_wechat_pay_ready + + is_ready, msg = check_wechat_pay_ready() + + # 调试信息输出到 stderr + debug_info = debug_output.getvalue() + if debug_info: + print(debug_info, file=sys.stderr) - is_ready, msg = check_wechat_pay_ready() result = { 'success': is_ready, 'message': msg @@ -84,6 +123,10 @@ def check_config(): return is_ready except Exception as e: + debug_info = debug_output.getvalue() + if debug_info: + print(debug_info, file=sys.stderr) + print(json.dumps({ 'success': False, 'error': f'{type(e).__name__}: {str(e)}'