修正虎牙活动WSS初始化序列
This commit is contained in:
+16
-7
@@ -63,6 +63,8 @@ SEQ_GETCONFIG = 0x1D000076
|
||||
SEQ_REGISTER = 0x1D00003C
|
||||
SEQ_CONFIRM = 0x1D000002
|
||||
SEQ_BUSINESS = 0x1D000106 # 业务 RPC (HAR 7.4 实证:业务帧固定使用该 seq)
|
||||
SEQ_ACTIVITY_WSLAUNCH = 0x1D000100
|
||||
SEQ_ACTIVITY_BIZ = 0x1D000109
|
||||
|
||||
|
||||
class WssCommand:
|
||||
@@ -113,6 +115,7 @@ class HuyaWssClient:
|
||||
self._heartbeat_task = None
|
||||
self._launch_guid = ""
|
||||
self._launch_ip = ""
|
||||
self._activity_mode = False
|
||||
|
||||
def _next_biz_seq(self) -> int:
|
||||
"""业务 RPC 的 frame seq。
|
||||
@@ -120,7 +123,7 @@ class HuyaWssClient:
|
||||
浏览器在商城 WSS 上连续发送多个业务 RPC 时,frame seq 都保持
|
||||
0x1d000106;真正区分请求依赖 WUP requestId。
|
||||
"""
|
||||
return SEQ_BUSINESS
|
||||
return SEQ_ACTIVITY_BIZ if self._activity_mode else SEQ_BUSINESS
|
||||
|
||||
def _next_wup_req_id(self) -> int:
|
||||
"""业务 WUP requestId,HAR 中 getGoodsInfoV5 从 8 开始递增"""
|
||||
@@ -362,12 +365,16 @@ class HuyaWssClient:
|
||||
|
||||
async def initialize_activity(self, uid: int, guid: str, cookie: str):
|
||||
"""活动通道初始化:heartbeat -> wsLaunch -> AUTH -> getConfig -> confirm。"""
|
||||
self._activity_mode = True
|
||||
await self.send_heartbeat()
|
||||
launch_rsp = await self.call_ws_launch_activity(uid, guid)
|
||||
if launch_rsp is None:
|
||||
self.logger("[WSS] 活动 wsLaunch 无响应")
|
||||
return False
|
||||
await self.send_auth(cookie)
|
||||
await self.call_get_config_activity(uid, cookie)
|
||||
await self.send_auth(cookie, sequence=SEQ_ACTIVITY_BIZ)
|
||||
config_rsp = await self.call_get_config_activity(uid, cookie)
|
||||
if config_rsp is None:
|
||||
self.logger("[WSS] 活动 getConfig 无响应,继续发送 confirm")
|
||||
await self.send_confirm()
|
||||
await asyncio.sleep(0.1)
|
||||
return True
|
||||
@@ -392,9 +399,10 @@ class HuyaWssClient:
|
||||
wup.iTimeout = 0
|
||||
wup.newdata["tReq"] = os.get_bytes()
|
||||
body = self._encode_rpc_body(wup.encode())
|
||||
msg = WssMessage(WssCommand.RPC_REQUEST, SEQ_WSLAUNCH, body)
|
||||
msg = WssMessage(WssCommand.RPC_REQUEST, SEQ_ACTIVITY_WSLAUNCH, body)
|
||||
future = asyncio.Future()
|
||||
self.rpc_queue.append(future)
|
||||
self.logger(format_wss_log(body, WssCommand.RPC_REQUEST, SEQ_ACTIVITY_WSLAUNCH, "发"))
|
||||
await self.ws.send(msg.encode())
|
||||
try:
|
||||
response = await asyncio.wait_for(future, timeout)
|
||||
@@ -402,6 +410,7 @@ class HuyaWssClient:
|
||||
if future in self.rpc_queue:
|
||||
self.rpc_queue.remove(future)
|
||||
return None
|
||||
self.logger(format_wss_log(response, WssCommand.RPC_RESPONSE, SEQ_ACTIVITY_WSLAUNCH, "收"))
|
||||
self._parse_launch_response(response)
|
||||
return response
|
||||
|
||||
@@ -537,13 +546,13 @@ class HuyaWssClient:
|
||||
return body[5 : 5 + wup_len]
|
||||
return body
|
||||
|
||||
async def send_auth(self, cookie: str):
|
||||
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}"
|
||||
msg = WssMessage(
|
||||
command=WssCommand.AUTH,
|
||||
sequence=SEQ_WSLAUNCH,
|
||||
sequence=sequence,
|
||||
body=auth_text.encode("utf-8") + TAIL_BYTES,
|
||||
)
|
||||
await self.ws.send(msg.encode())
|
||||
@@ -551,7 +560,7 @@ class HuyaWssClient:
|
||||
format_wss_log(
|
||||
auth_text.encode("utf-8") + TAIL_BYTES,
|
||||
WssCommand.AUTH,
|
||||
SEQ_WSLAUNCH,
|
||||
sequence,
|
||||
"发",
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user