fix(huya): 区分当前绑定与待确认角色
This commit is contained in:
+110
-13
@@ -1596,6 +1596,55 @@ def _bind_game_account_has_role(resp: Any) -> bool:
|
||||
return bool(getattr(game_role, "roleName", ""))
|
||||
|
||||
|
||||
def _bind_game_account_candidate(resp: Any, source: str) -> dict[str, Any]:
|
||||
"""把一路 ``checkUserBindGameAccount`` 响应整理成可序列化的角色候选。
|
||||
|
||||
2026-11-14 待绑定状态抓包确认:
|
||||
- ``gid + outerActId`` 返回当前已绑定角色;
|
||||
- ``gid + outerActId=空`` 返回待确认的新角色。
|
||||
|
||||
两路都可能是 200,不能只看“有没有角色名”就认为后一路覆盖前一路。
|
||||
"""
|
||||
account_data = getattr(resp, "accountData", None)
|
||||
game_account = getattr(account_data, "gameAccount", None)
|
||||
game_role = getattr(account_data, "gameRole", None)
|
||||
role_name = str(getattr(game_role, "roleName", "") or "").strip()
|
||||
plat_name = str(getattr(game_role, "platName", "") or "").strip()
|
||||
area_name = str(getattr(game_role, "areaName", "") or "").strip()
|
||||
return {
|
||||
"source": source,
|
||||
"game_title": str(getattr(resp, "gameName", "") or ""),
|
||||
"role_name": role_name,
|
||||
"role_id": str(getattr(game_role, "roleId", "") or ""),
|
||||
"plat_name": plat_name,
|
||||
"area_name": area_name,
|
||||
"channel": " / ".join(part for part in (plat_name, area_name) if part),
|
||||
"partition_name": str(getattr(game_role, "partitionName", "") or ""),
|
||||
"game_serial": str(getattr(game_role, "gameSerial", "") or ""),
|
||||
"game_account": {
|
||||
"nick": str(getattr(game_account, "nick", "") or ""),
|
||||
"type": str(getattr(game_account, "type", "") or ""),
|
||||
"face_url": str(getattr(game_account, "faceUrl", "") or ""),
|
||||
"has_open_id": bool(getattr(game_account, "openId", "")),
|
||||
"has_access_token": bool(getattr(game_account, "accessToken", "")),
|
||||
},
|
||||
"game_role": {
|
||||
"role_id": str(getattr(game_role, "roleId", "") or ""),
|
||||
"role_name": role_name,
|
||||
"area_name": area_name,
|
||||
"plat_name": plat_name,
|
||||
"partition_name": str(getattr(game_role, "partitionName", "") or ""),
|
||||
"game_serial": str(getattr(game_role, "gameSerial", "") or ""),
|
||||
},
|
||||
"is_bind_account": int(getattr(account_data, "isBindAcount", 0) or 0),
|
||||
"is_bind_role": int(getattr(account_data, "isBindRole", 0) or 0),
|
||||
"is_need_act_check": int(getattr(account_data, "isNeedActCheck", 0) or 0),
|
||||
"change_bind_time": int(getattr(account_data, "changBindTime", 0) or 0),
|
||||
"change_bind_day": int(getattr(resp, "changeBindDay", 0) or 0),
|
||||
"status": int(getattr(resp, "status", 0) or 0),
|
||||
}
|
||||
|
||||
|
||||
def query_bind_game_account(
|
||||
client: Any,
|
||||
*,
|
||||
@@ -1608,15 +1657,21 @@ def query_bind_game_account(
|
||||
scene: str = "",
|
||||
timeout: float | None = None,
|
||||
) -> tuple[Any, dict[str, Any]]:
|
||||
"""查询绑定游戏账号(官方活动页两条查询,返回最新角色)。
|
||||
"""查询绑定游戏账号,并区分当前绑定角色与待确认角色。
|
||||
|
||||
2026-11-09 真机定论:新版活动页先查 ``gid + outerActId``,再查
|
||||
``gid + outerActId=空``;**角色名以第二路为准**(第一路会返回旧的缓存角色)。
|
||||
旧协议(gid=0)第二路会被服务端判 501,保持外层优先、缺角色时补查内层。
|
||||
新版活动页会查两路:
|
||||
- ``gid + outerActId``:当前已生效绑定;
|
||||
- ``gid + outerActId=空``:角色选择/换绑后、点「确认绑定」前的新角色。
|
||||
|
||||
2026-11-14 待绑定状态真机抓包中,两路同时返回 200:
|
||||
第一路是页面右上角显示的当前角色,第二路是确认弹窗里的待绑定角色。
|
||||
因此不能再用“内层有角色就无条件覆盖”的规则。只有两路确实不同时,
|
||||
才把内层标记为 ``pending_role``;返回值优先当前绑定,首次绑定没有当前角色时
|
||||
才回退到待确认角色。
|
||||
|
||||
返回 ``(status, detail)``:
|
||||
- ``status``:最终选中的 ``CheckUserBindGameAccountResp``(``None`` 表示接口无响应);
|
||||
- ``detail``:两路响应与来源标记,供任务结果透传(可 JSON 序列化)。
|
||||
- ``status``:当前绑定响应;没有当前绑定则回退待确认响应;
|
||||
- ``detail``:两路原始响应、标准化候选和来源标记(可 JSON 序列化)。
|
||||
"""
|
||||
|
||||
def _call(outer_id: str, use_outer: int):
|
||||
@@ -1643,15 +1698,16 @@ def query_bind_game_account(
|
||||
if outer.status != 200:
|
||||
return outer, detail
|
||||
|
||||
outer_role = _bind_game_account_candidate(outer, "outer")
|
||||
inner_role: dict[str, Any] | None = None
|
||||
chosen = outer
|
||||
if gid:
|
||||
# 第二路(gid + outerActId=空)是最新角色源,带出角色就优先采用。
|
||||
# 第二路专门读取换绑/首次绑定后、确认前的角色候选。
|
||||
inner = _call("", 0)
|
||||
if inner is not None:
|
||||
detail["inner_bind_status"] = inner.to_dict()
|
||||
if inner.status == 200 and _bind_game_account_has_role(inner):
|
||||
chosen = inner
|
||||
detail["bind_status_source"] = "inner"
|
||||
if inner.status == 200:
|
||||
inner_role = _bind_game_account_candidate(inner, "inner")
|
||||
else:
|
||||
account_data = getattr(outer, "accountData", None)
|
||||
if not _bind_game_account_has_role(outer) and bool(
|
||||
@@ -1662,9 +1718,50 @@ def query_bind_game_account(
|
||||
inner = _call("", 0)
|
||||
if inner is not None:
|
||||
detail["inner_bind_status"] = inner.to_dict()
|
||||
if inner.status == 200 and _bind_game_account_has_role(inner):
|
||||
chosen = inner
|
||||
detail["bind_status_source"] = "inner"
|
||||
if inner.status == 200:
|
||||
inner_role = _bind_game_account_candidate(inner, "inner")
|
||||
|
||||
current_role = outer_role if outer_role["role_name"] else None
|
||||
role_identity_changed = bool(
|
||||
current_role
|
||||
and inner_role
|
||||
and (
|
||||
inner_role["role_name"] != current_role["role_name"]
|
||||
or (
|
||||
inner_role["role_id"]
|
||||
and current_role["role_id"]
|
||||
and inner_role["role_id"] != current_role["role_id"]
|
||||
)
|
||||
)
|
||||
)
|
||||
pending_role = (
|
||||
inner_role
|
||||
if inner_role
|
||||
and inner_role["role_name"]
|
||||
and (not current_role or role_identity_changed)
|
||||
else None
|
||||
)
|
||||
if current_role:
|
||||
chosen = outer
|
||||
elif pending_role:
|
||||
chosen = inner
|
||||
detail["bind_status_source"] = "inner_pending"
|
||||
|
||||
candidates = [
|
||||
candidate
|
||||
for candidate in (outer_role, inner_role)
|
||||
if candidate and candidate["role_name"]
|
||||
]
|
||||
detail.update(
|
||||
{
|
||||
"outer_bind_role": outer_role,
|
||||
"inner_bind_role": inner_role,
|
||||
"current_role": current_role,
|
||||
"pending_role": pending_role,
|
||||
"role_candidates": candidates,
|
||||
"has_pending_role": bool(pending_role),
|
||||
}
|
||||
)
|
||||
|
||||
detail["bind_status"] = chosen.to_dict()
|
||||
return chosen, detail
|
||||
|
||||
Reference in New Issue
Block a user