From 6a0e88055d656a8fd0f92db674640aa7dda651a2 Mon Sep 17 00:00:00 2001 From: yml Date: Sun, 22 Nov 2026 18:51:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(douyu):=20=E4=BC=98=E5=85=88=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=97=A7=E7=89=88=E8=A7=92=E8=89=B2=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/douyu/activity_client.py | 10 ++++++++-- tests/test_douyu_binding_state.py | 25 ++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/core/douyu/activity_client.py b/core/douyu/activity_client.py index 229404c..7128581 100644 --- a/core/douyu/activity_client.py +++ b/core/douyu/activity_client.py @@ -418,7 +418,13 @@ class DouyuActivityClient: return ctn def get_bind_qr(self, act_alias: str) -> dict[str, Any]: - """按最新活动页链路生成腾讯游戏角色绑定二维码。""" + """生成腾讯游戏角色绑定二维码。 + + 2026-11-22 新 HAR:活动页“切换”按钮会引导用户去斗鱼个人中心,个人中心 + 普通入口携带完整游戏列表,二维码无法自动选中和平精英。``gameRoleBindUrl`` + 仍是旧版直接角色绑定页,带 ``gameIdList=cjm``,优先使用;只有旧入口缺失 + 时才回退到普通 ``url``。 + """ ctn = self.acf_ccn(refresh_subscribe=False) payload = self._request_json( "get", @@ -430,7 +436,7 @@ class DouyuActivityClient: }, ) data = payload.get("data") or {} - url = data.get("url") or data.get("gameRoleBindUrl") or "" + url = data.get("gameRoleBindUrl") or data.get("url") or "" if not url: raise DouyuActivityError(payload.get("msg") or "获取绑定二维码失败") return { diff --git a/tests/test_douyu_binding_state.py b/tests/test_douyu_binding_state.py index 7548c1b..7130be6 100644 --- a/tests/test_douyu_binding_state.py +++ b/tests/test_douyu_binding_state.py @@ -528,7 +528,8 @@ def test_qr_and_confirm_requests_follow_latest_har(monkeypatch): qr = client.get_bind_qr(ACT_ALIAS) confirmed = client.confirm_bind(ACT_ALIAS) - assert qr["url"] == "https://livelink.example/role" + assert qr["url"] == "https://livelink.example/bind" + assert qr["role_param_url"] == "https://livelink.example/role" assert qr["game_role_bind_url"] == "https://livelink.example/bind" assert confirmed["ctn"] == "ctn" assert calls[0]["method"] == "get" @@ -566,3 +567,25 @@ def test_confirm_bind_preserves_platform_cooldown_error_code(monkeypatch): assert exc_info.value.code == -200001 assert exc_info.value.payload == payload + + +def test_get_bind_qr_falls_back_to_role_param_url(monkeypatch): + client = DouyuActivityClient("acf_ccn=ctn") + monkeypatch.setattr( + client, + "acf_ccn", + lambda *, refresh_subscribe=True: "ctn", + ) + monkeypatch.setattr( + client, + "_request_json", + lambda *_args, **_kwargs: { + "error": 0, + "data": {"url": "https://livelink.example/role"}, + }, + ) + + qr = client.get_bind_qr(ACT_ALIAS) + + assert qr["url"] == "https://livelink.example/role" + assert qr["game_role_bind_url"] == ""