This commit is contained in:
2026-02-12 23:35:51 +08:00
parent fea8f2a20a
commit 55e335ea06
2 changed files with 5 additions and 4 deletions

View File

@@ -749,10 +749,8 @@ class OrderViewSet(viewsets.ModelViewSet):
message_build = f"{wechat_config.app_id}\n{timestamp}\n{nonce_str}\n{package}\n" message_build = f"{wechat_config.app_id}\n{timestamp}\n{nonce_str}\n{package}\n"
# 使用商户私钥签名 # 使用商户私钥签名
# 这里的私钥加载逻辑需复用 get_wechat_pay_client 中的逻辑,或者直接从 wxpay 实例获取 (如果它暴露了) # 注意WeChatPayV3 对象的私钥属性名可能随版本变化,或者被封装
# 简单起见,我们重新加载私钥 # 这里我们不直接访问私钥,而是利用 SDK 提供的 sign 方法
private_key_str = wxpay._private_key # 假设 SDK 内部存储了 private_key (通常是 obj)
# 由于 SDK 内部处理复杂,我们尝试用 cryptography 库签名
# 实际上 wechatpayv3 库提供了 sign 方法 # 实际上 wechatpayv3 库提供了 sign 方法
signature = wxpay.sign(message_build) signature = wxpay.sign(message_build)
@@ -769,6 +767,9 @@ class OrderViewSet(viewsets.ModelViewSet):
return Response({'error': '微信下单失败', 'detail': result}, status=400) return Response({'error': '微信下单失败', 'detail': result}, status=400)
except Exception as e: except Exception as e:
import traceback
traceback.print_exc()
print(f"Prepay failed with error: {str(e)}")
return Response({'error': str(e)}, status=500) return Response({'error': str(e)}, status=500)
@action(detail=False, methods=['get']) @action(detail=False, methods=['get'])