fix(ai): DeepSeek 余额按官方 balance_infos 解析
/user/balance 返回的是 {is_available, balance_infos[]},没有顶层 data,
旧实现永远解析出 None,连接测试会显示「余额 None CNY」。同时补全
TotHost 预设平台,新环境初始化后即可直接配 whmcs-panel。
This commit is contained in:
+11
-3
@@ -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:
|
||||
|
||||
@@ -35,6 +35,10 @@ PRESET_PROVIDERS = [
|
||||
{"slug": "linode", "name": "Linode", "name_en": "Akamai Linode", "category": "vps",
|
||||
"services": "vps,domain,dns",
|
||||
"website": "https://linode.com", "console_url": "https://cloud.linode.com", "sdk_type": "linode-api"},
|
||||
# WHMCS 面板类平台没有开放 API,通过账号关联的登录凭据进入客户区只读核对。
|
||||
{"slug": "tothost", "name": "TotHost", "name_en": "TotHost", "category": "vps",
|
||||
"services": "vps",
|
||||
"website": "https://www.tothost.vn", "console_url": "https://billing.tothost.vn/clientarea.php", "sdk_type": "whmcs-panel"},
|
||||
# 以下平台暂无适配器:sdk_type 必须留空。
|
||||
# 填了不存在的 sdk_type 会让平台卡片显示「API 对接: xxx」,用户建账号点同步才撞
|
||||
# 「暂不支持的 SDK 类型」——声明支持却不支持,比明说不支持更糟。
|
||||
|
||||
Reference in New Issue
Block a user