fix(ai): DeepSeek 余额按官方 balance_infos 解析

/user/balance 返回的是 {is_available, balance_infos[]},没有顶层 data,
旧实现永远解析出 None,连接测试会显示「余额 None CNY」。同时补全
TotHost 预设平台,新环境初始化后即可直接配 whmcs-panel。
This commit is contained in:
gouki
2026-10-26 08:43:54 +00:00
parent abd2fa8206
commit 9aa1ca431e
4 changed files with 48 additions and 6 deletions
+11 -3
View File
@@ -34,12 +34,20 @@ class DeepSeekAdapter(_AIBase):
BASE = "https://api.deepseek.com"
def _balance(self) -> AccountInfo:
data = self._get(self.BASE + "/user/balance").get("data", {})
# 官方响应为 {is_available, balance_infos: [{currency,total_balance,...}]},
# 没有顶层 data;同时兼容旧版 data.total_balance 形态。
data = self._get(self.BASE + "/user/balance")
infos = data.get("balance_infos") or []
info = next((i for i in infos if i.get("currency") == "CNY"), infos[0] if infos else {})
if not info and isinstance(data.get("data"), dict):
info = data["data"]
try:
total = float(data.get("total_balance")) if data.get("total_balance") is not None else None
total = float(info.get("total_balance")) if info.get("total_balance") is not None else None
except (TypeError, ValueError):
total = None
return AccountInfo(balance=total, currency="CNY", raw=data)
return AccountInfo(
balance=total, currency=info.get("currency") or "CNY", raw=data
)
def test_connection(self) -> dict:
try: