diff --git a/__pycache__/app.cpython-310.pyc b/__pycache__/app.cpython-310.pyc index a8142f82..71691407 100644 Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ diff --git a/__pycache__/wechat_pay_worker.cpython-310.pyc b/__pycache__/wechat_pay_worker.cpython-310.pyc new file mode 100644 index 00000000..e5e7f403 Binary files /dev/null and b/__pycache__/wechat_pay_worker.cpython-310.pyc differ diff --git a/app.py b/app.py index f2d3cd78..40254f51 100755 --- a/app.py +++ b/app.py @@ -2269,14 +2269,20 @@ def check_order_status(order_id): 'message': '订单已过期' }) - # 调用微信支付API查询真实状态 + # 调用微信支付API查询真实状态(使用 subprocess 绕过 eventlet DNS 问题) try: - from wechat_pay import create_wechat_pay_instance - wechat_pay = create_wechat_pay_instance() + import subprocess - query_result = wechat_pay.query_order(order_no=order.order_no) + script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'wechat_pay_worker.py') - if query_result['success']: + query_proc = subprocess.run( + [sys.executable, script_path, 'query', order.order_no], + capture_output=True, text=True, timeout=30 + ) + + query_result = json.loads(query_proc.stdout) if query_proc.stdout else {'success': False, 'error': '无返回'} + + if query_result.get('success'): trade_state = query_result.get('trade_state') transaction_id = query_result.get('transaction_id') @@ -2372,14 +2378,20 @@ def force_update_order_status(order_id): if not order: return jsonify({'success': False, 'error': '订单不存在'}), 404 - # 检查微信支付状态 + # 检查微信支付状态(使用 subprocess 绕过 eventlet DNS 问题) try: - from wechat_pay import create_wechat_pay_instance - wechat_pay = create_wechat_pay_instance() + import subprocess - query_result = wechat_pay.query_order(order_no=order.order_no) + script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'wechat_pay_worker.py') - if query_result['success'] and query_result.get('trade_state') == 'SUCCESS': + query_proc = subprocess.run( + [sys.executable, script_path, 'query', order.order_no], + capture_output=True, text=True, timeout=30 + ) + + query_result = json.loads(query_proc.stdout) if query_proc.stdout else {'success': False, 'error': '无返回'} + + if query_result.get('success') and query_result.get('trade_state') == 'SUCCESS': # 强制更新为已支付 old_status = order.status order.mark_as_paid(query_result.get('transaction_id'))