feat(douyu): 完成账号平台阶段一到四并接入最新协议
This commit is contained in:
@@ -40,6 +40,7 @@ from .account_events_service import CATEGORY_OPS, emit
|
||||
from .account_lifecycle import on_ck_verdict
|
||||
from .account_sync_service import (
|
||||
DOMAIN_ELITE,
|
||||
DOMAIN_ESPORTS,
|
||||
DOMAIN_GOLD,
|
||||
DOMAIN_POINTS,
|
||||
DOMAIN_ROLE,
|
||||
@@ -49,11 +50,13 @@ from .account_sync_service import (
|
||||
from .cookie_check_service import check_douyu_cookie, classify_douyu_cookie_result
|
||||
from .douyu_activity_query import (
|
||||
activity_client,
|
||||
extract_points_expire_time,
|
||||
query_activity_goods,
|
||||
query_bind_info,
|
||||
query_csrf,
|
||||
query_elite_user_info,
|
||||
query_esports_bind_info,
|
||||
query_esports_user_info,
|
||||
query_gold_account,
|
||||
query_limited_goods_result,
|
||||
query_points,
|
||||
@@ -520,14 +523,10 @@ def _points_expire_at(
|
||||
*,
|
||||
checked_at: datetime,
|
||||
) -> datetime | None:
|
||||
raw = (points_response or {}).get("willExpireTime") or (points_response or {}).get(
|
||||
"will_expire_time"
|
||||
)
|
||||
value = _to_int(raw)
|
||||
if value is None or value <= 0:
|
||||
# 2026-11-21:积分响应可能是归一化结果、raw 或 raw.data,统一走同一个提取器。
|
||||
value = extract_points_expire_time(points_response)
|
||||
if value is None:
|
||||
return None
|
||||
if value > 10_000_000_000:
|
||||
value //= 1000
|
||||
if value < int(checked_at.timestamp()) - 60:
|
||||
return None
|
||||
return datetime.fromtimestamp(value, tz=UTC)
|
||||
@@ -613,6 +612,8 @@ def probe_account(
|
||||
_DEFAULT_SESSION_CHECKER
|
||||
),
|
||||
with_elite: bool = True,
|
||||
with_esports: bool = False,
|
||||
with_storehome: bool = True,
|
||||
with_eligibility: bool = False,
|
||||
with_limited_goods: bool = False,
|
||||
with_gold: bool = False,
|
||||
@@ -628,6 +629,8 @@ def probe_account(
|
||||
cache_mode = "|".join(
|
||||
[
|
||||
f"elite={int(with_elite)}",
|
||||
f"esports_info={int(with_esports)}",
|
||||
f"storehome={int(with_storehome)}",
|
||||
f"elig={int(with_eligibility)}",
|
||||
f"limited={int(with_limited_goods)}",
|
||||
f"gold={int(with_gold)}",
|
||||
@@ -685,6 +688,15 @@ def probe_account(
|
||||
"opened": account.elite_opened,
|
||||
"error": "",
|
||||
},
|
||||
"esports": {
|
||||
"status": CAPABILITY_UNKNOWN,
|
||||
"raw": {},
|
||||
"manual_type": None,
|
||||
"manual_score": None,
|
||||
"expire_time": None,
|
||||
"opened": account.esports_opened,
|
||||
"error": "",
|
||||
},
|
||||
"eligibility": {
|
||||
"points": account.points,
|
||||
"points_response": {},
|
||||
@@ -742,6 +754,17 @@ def probe_account(
|
||||
except Exception as exc: # noqa: BLE001 - 单项能力边界
|
||||
errors["elite"] = f"{type(exc).__name__}: {_text(exc)}"
|
||||
|
||||
esports: dict[str, Any] = {}
|
||||
esports_manual_id = str(config_info.get("esports_manual_id") or "").strip()
|
||||
if esports_manual_id and with_esports:
|
||||
try:
|
||||
esports = query_esports_user_info(
|
||||
active_client,
|
||||
manual_id=esports_manual_id,
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001 - 单项能力边界
|
||||
errors["esports"] = f"{type(exc).__name__}: {_text(exc)}"
|
||||
|
||||
roles: dict[str, dict[str, Any]] = {}
|
||||
if with_elite_role:
|
||||
roles["elite"] = resolve_elite_role(active_client, config_info)
|
||||
@@ -764,7 +787,7 @@ def probe_account(
|
||||
points_response = points_result
|
||||
except Exception as exc: # noqa: BLE001
|
||||
errors["points"] = f"{type(exc).__name__}: {_text(exc)}"
|
||||
if with_eligibility or with_limited_goods:
|
||||
if with_storehome and (with_eligibility or with_limited_goods):
|
||||
try:
|
||||
limited_result = query_limited_goods_result(
|
||||
active_client,
|
||||
@@ -849,6 +872,12 @@ def probe_account(
|
||||
manual_score = _to_int(elite.get("manual_score"))
|
||||
expire_time = normalize_elite_expire_time(elite.get("expire_time"))
|
||||
elite_opened = elite_is_currently_open(manual_type, expire_time, now=checked_at)
|
||||
esports_manual_type = _to_int(esports.get("manual_type"))
|
||||
esports_manual_score = _to_int(esports.get("manual_score"))
|
||||
esports_expire_time = normalize_elite_expire_time(esports.get("expire_time"))
|
||||
esports_opened = bool(
|
||||
esports_manual_type is not None and esports_manual_type >= 1
|
||||
)
|
||||
if points is None:
|
||||
points = manual_score
|
||||
identity = _identity_result(
|
||||
@@ -876,6 +905,19 @@ def probe_account(
|
||||
"opened": elite_opened,
|
||||
"error": errors.get("elite", ""),
|
||||
},
|
||||
"esports": {
|
||||
"status": CAPABILITY_OK
|
||||
if esports
|
||||
else CAPABILITY_ERROR
|
||||
if "esports" in errors
|
||||
else CAPABILITY_UNKNOWN,
|
||||
"raw": esports,
|
||||
"manual_type": esports_manual_type,
|
||||
"manual_score": esports_manual_score,
|
||||
"expire_time": esports_expire_time,
|
||||
"opened": esports_opened,
|
||||
"error": errors.get("esports", ""),
|
||||
},
|
||||
"eligibility": {
|
||||
"manual_id": manual_id,
|
||||
"rid": str(config_info.get("rid") or ""),
|
||||
@@ -966,6 +1008,7 @@ def persist_probe_result(
|
||||
source: str,
|
||||
record_event: bool = True,
|
||||
commit: bool = False,
|
||||
update_session: bool = True,
|
||||
) -> None:
|
||||
"""把一次探针结果写回账号和生命周期,是账号能力的唯一落库入口。"""
|
||||
now = _now()
|
||||
@@ -977,7 +1020,11 @@ def persist_probe_result(
|
||||
|
||||
session = probe.get("session") or {}
|
||||
session_status = str(session.get("status") or "")
|
||||
if session_status in {SESSION_VALID, SESSION_INVALID, SESSION_ERROR}:
|
||||
if update_session and session_status in {
|
||||
SESSION_VALID,
|
||||
SESSION_INVALID,
|
||||
SESSION_ERROR,
|
||||
}:
|
||||
detail = (
|
||||
session.get("detail") if isinstance(session.get("detail"), dict) else {}
|
||||
)
|
||||
@@ -1022,10 +1069,26 @@ def persist_probe_result(
|
||||
raw_payload=dict(elite),
|
||||
)
|
||||
|
||||
esports = probe.get("esports") or {}
|
||||
if esports.get("status") == CAPABILITY_OK:
|
||||
account.esports_opened = bool(esports.get("opened"))
|
||||
account.esports_points = _to_int(esports.get("manual_score"))
|
||||
account.esports_expire_time = _to_int(esports.get("expire_time"))
|
||||
record_sync_success(
|
||||
db,
|
||||
account_id=int(account.id),
|
||||
domain=DOMAIN_ESPORTS,
|
||||
source=source,
|
||||
observed_at=now,
|
||||
raw_payload=dict(esports),
|
||||
)
|
||||
|
||||
eligibility = probe.get("eligibility") or {}
|
||||
if _to_int(eligibility.get("points")) is not None:
|
||||
account.points = _to_int(eligibility.get("points"))
|
||||
if isinstance(eligibility.get("points_response"), dict):
|
||||
if isinstance(eligibility.get("points_response"), dict) and eligibility[
|
||||
"points_response"
|
||||
]:
|
||||
record_sync_success(
|
||||
db,
|
||||
account_id=int(account.id),
|
||||
|
||||
Reference in New Issue
Block a user