虎牙网页Cookie来源驱动合并与WSS传输门禁
This commit is contained in:
+26
-11
@@ -248,6 +248,8 @@ class HuyaWssClient:
|
||||
"Chrome/149.0.0.0 Safari/537.36"
|
||||
)
|
||||
headers = {"Accept-Language": "zh-CN,zh;q=0.9"}
|
||||
if cookie:
|
||||
headers["Cookie"] = cookie
|
||||
|
||||
try:
|
||||
self.ws = await asyncio.wait_for(
|
||||
@@ -384,8 +386,11 @@ class HuyaWssClient:
|
||||
if launch_rsp is None:
|
||||
self.logger("[WSS] 活动 wsLaunch 无响应")
|
||||
return False
|
||||
await self.send_auth(cookie, sequence=SEQ_ACTIVITY_BIZ)
|
||||
config_rsp = await self.call_get_config_activity(uid, cookie)
|
||||
await self.send_auth(uid, cookie, sequence=SEQ_ACTIVITY_BIZ)
|
||||
# 9.1 抓包:getConfig 使用 wsLaunch 响应返回的新 guid;业务 UserId 仍为空 guid。
|
||||
config_rsp = await self.call_get_config_activity(
|
||||
uid, cookie, guid=self._launch_guid
|
||||
)
|
||||
if config_rsp is None:
|
||||
self.logger("[WSS] 活动 getConfig 无响应,继续发送 confirm")
|
||||
await self.send_confirm()
|
||||
@@ -427,17 +432,20 @@ class HuyaWssClient:
|
||||
self._parse_launch_response(response)
|
||||
return response
|
||||
|
||||
async def call_get_config_activity(self, uid: int, cookie: str, timeout: float = 10.0):
|
||||
user = self._build_activity_user(uid, cookie)
|
||||
async def call_get_config_activity(
|
||||
self, uid: int, cookie: str, timeout: float = 10.0, guid: str = ""
|
||||
):
|
||||
user = self._build_activity_user(uid, cookie, guid=guid)
|
||||
req = _ActivityConfigReq(user)
|
||||
return await self.call_rpc("mobileui", "getConfig", req, None, timeout=timeout)
|
||||
|
||||
@staticmethod
|
||||
def _build_activity_user(uid: int, cookie: str):
|
||||
def _build_activity_user(uid: int, cookie: str, guid: str = ""):
|
||||
from .activity_structs import ActivityUserId
|
||||
|
||||
user = ActivityUserId()
|
||||
user.lUid = int(uid or 0)
|
||||
user.sGuid = guid or ""
|
||||
user.sHuYaUA = WSS_COOKIE_UA
|
||||
user.sCookie = HuyaWssClient._normalize_biz_cookie(cookie)
|
||||
return user
|
||||
@@ -559,19 +567,26 @@ class HuyaWssClient:
|
||||
return body[5 : 5 + wup_len]
|
||||
return body
|
||||
|
||||
async def send_auth(self, cookie: str, sequence: int = SEQ_WSLAUNCH):
|
||||
"""cmd 0x0a AUTH — 发送 cookie"""
|
||||
ua = "webh5&0.0.1&websocket&&diypc_52775"
|
||||
auth_text = f"huya_ua={ua}; {cookie}"
|
||||
async def send_auth(self, uid: int, cookie: str, sequence: int = SEQ_WSLAUNCH):
|
||||
"""cmd 0x0a AUTH — 发送 TAF 认证结构(与 9.1 活动帧一致)。"""
|
||||
os = TafOutputStream()
|
||||
os.write_int64(0, int(uid or 0))
|
||||
os.write_string(1, WSS_COOKIE_UA)
|
||||
os.write_string(2, HuyaWssClient._normalize_biz_cookie(cookie))
|
||||
os.write_int32(3, 0)
|
||||
os.write_int8(4, 1)
|
||||
os.write_string(5, "HUYA&ZH&2052")
|
||||
os.write_string(6, "")
|
||||
auth_body = os.get_bytes() + TAIL_BYTES
|
||||
msg = WssMessage(
|
||||
command=WssCommand.AUTH,
|
||||
sequence=sequence,
|
||||
body=auth_text.encode("utf-8") + TAIL_BYTES,
|
||||
body=auth_body,
|
||||
)
|
||||
await self.ws.send(msg.encode())
|
||||
self.logger(
|
||||
format_wss_log(
|
||||
auth_text.encode("utf-8") + TAIL_BYTES,
|
||||
auth_body,
|
||||
WssCommand.AUTH,
|
||||
sequence,
|
||||
"发",
|
||||
|
||||
Reference in New Issue
Block a user