fix(douyu): 修正绑定状态与换绑冷却判定
This commit is contained in:
@@ -23,6 +23,7 @@ from .account_binding import (
|
||||
binding_snapshot,
|
||||
is_bound_act,
|
||||
is_pending_binding_role,
|
||||
is_platform_account_bind_cooldown,
|
||||
is_role_change_cooling,
|
||||
role_change_available_at,
|
||||
set_bind_status,
|
||||
@@ -1323,6 +1324,9 @@ class BindMixin:
|
||||
),
|
||||
"bind_phase": "change_waiting",
|
||||
"bind_polling": False,
|
||||
# 2026-11-22 换绑失败 HAR:canChangeTime 限制的是当前斗鱼账号,
|
||||
# 不是客户扫码后出现的腾讯游戏角色。
|
||||
"issue_code": "account_role_cooldown",
|
||||
}
|
||||
self._apply_bind_info_to_account(
|
||||
account,
|
||||
@@ -1333,7 +1337,7 @@ class BindMixin:
|
||||
db,
|
||||
task,
|
||||
"failed",
|
||||
f"{role_label} 暂不能换绑,剩余 {wait_text}",
|
||||
f"斗鱼账号当前角色({role_label})未到可换绑时间,剩余 {wait_text}",
|
||||
result,
|
||||
)
|
||||
return
|
||||
@@ -1386,9 +1390,52 @@ class BindMixin:
|
||||
)
|
||||
),
|
||||
}
|
||||
# 2026-11-22:二维码生成前的 pending 只能作为 baseline,不能直接
|
||||
# 推进 role_ready。官方活动 alias 会长期保留 needBindAct=1,必须在
|
||||
# 二维码生成后观察到绑定状态变化,才能证明这是本轮扫码结果。
|
||||
# 2026-11-22 绑定成功 HAR:二维码生成前已经存在的 bindAct=0 角色
|
||||
# 是官网认可的 pending,可以直接确认,不要求本轮再次出现状态迁移。
|
||||
# 历史 bindAct=1 角色已被上面的 pending 判定排除,不会再误报。
|
||||
if pending_decision["confirmable"]:
|
||||
pending_snapshot = self._bind_snapshot(pending_before)
|
||||
pending_role = str(pending_snapshot["role_name"] or "")
|
||||
pending_alias = str(pending_before.get("act_alias") or "")
|
||||
pending_summary = (
|
||||
f"act={pending_alias or '-'} "
|
||||
f"{self._format_bind_summary(pending_before, pending=True)}"
|
||||
)
|
||||
result.update(
|
||||
{
|
||||
**pending_snapshot,
|
||||
"act_alias": pending_alias,
|
||||
"query_act_alias": pending_alias,
|
||||
"pending_role_name": pending_role,
|
||||
"bind_ready_for_confirm": True,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "role_ready",
|
||||
"bind_polling": False,
|
||||
"bind_summary": pending_summary,
|
||||
"bind_decision": pending_decision,
|
||||
"bind_candidate_decisions": candidate_decisions,
|
||||
"action_act_aliases": action_aliases,
|
||||
"poll_count": 0,
|
||||
}
|
||||
)
|
||||
account.updated_at = qr_generated_at
|
||||
self._push_log(
|
||||
"success",
|
||||
"生成二维码时发现已有可确认角色 "
|
||||
f"act={pending_alias or '-'} role={pending_role or '-'} "
|
||||
f"reason={pending_decision['reason']}",
|
||||
)
|
||||
self._mark_task(
|
||||
db,
|
||||
task,
|
||||
"success",
|
||||
f"已识别现有待确认角色: {pending_role},待确认绑定",
|
||||
result,
|
||||
)
|
||||
return
|
||||
|
||||
# 没有可确认 pending 时只发布二维码并交给持久化轮询。尤其不能在
|
||||
# bindAct=1 + needBindAct=1 时提前进入 role_ready。
|
||||
account.updated_at = datetime.now(UTC)
|
||||
task.queue_lane = "binding_poll"
|
||||
task.next_run_at = qr_generated_at + timedelta(
|
||||
@@ -1558,25 +1605,67 @@ class BindMixin:
|
||||
confirm_result = client.confirm_bind(use_confirm_alias)
|
||||
except DouyuActivityError as exc:
|
||||
confirm_msg = str(exc)
|
||||
confirm_code = getattr(exc, "code", None)
|
||||
confirm_payload = getattr(exc, "payload", None)
|
||||
self._push_log("warning", f"确认绑定接口失败: {confirm_msg}")
|
||||
# 待绑定游戏账号侧换绑限制(未到换绑时间等)导致确认失败:保留原绑定并给出明确提示
|
||||
if isinstance(confirm_payload, dict) and confirm_payload:
|
||||
record_role_api_response(
|
||||
db,
|
||||
account_id=account.id,
|
||||
task_id=task.id,
|
||||
response=confirm_payload,
|
||||
scope=SCOPE_ELITE,
|
||||
stage="confirm_bind.error",
|
||||
source="douyu_task.confirm_bind",
|
||||
act_alias=use_confirm_alias,
|
||||
)
|
||||
account_cooldown = is_platform_account_bind_cooldown(
|
||||
confirm_code,
|
||||
confirm_msg,
|
||||
)
|
||||
before_bound_snapshot = self._bind_snapshot(before_bound)
|
||||
before_bound_role = str(before_bound_snapshot["role_name"] or "")
|
||||
before_bound_wait = before_bound_snapshot["change_role_wait_time"]
|
||||
before_bound_wait_text = self._format_wait_time(before_bound_wait)
|
||||
if account_cooldown:
|
||||
issue_code = "account_role_cooldown"
|
||||
role_label = before_bound_role or role_name or "当前角色"
|
||||
suffix = f",剩余 {before_bound_wait_text}" if before_bound_wait_text else ""
|
||||
failure_message = (
|
||||
f"斗鱼账号当前绑定角色({role_label})未到可换绑时间"
|
||||
f"{suffix},请更换斗鱼账号或稍后重试"
|
||||
)
|
||||
else:
|
||||
issue_code = "customer_role_cooldown"
|
||||
failure_message = (
|
||||
f"待绑定游戏账号({role_name or '-'})未到换绑时间"
|
||||
"(不是斗鱼/虎牙账号),请重新换账号扫码绑定"
|
||||
)
|
||||
# 2026-11-22 换绑失败 HAR:actBind 已拒绝时新角色只存在于 cjm 候选态,
|
||||
# 活动 alias 仍是原绑定。必须保留旧角色,不能让失败角色污染账号库。
|
||||
if before_bound is not None:
|
||||
self._apply_bind_info_to_account(account, before_bound)
|
||||
self._apply_bind_info_to_account(account, before_bound, BIND_BOUND)
|
||||
else:
|
||||
account.updated_at = datetime.now(UTC)
|
||||
self._mark_task(
|
||||
db,
|
||||
task,
|
||||
"failed",
|
||||
f"待绑定游戏账号({role_name or '-'})未到换绑时间(不是斗鱼/虎牙账号),请重新换账号扫码绑定",
|
||||
failure_message,
|
||||
{
|
||||
"act_alias": use_confirm_alias,
|
||||
"query_act_alias": query_alias,
|
||||
"query_act_aliases": query_aliases,
|
||||
"before_bind_info": before,
|
||||
"before_bound_bind_info": before_bound,
|
||||
"before_bound_snapshot": (
|
||||
before_bound_snapshot if before_bound is not None else None
|
||||
),
|
||||
**before_snapshot,
|
||||
"confirm_error": confirm_msg,
|
||||
"bind_ready_for_confirm": True,
|
||||
"confirm_error_code": confirm_code,
|
||||
"issue_code": issue_code,
|
||||
"bind_ready_for_confirm": False,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "confirm_failed",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user