fix(douyu): 修正绑定状态与换绑冷却判定
This commit is contained in:
@@ -285,6 +285,25 @@ def role_change_available_at(
|
||||
return None
|
||||
|
||||
|
||||
def is_platform_account_bind_cooldown(
|
||||
error_code: Any = None,
|
||||
message: str = "",
|
||||
) -> bool:
|
||||
"""是否为斗鱼平台账号自身的换绑冷却。
|
||||
|
||||
2026-11-22 换绑失败 HAR 中 ``actBind`` 返回 ``-200001``:
|
||||
“该平台账号未到可换绑时间,请使用其他平台账号”。它限制的是当前斗鱼号,
|
||||
不是用户扫码选择的腾讯游戏角色;提示和人工处理都必须区分两者。
|
||||
"""
|
||||
try:
|
||||
normalized_code = int(error_code)
|
||||
except (TypeError, ValueError):
|
||||
normalized_code = None
|
||||
return normalized_code == -200001 or "该平台账号未到可换绑时间" in (
|
||||
message or ""
|
||||
)
|
||||
|
||||
|
||||
def binding_pending_decision(
|
||||
info: dict | None,
|
||||
*,
|
||||
@@ -295,9 +314,15 @@ def binding_pending_decision(
|
||||
) -> dict[str, Any]:
|
||||
"""解释一个绑定候选是否可进入确认阶段。
|
||||
|
||||
角色名不是唯一事实,也不能要求每次都必须换新角色。用户重新绑定同名角色
|
||||
时,必须观察到二维码生成后的状态变化。``needBindAct=1`` 在本活动里是
|
||||
持续存在的“仍允许绑定”标志,不能单独证明存在新的扫码结果。
|
||||
2026-11-22 两份 HAR 证明必须把两类状态分开:
|
||||
|
||||
- ``bindAct=0 + roleName``:角色已选中但未最终生效,是可确认 pending。
|
||||
它可以在生成新二维码前就存在,官网仍允许直接 ``actBind``;
|
||||
- ``bindAct=1 + needBindAct=1``:最终绑定已经生效。``needBindAct`` 是长期
|
||||
存在的“仍允许以后换绑”标志,不能当成新的扫码结果。
|
||||
|
||||
因此 ``bindAct=1`` 永远不是 pending;``bindAct=0`` 的动作 alias 即使没有
|
||||
观察到本轮状态迁移,也仍然可以确认。角色名相同不等于已经绑定。
|
||||
"""
|
||||
result: dict[str, Any] = {
|
||||
"alias": str((info or {}).get("act_alias") or ""),
|
||||
@@ -339,60 +364,67 @@ def binding_pending_decision(
|
||||
if not role_name:
|
||||
result["reason"] = "no_role"
|
||||
return result
|
||||
baseline = baseline_role_name.strip()
|
||||
if not baseline:
|
||||
# 2026-11-22:没有 baseline 无法证明这是本轮扫码产生的新角色。
|
||||
# 历史库中 bound + needBindAct 会长期并存,不能再次冒充 pending。
|
||||
result["reason"] = (
|
||||
"already_bound"
|
||||
if snapshot["is_bound_act"]
|
||||
else "pending_without_baseline"
|
||||
)
|
||||
if snapshot["is_bound_act"]:
|
||||
# 2026-11-22 换绑失败 HAR:历史角色会长期返回 bindAct=1 + needBindAct=1。
|
||||
# 这表示当前绑定仍生效,不是待确认;若官方在扫码后直接完成绑定,轮询层
|
||||
# 会通过 directly_confirmed 收敛,不需要把它伪装成 pending。
|
||||
result["reason"] = "already_bound"
|
||||
return result
|
||||
if role_name.casefold() != baseline.casefold():
|
||||
baseline = baseline_role_name.strip()
|
||||
if baseline and role_name.casefold() != baseline.casefold():
|
||||
result["role_changed"] = True
|
||||
result.update({"confirmable": True, "reason": "role_changed"})
|
||||
return result
|
||||
if not isinstance(baseline_info, dict):
|
||||
if snapshot["is_bound_act"]:
|
||||
result["reason"] = "already_bound"
|
||||
|
||||
baseline_snapshot: dict[str, Any] | None = None
|
||||
if isinstance(baseline_info, dict):
|
||||
baseline_snapshot = binding_snapshot(baseline_info)
|
||||
result["baseline_need_bind_act"] = bool(
|
||||
baseline_snapshot["need_bind_act"]
|
||||
)
|
||||
result["baseline_is_pending"] = bool(
|
||||
baseline_snapshot["role_name"]
|
||||
and not baseline_snapshot["is_bound_act"]
|
||||
and baseline_snapshot["need_bind_act"]
|
||||
)
|
||||
if result["same_alias"] and baseline_snapshot["is_bound_act"]:
|
||||
result.update(
|
||||
{
|
||||
"confirmable": True,
|
||||
"reason": "same_alias_after_bound_transition",
|
||||
}
|
||||
)
|
||||
return result
|
||||
result["reason"] = "same_role_without_baseline_info"
|
||||
if (
|
||||
result["same_alias"]
|
||||
and not baseline_snapshot["need_bind_act"]
|
||||
and snapshot["need_bind_act"]
|
||||
):
|
||||
result.update(
|
||||
{
|
||||
"confirmable": True,
|
||||
"reason": "same_alias_after_pending_transition",
|
||||
}
|
||||
)
|
||||
return result
|
||||
|
||||
# 2026-11-22 绑定成功 HAR:官网允许确认二维码生成前就已经存在的
|
||||
# bindAct=0 角色。这里不能再要求“本轮必须发生状态变化”,否则合法 pending
|
||||
# 会一直轮询到超时。关键安全边界是上面的 bindAct=1 已提前返回。
|
||||
if result["actionable_alias"] and snapshot["need_bind_act"]:
|
||||
result.update(
|
||||
{
|
||||
"confirmable": True,
|
||||
"reason": "existing_actionable_pending",
|
||||
}
|
||||
)
|
||||
return result
|
||||
|
||||
baseline_snapshot = binding_snapshot(baseline_info)
|
||||
result["baseline_need_bind_act"] = bool(
|
||||
baseline_snapshot["need_bind_act"]
|
||||
)
|
||||
result["baseline_is_pending"] = bool(
|
||||
baseline_snapshot["role_name"]
|
||||
and not baseline_snapshot["is_bound_act"]
|
||||
and baseline_snapshot["need_bind_act"]
|
||||
)
|
||||
if result["same_alias"] and (
|
||||
baseline_snapshot["is_bound_act"] and not snapshot["is_bound_act"]
|
||||
):
|
||||
result.update(
|
||||
{
|
||||
"confirmable": True,
|
||||
"reason": "same_alias_after_bound_transition",
|
||||
}
|
||||
)
|
||||
if not baseline:
|
||||
result["reason"] = "pending_without_baseline"
|
||||
return result
|
||||
if (
|
||||
result["same_alias"]
|
||||
and not snapshot["is_bound_act"]
|
||||
and snapshot["need_bind_act"]
|
||||
and not baseline_snapshot["need_bind_act"]
|
||||
):
|
||||
result.update(
|
||||
{
|
||||
"confirmable": True,
|
||||
"reason": "same_alias_after_pending_transition",
|
||||
}
|
||||
)
|
||||
return result
|
||||
if snapshot["is_bound_act"]:
|
||||
result["reason"] = "already_bound"
|
||||
if baseline_snapshot is None:
|
||||
result["reason"] = "same_role_without_baseline_info"
|
||||
return result
|
||||
result["reason"] = (
|
||||
"same_role_stale_pending"
|
||||
|
||||
Reference in New Issue
Block a user