update pay ui
This commit is contained in:
Binary file not shown.
@@ -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,7 +31,11 @@ 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:
|
||||
with redirect_stdout(debug_output):
|
||||
from wechat_pay import create_wechat_pay_instance
|
||||
|
||||
wechat_pay = create_wechat_pay_instance()
|
||||
@@ -39,10 +46,21 @@ def create_order(order_no, total_fee, body, product_id=None):
|
||||
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):
|
||||
"""查询订单状态"""
|
||||
debug_output = io.StringIO()
|
||||
|
||||
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():
|
||||
"""检查微信支付配置"""
|
||||
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)
|
||||
|
||||
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)}'
|
||||
|
||||
Reference in New Issue
Block a user