update pay ui
This commit is contained in:
Binary file not shown.
@@ -15,12 +15,15 @@
|
|||||||
|
|
||||||
返回值:
|
返回值:
|
||||||
成功返回 0,失败返回 1
|
成功返回 0,失败返回 1
|
||||||
输出 JSON 格式的结果
|
输出 JSON 格式的结果(到 stdout)
|
||||||
|
调试信息输出到 stderr
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import io
|
||||||
|
from contextlib import redirect_stdout
|
||||||
|
|
||||||
# 添加当前目录到路径
|
# 添加当前目录到路径
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
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):
|
def create_order(order_no, total_fee, body, product_id=None):
|
||||||
"""创建微信支付订单"""
|
"""创建微信支付订单"""
|
||||||
|
# 捕获所有 stdout 输出(wechat_pay.py 的调试信息)
|
||||||
|
debug_output = io.StringIO()
|
||||||
|
|
||||||
try:
|
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()
|
wechat_pay = create_wechat_pay_instance()
|
||||||
result = wechat_pay.create_native_order(
|
result = wechat_pay.create_native_order(
|
||||||
order_no=order_no,
|
order_no=order_no,
|
||||||
total_fee=float(total_fee),
|
total_fee=float(total_fee),
|
||||||
body=body,
|
body=body,
|
||||||
product_id=product_id
|
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))
|
print(json.dumps(result, ensure_ascii=False))
|
||||||
return result.get('success', False)
|
return result.get('success', False)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# 调试信息输出到 stderr
|
||||||
|
debug_info = debug_output.getvalue()
|
||||||
|
if debug_info:
|
||||||
|
print(debug_info, file=sys.stderr)
|
||||||
|
|
||||||
print(json.dumps({
|
print(json.dumps({
|
||||||
'success': False,
|
'success': False,
|
||||||
'error': f'{type(e).__name__}: {str(e)}'
|
'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):
|
def query_order(order_no):
|
||||||
"""查询订单状态"""
|
"""查询订单状态"""
|
||||||
try:
|
debug_output = io.StringIO()
|
||||||
from wechat_pay import create_wechat_pay_instance
|
|
||||||
|
|
||||||
wechat_pay = create_wechat_pay_instance()
|
try:
|
||||||
result = wechat_pay.query_order(order_no=order_no)
|
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))
|
print(json.dumps(result, ensure_ascii=False))
|
||||||
return result.get('success', False)
|
return result.get('success', False)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
debug_info = debug_output.getvalue()
|
||||||
|
if debug_info:
|
||||||
|
print(debug_info, file=sys.stderr)
|
||||||
|
|
||||||
print(json.dumps({
|
print(json.dumps({
|
||||||
'success': False,
|
'success': False,
|
||||||
'error': f'{type(e).__name__}: {str(e)}'
|
'error': f'{type(e).__name__}: {str(e)}'
|
||||||
@@ -71,10 +101,19 @@ def query_order(order_no):
|
|||||||
|
|
||||||
def check_config():
|
def check_config():
|
||||||
"""检查微信支付配置"""
|
"""检查微信支付配置"""
|
||||||
try:
|
debug_output = io.StringIO()
|
||||||
from wechat_pay import check_wechat_pay_ready
|
|
||||||
|
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 = {
|
result = {
|
||||||
'success': is_ready,
|
'success': is_ready,
|
||||||
'message': msg
|
'message': msg
|
||||||
@@ -84,6 +123,10 @@ def check_config():
|
|||||||
return is_ready
|
return is_ready
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
debug_info = debug_output.getvalue()
|
||||||
|
if debug_info:
|
||||||
|
print(debug_info, file=sys.stderr)
|
||||||
|
|
||||||
print(json.dumps({
|
print(json.dumps({
|
||||||
'success': False,
|
'success': False,
|
||||||
'error': f'{type(e).__name__}: {str(e)}'
|
'error': f'{type(e).__name__}: {str(e)}'
|
||||||
|
|||||||
Reference in New Issue
Block a user