feat(huya): 对齐积分中心开通链路(2026-10-13 抓包)
按 10.13「开通精英宝典/购买幸运币」抓包(m-shop.huya.com/points.html)对齐商城链路: - WSS host 改为 launch.queryHttpDns 动态解析(失败回退抓包实测 host);握手 baseinfo 只带 uid/guid/页面 UA/exp,Origin 与页面同源 - wsLaunch 改为带真实 lUid/sGuid;初始化补上 AUTH(0x0A) → getConfig → UpdateUserExps(0x17),并把 getConfig 下发的版本 map 原样回传(不回传则业务 RPC 无响应) - 补齐新 RPC:getSupplierInfoV5 / acceptHyProtocolV5 / calcOrderPromotion / PlayMallUI.getMyPromotion|queryAllocation / wupui.* / huyauserui.getUserProfile - 下单参数对齐:shopAppInfo.scene=7 与订单 src/orderScene=4 分离、orderType=6、 bizType=5、gameCategoryId=507、extraParam.bizParams 标记 jifencenter、env 仅空点击 序列、支付回调指向 m-shop.huya.com/points.html - 开通链路抽到 services/huya_shop_flow.py,充值任务改为调用它 验证:新增 tests/test_huya_points_shop_protocol.py 与抓包逐字节比对(心跳、版本回传、 wsLaunch/getConfig/下单/支付帧与新 RPC 参数,共 10 条);按 AGENTS.md 做了反向验证 (把 jifencenter 改成 0 后该用例变红,还原后恢复)。ruff format --check 与全量 pytest 通过。
This commit is contained in:
@@ -11,9 +11,19 @@ import urllib.parse
|
||||
from collections.abc import Callable
|
||||
from typing import Literal
|
||||
|
||||
from .http_client import HuyaHttpClient, generate_http_baseinfo
|
||||
from .http_client import (
|
||||
HuyaHttpClient,
|
||||
generate_http_baseinfo,
|
||||
generate_ws_baseinfo,
|
||||
resolve_wss_host,
|
||||
)
|
||||
from .web_cookie_fields import missing_web_cookie_fields
|
||||
from .wss_client import ACTIVITY_WS_HOST, SHOP_BASEINFO, SHOP_WS_HOST, HuyaWssClient
|
||||
from .wss_client import (
|
||||
ACTIVITY_WS_HOST,
|
||||
POINTS_ORIGIN,
|
||||
POINTS_PAGE_UA,
|
||||
HuyaWssClient,
|
||||
)
|
||||
|
||||
|
||||
class HuyaEliteWssSession:
|
||||
@@ -35,7 +45,8 @@ class HuyaEliteWssSession:
|
||||
self.logger = logger or (lambda _message: None)
|
||||
self.http = HuyaHttpClient(logger=self.logger)
|
||||
self.loop = asyncio.new_event_loop()
|
||||
self.client: HuyaWssClient | None = None
|
||||
# 构造期必定赋值;提前声明为具体类型,避免每个透传方法都被判定为可选成员。
|
||||
self.client: HuyaWssClient
|
||||
self._closed = False
|
||||
|
||||
if kind == "activity":
|
||||
@@ -45,9 +56,15 @@ class HuyaEliteWssSession:
|
||||
connect_host = host or ACTIVITY_WS_HOST
|
||||
origin = "https://zt.huya.com"
|
||||
else:
|
||||
baseinfo = SHOP_BASEINFO
|
||||
connect_host = host or SHOP_WS_HOST
|
||||
origin = "https://m-shop.yaoguo.com"
|
||||
# 积分中心通道(2026-10-13 抓包对齐):
|
||||
# - host 由 launch.queryHttpDns 动态解析(失败回退抓包实测 host)
|
||||
# - 握手 baseinfo 带真实 uid/guid + h5_/points.html UA,cookie/trace 为空
|
||||
# - Origin 与页面同源(m-shop.huya.com)
|
||||
baseinfo = generate_ws_baseinfo(self.uid, self.guid, POINTS_PAGE_UA)
|
||||
connect_host = host or resolve_wss_host(
|
||||
self.uid, self.cookie, self.guid, self.logger
|
||||
)
|
||||
origin = POINTS_ORIGIN
|
||||
|
||||
self.client = HuyaWssClient(baseinfo=baseinfo, logger=self.logger)
|
||||
try:
|
||||
@@ -92,11 +109,11 @@ class HuyaEliteWssSession:
|
||||
initialized = self.loop.run_until_complete(
|
||||
self.client.initialize_activity(self.uid, self.guid, self.cookie)
|
||||
if kind == "activity"
|
||||
else self.client.initialize(self.uid, "", self.cookie)
|
||||
else self.client.initialize(self.uid, self.guid, self.cookie)
|
||||
)
|
||||
if not initialized:
|
||||
raise RuntimeError(f"虎牙 {kind} WSS 初始化失败")
|
||||
if kind == "activity" and self.client._launch_guid:
|
||||
if self.client._launch_guid:
|
||||
# wsLaunch 的 sGuid 是当前连接的真实会话值,供后续业务 Cookie
|
||||
# 与 HTTP baseinfo 继续复用,避免沿用登录时的旧 guid。
|
||||
self.cookie = self.client._cookie_with_guid(
|
||||
@@ -233,5 +250,28 @@ class HuyaEliteWssSession:
|
||||
def query_user_order_list(self, **kwargs):
|
||||
return self._run(self.client.query_user_order_list(**kwargs))
|
||||
|
||||
# ---- 积分中心链路新增 RPC(2026-10-13 抓包) ----
|
||||
|
||||
def get_supplier_info(self, **kwargs):
|
||||
return self._run(self.client.get_supplier_info(**kwargs))
|
||||
|
||||
def accept_hy_protocol(self, **kwargs):
|
||||
return self._run(self.client.accept_hy_protocol(**kwargs))
|
||||
|
||||
def calc_order_promotion(self, **kwargs):
|
||||
return self._run(self.client.calc_order_promotion(**kwargs))
|
||||
|
||||
def play_mall_query_allocation(self, **kwargs):
|
||||
return self._run(self.client.play_mall_query_allocation(**kwargs))
|
||||
|
||||
def play_mall_get_my_promotion(self, **kwargs):
|
||||
return self._run(self.client.play_mall_get_my_promotion(**kwargs))
|
||||
|
||||
def get_user_profile(self, **kwargs):
|
||||
return self._run(self.client.get_user_profile(**kwargs))
|
||||
|
||||
def get_follow_wechat_status(self, **kwargs):
|
||||
return self._run(self.client.get_follow_wechat_status(**kwargs))
|
||||
|
||||
|
||||
__all__ = ["HuyaEliteWssSession"]
|
||||
|
||||
Reference in New Issue
Block a user