fix(huya): 修复精英宝典绑定后角色识别失败

This commit is contained in:
yml2213
2026-11-09 21:25:53 +08:00
parent 5f1d78e1e4
commit b06b622eb3
2 changed files with 63 additions and 15 deletions
+54 -5
View File
@@ -135,12 +135,20 @@ class _FakeGameRole:
class _FakeBindAccountData:
def __init__(self, nick: str, role_name: str):
def __init__(
self,
nick: str,
role_name: str,
*,
is_bind_account: int = 1,
is_bind_role: int = 1,
is_need_act_check: int = 0,
):
self.gameAccount = _FakeGameAccount(nick)
self.gameRole = _FakeGameRole(role_name, "苹果(iOS)", "手Q")
self.isBindAcount = 1
self.isBindRole = 1
self.isNeedActCheck = 0
self.isBindAcount = is_bind_account
self.isBindRole = is_bind_role
self.isNeedActCheck = is_need_act_check
self.changBindTime = 0
@@ -152,13 +160,22 @@ class _FakeBindResponse:
msg: str = "",
nick: str = "微信用户",
role_name: str = "吃鸡199706",
is_bind_account: int = 1,
is_bind_role: int = 1,
is_need_act_check: int = 0,
):
self.status = status
self.msg = msg
self.gameName = "和平精英"
self.gameAuthScene = ""
self.changeBindDay = 7
self.accountData = _FakeBindAccountData(nick, role_name)
self.accountData = _FakeBindAccountData(
nick,
role_name,
is_bind_account=is_bind_account,
is_bind_role=is_bind_role,
is_need_act_check=is_need_act_check,
)
def to_dict(self) -> dict:
return {
@@ -976,6 +993,38 @@ def test_bind_protocol_prefers_configured_gid_and_keeps_legacy_fallback():
}
def test_inner_bind_probe_keeps_gid_and_empties_outer_act_id(monkeypatch):
"""官方页面第二路查询必须是 gid=3203 + outerActId='',才能取到角色名。"""
calls: list[dict] = []
responses = [
_FakeBindResponse(role_name="", is_bind_role=0, is_need_act_check=1),
_FakeBindResponse(role_name="和平精英角色", is_bind_role=1),
]
client = _CkProbeClient(None)
def fake_check(**kwargs):
calls.append(kwargs)
return responses[len(calls) - 1]
monkeypatch.setattr(client, "check_user_bind_game_account", fake_check)
runner, _marks = _task_runner(monkeypatch, "query_game_name")
status, _query = runner._resolve_bind_status(
client,
UID,
COOKIE,
b_act_id_int=0,
outer_act_id="17096",
gid=3203,
is_use_outer_act_id=0,
scene="undefined",
)
assert status.accountData.gameRole.roleName == "和平精英角色"
assert calls[0]["outer_act_id"] == "17096"
assert calls[0]["gid"] == 3203
assert calls[1]["outer_act_id"] == ""
assert calls[1]["gid"] == 3203
def test_confirm_bind_uses_latest_har_protocol(monkeypatch):
"""确认绑定复用抓包里的 gid=3203 / bActId=0 / outerActId=17096。"""
client = _BindConfirmClient()