From 20a0348743a4a9800316f885c8fd9eb0a858652d Mon Sep 17 00:00:00 2001
From: wwwwwwwww <526125649@qq.com>
Date: Fri, 12 Jun 2026 11:08:47 +0800
Subject: [PATCH] 1
---
.../src/pages/AdminPaymentConfig.tsx | 20 ++++++++---
video-gen-api/app/services/payment.py | 35 ++++++++++++++++---
2 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/video-gen-admin/src/pages/AdminPaymentConfig.tsx b/video-gen-admin/src/pages/AdminPaymentConfig.tsx
index 511ae365..d8353f8f 100644
--- a/video-gen-admin/src/pages/AdminPaymentConfig.tsx
+++ b/video-gen-admin/src/pages/AdminPaymentConfig.tsx
@@ -235,11 +235,23 @@ const AdminPaymentConfig: React.FC = () => {
-
-
+
+
-
-
+
+
diff --git a/video-gen-api/app/services/payment.py b/video-gen-api/app/services/payment.py
index b38f5600..28bbb017 100644
--- a/video-gen-api/app/services/payment.py
+++ b/video-gen-api/app/services/payment.py
@@ -211,6 +211,28 @@ _alipay_client = None
_alipay_client_app_id = None
+def _format_alipay_key(key: str) -> str:
+ """
+ 格式化支付宝密钥,移除PEM头部和尾部,并清理所有空白字符。
+ """
+ if not key:
+ return ""
+ # 移除首尾空白
+ key = key.strip()
+ # 移除 PEM 头部和尾部
+ key = key.replace("-----BEGIN RSA PRIVATE KEY-----", "")
+ key = key.replace("-----BEGIN PRIVATE KEY-----", "")
+ key = key.replace("-----END RSA PRIVATE KEY-----", "")
+ key = key.replace("-----END PRIVATE KEY-----", "")
+ key = key.replace("-----BEGIN PUBLIC KEY-----", "")
+ key = key.replace("-----END PUBLIC KEY-----", "")
+ key = key.replace("-----BEGIN ALIPAY PUBLIC KEY-----", "")
+ key = key.replace("-----END ALIPAY PUBLIC KEY-----", "")
+ # 移除所有空白字符(换行、空格、制表符等)
+ key = "".join(key.split())
+ return key
+
+
def _get_alipay_client(app_id: str, private_key: str, public_key: str, gateway: str = ""):
"""Get or create an Alipay client. Recreated if app_id changes."""
global _alipay_client, _alipay_client_app_id
@@ -228,18 +250,23 @@ def _get_alipay_client(app_id: str, private_key: str, public_key: str, gateway:
)
return None
+ # 格式化私钥和公钥
+ formatted_private_key = _format_alipay_key(private_key)
+ formatted_public_key = _format_alipay_key(public_key)
+
config = AlipayClientConfig()
config.server_url = gateway or "https://openapi.alipay.com/gateway.do"
config.app_id = app_id
- config.app_private_key = private_key
- config.alipay_public_key = public_key
+ config.app_private_key = formatted_private_key
+ config.alipay_public_key = formatted_public_key
config.sign_type = "RSA2"
config.charset = "utf-8"
try:
_alipay_client = DefaultAlipayClient(config, logger)
_alipay_client_app_id = app_id
- except Exception:
+ logger.info("Alipay client initialized successfully")
+ except Exception as e:
logger.exception("Failed to initialize Alipay client")
_alipay_client = None
_alipay_client_app_id = None
@@ -505,7 +532,7 @@ async def _close_wechat_order(db: AsyncSession, order: PaymentOrder, db_configs:
try:
code, result = client.close(out_trade_no=order.order_no)
- if code == 200:
+ if code == 204:
logger.info(f"WeChat order closed: order_no={order.order_no}")
return True
else: