n
This commit is contained in:
@@ -41,7 +41,7 @@ def patched_request(self, *args, **kwargs):
|
||||
return original_request(self, *args, **kwargs)
|
||||
Core.request = patched_request
|
||||
|
||||
def get_wechat_pay_client():
|
||||
def get_wechat_pay_client(pay_type=WeChatPayType.NATIVE):
|
||||
"""
|
||||
获取微信支付 V3 客户端实例的辅助函数
|
||||
"""
|
||||
@@ -108,7 +108,7 @@ def get_wechat_pay_client():
|
||||
|
||||
try:
|
||||
wxpay = WeChatPay(
|
||||
wechatpay_type=WeChatPayType.NATIVE,
|
||||
wechatpay_type=pay_type,
|
||||
mchid=mch_id,
|
||||
private_key=private_key,
|
||||
cert_serial_no=serial_no,
|
||||
@@ -699,7 +699,7 @@ class OrderViewSet(viewsets.ModelViewSet):
|
||||
return Response({'error': '支付系统维护中'}, status=status.HTTP_503_SERVICE_UNAVAILABLE)
|
||||
|
||||
# 初始化支付客户端
|
||||
wxpay, error_msg = get_wechat_pay_client()
|
||||
wxpay, error_msg = get_wechat_pay_client(pay_type=WeChatPayType.JSAPI)
|
||||
if not wxpay:
|
||||
return Response({'error': error_msg}, status=500)
|
||||
|
||||
@@ -717,6 +717,12 @@ class OrderViewSet(viewsets.ModelViewSet):
|
||||
else:
|
||||
description = f"支付订单 {order.id}"
|
||||
|
||||
print(f"准备发起微信支付(小程序):")
|
||||
print(f" OutTradeNo: {out_trade_no}")
|
||||
print(f" Amount: {amount_in_cents} 分")
|
||||
print(f" OpenID: {user.openid}")
|
||||
print(f" NotifyURL: {wechat_config.notify_url}")
|
||||
|
||||
# 统一下单 (JSAPI)
|
||||
code, message = wxpay.pay(
|
||||
description=description,
|
||||
@@ -726,6 +732,8 @@ class OrderViewSet(viewsets.ModelViewSet):
|
||||
notify_url=wechat_config.notify_url
|
||||
)
|
||||
|
||||
print(f"微信支付响应: Code={code}, Message={message}")
|
||||
|
||||
result = json.loads(message)
|
||||
if code in range(200, 300):
|
||||
prepay_id = result.get('prepay_id')
|
||||
|
||||
Reference in New Issue
Block a user