refactor: 优化后端支付与微信支付

- 优化payment/config.py、wechat_pay.py
- 优化routers/payment.py、plans.py、quota.py、websocket.py
- 更新main.py、.env.production

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
iammm0
2026-02-11 16:06:15 +08:00
parent 240a184da8
commit 44b405d647
8 changed files with 274 additions and 38 deletions

View File

@@ -109,7 +109,7 @@ async def startup_event():
# 检查并预加载 ASR 模型(在后台线程执行,避免阻塞启动)
try:
from services.asr_service import asr_service
from services import asr_service
asr_ready = await asyncio.to_thread(asr_service.ensure_ready)
if asr_ready:
logger.info("ASR 模型已就绪(本地 Whisper")
@@ -118,6 +118,18 @@ async def startup_event():
except Exception as e:
logger.warning(f"ASR 初始化检查失败: {e}")
# 预初始化微信支付客户端(在后台线程执行,避免首次下单时 _ensure_client 占满 25s 导致超时)
try:
def _init_wechat_pay_client():
from routers.payment import get_payment_service
svc = get_payment_service()
if svc.is_method_available("wechat"):
_ = svc.wechat_client # 触发 _ensure_client()
await asyncio.to_thread(_init_wechat_pay_client)
logger.info("微信支付客户端已预初始化")
except Exception as e:
logger.warning(f"微信支付预初始化失败(首次下单时再初始化): {e}")
@app.on_event("shutdown")
async def shutdown_event():