gunicorn
This commit is contained in:
@@ -33,9 +33,13 @@ def get_wechat_pay_client():
|
||||
"""
|
||||
获取微信支付 V3 客户端实例的辅助函数
|
||||
"""
|
||||
print(f"正在获取微信支付配置...")
|
||||
wechat_config = WeChatPayConfig.objects.filter(is_active=True).first()
|
||||
if not wechat_config:
|
||||
print("错误: 数据库中没有激活的 WeChatPayConfig")
|
||||
return None, "支付配置未找到"
|
||||
|
||||
print(f"找到配置: ID={wechat_config.id}, MCH_ID={wechat_config.mch_id}")
|
||||
|
||||
# 1. 严格清理所有配置项的空格和换行符
|
||||
mch_id = str(wechat_config.mch_id).strip()
|
||||
@@ -135,6 +139,10 @@ def pay(request):
|
||||
微信支付 V3 Native 下单接口
|
||||
参数: goodid, quantity, customer_name, phone_number, shipping_address, ref_code
|
||||
"""
|
||||
print(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] 进入 pay 接口")
|
||||
print(f"Request Headers: {request.headers}")
|
||||
print(f"Request Data: {request.data}")
|
||||
|
||||
# 1. 获取并验证请求参数
|
||||
good_id = request.data.get('goodid')
|
||||
quantity = int(request.data.get('quantity', 1))
|
||||
@@ -144,18 +152,25 @@ def pay(request):
|
||||
ref_code = request.data.get('ref_code')
|
||||
|
||||
if not all([good_id, customer_name, phone_number, shipping_address]):
|
||||
return Response({'error': '缺少必要参数: goodid, customer_name, phone_number, shipping_address'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
missing_params = []
|
||||
if not good_id: missing_params.append('goodid')
|
||||
if not customer_name: missing_params.append('customer_name')
|
||||
if not phone_number: missing_params.append('phone_number')
|
||||
if not shipping_address: missing_params.append('shipping_address')
|
||||
print(f"支付接口缺少参数: {missing_params}, 接收到的数据: {request.data}")
|
||||
return Response({'error': f'缺少必要参数: {", ".join(missing_params)}'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 2. 获取支付配置并初始化客户端
|
||||
wxpay, error_msg = get_wechat_pay_client()
|
||||
if not wxpay:
|
||||
return Response({'error': error_msg}, status=status.HTTP_400_BAD_REQUEST)
|
||||
print(f"支付配置错误: {error_msg}")
|
||||
return Response({'error': f'支付配置错误: {error_msg}'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 3. 查找商品和销售员,创建订单
|
||||
# ... (此处省略中间逻辑,保持不变) ...
|
||||
try:
|
||||
product = ESP32Config.objects.get(id=good_id)
|
||||
except ESP32Config.DoesNotExist:
|
||||
print(f"商品不存在: {good_id}")
|
||||
return Response({'error': f'找不到 ID 为 {good_id} 的商品'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
salesperson = None
|
||||
|
||||
Reference in New Issue
Block a user