Merge branch 'main' of gitee.com:wg123/video-gen into main

This commit is contained in:
18610128193
2026-06-10 14:44:35 +08:00
5 changed files with 61 additions and 34 deletions
+28
View File
@@ -412,6 +412,34 @@ async def list_payment_configs(
]
@router.put("/payment-configs/batch")
async def batch_update_payment_configs(
req: dict[str, str],
admin: User = Depends(get_admin_user),
db: AsyncSession = Depends(get_db),
):
"""Batch upsert payment configs. Creates missing keys, updates existing ones."""
from app.utils.id_gen import generate_id
for key, value in req.items():
if not key.startswith("payment_"):
continue
result = await db.execute(
select(SystemConfig).where(SystemConfig.key == key).limit(1)
)
config = result.scalar_one_or_none()
if config:
config.value = value
else:
db.add(SystemConfig(
id=generate_id(),
key=key,
value=value,
))
await db.flush()
return {"ok": True}
@router.put("/payment-configs/{config_id}")
async def update_payment_config(
config_id: str,
+4 -3
View File
@@ -41,7 +41,7 @@ _alipay_client = None
_alipay_client_app_id = None
def _get_alipay_client(app_id: str, private_key: str, public_key: str):
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
@@ -59,7 +59,7 @@ def _get_alipay_client(app_id: str, private_key: str, public_key: str):
return None
config = AlipayClientConfig()
config.server_url = "https://openapi.alipay.com/gateway.do"
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
@@ -187,12 +187,13 @@ def _create_alipay_order(order: PaymentOrder, db_configs: dict[str, str]) -> str
private_key = db_configs.get("payment_alipay_private_key", "")
public_key = db_configs.get("payment_alipay_public_key", "")
notify_url = db_configs.get("payment_alipay_notify_url", "")
gateway = db_configs.get("payment_alipay_gateway", "")
if not app_id or not private_key:
logger.warning("Alipay config missing in database (app_id / private_key)")
return None
client = _get_alipay_client(app_id, private_key, public_key)
client = _get_alipay_client(app_id, private_key, public_key, gateway)
if client is None:
return None