套餐与订单
已购套餐
GET/api/me/packages
| 字段 | 类型 | 说明 |
|---|---|---|
package_name | string | 套餐名 |
traffic_limit_gb | number | 流量配额(GB),-1 = 不限 |
traffic_used_gb | number | 已用流量(GB) |
traffic_remain_gb | number | 剩余流量(GB),-1 = 不限 |
domains | string | 可用域名数上限。注意是字符串,要比较请先转数字;"-1" = 不限 |
sites_usage | array | 不是数量,是明细:每个元素 {"site_id","domain","used_gb"}。已用域名数 = 数组长度 |
bandwidth connections | string | 带宽 / 连接数上限,"-1" = 不限 |
expires_at expire_at | string | 到期时间,ISO 8601 字符串(不是时间戳) |
valid_until | string | 实测常为空串,判到期请用 expires_at |
line_id backup_line_id | number | 线路与备用线路 |
这一族字段的类型不统一:流量类是数字,而
domains / bandwidth / connections 是字符串。写判断前先转型,别直接比大小。-1(或 "-1")一律表示不限,当成数值参与除法会得出荒谬结果。建议把这两个字段接进监控:
traffic_remain_gb 与 expires_at。套餐流量耗尽或到期时,站点会被系统自动停用,届时站点的 disabled_reason 会写明原因,而且直接调 enable 起不来 —— 提前几天告警比事后救火便宜得多。from datetime import datetime, timezone, timedelta
UNLIMITED = -1
for p in call("GET", "/api/me/packages")["packages"]:
name = p["package_name"]
# 流量: -1 = 不限, 跳过
limit = p.get("traffic_limit_gb")
remain = p.get("traffic_remain_gb")
if limit not in (None, UNLIMITED) and limit > 0:
if remain / limit < 0.1:
alert(f"{name} 剩余流量不足 10%: {remain:.1f}/{limit} GB")
# 域名: domains 是**字符串**, sites_usage 是**明细数组**
cap = int(p.get("domains") or 0) # 先转数字
used = len(p.get("sites_usage") or []) # 数组长度才是已用数
if cap > 0 and used >= cap:
alert(f"{name} 域名数已用满: {used}/{cap}")
# 到期: expires_at 是 ISO 8601 **字符串**, 不能直接和时间戳比大小
exp = p.get("expires_at")
if exp:
dt = datetime.fromisoformat(exp.replace("Z", "+00:00"))
if dt - datetime.now(timezone.utc) < timedelta(days=7):
alert(f"{name} 7 天内到期({exp})")
可购套餐
GET/api/me/packages/available
订单
GET/api/me/orders
订单记录,含 order_no、type、payment_method、amount 等。
GET/api/me/recharges
充值记录。