From 8e3c0e69bc56616d2540364be79cfc56dccac528 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Tue, 1 Sep 2026 12:56:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=99=8E=E7=89=99=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8wsLaunch=E5=8C=85=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/huya/wss_client.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/huya/wss_client.py b/core/huya/wss_client.py index 7b91b86..8fb9a6f 100644 --- a/core/huya/wss_client.py +++ b/core/huya/wss_client.py @@ -163,6 +163,19 @@ class HuyaWssClient: + HuyaWssClient._make_big_tail() ) + @staticmethod + def _encode_activity_launch_body(wup_data: bytes) -> bytes: + """活动 wsLaunch 使用浏览器的固定大包头,即使包体小于 255B。""" + if len(wup_data) < 4: + return wup_data + TAIL_BYTES + packet_len = len(wup_data) + return ( + bytes([packet_len & 0xFF]) + + packet_len.to_bytes(4, "big") + + wup_data[4:] + + TAIL_BYTES + ) + @staticmethod def _normalize_biz_cookie(cookie: str) -> str: """业务 RPC 的 huya_ua Cookie 值按浏览器 WSS 抓包修正""" @@ -398,7 +411,7 @@ class HuyaWssClient: wup.setRequestId(-1) wup.iTimeout = 0 wup.newdata["tReq"] = os.get_bytes() - body = self._encode_rpc_body(wup.encode()) + body = self._encode_activity_launch_body(wup.encode()) msg = WssMessage(WssCommand.RPC_REQUEST, SEQ_ACTIVITY_WSLAUNCH, body) future = asyncio.Future() self.rpc_queue.append(future)