feat: 重做协作台账状态机并支持充值核账

This commit is contained in:
yml2213
2026-10-19 16:06:02 +08:00
parent 781b27e63a
commit 3a6649a054
15 changed files with 2330 additions and 363 deletions
+46 -6
View File
@@ -817,7 +817,12 @@ class HuyaWssClient:
await self.ws.send(msg.encode())
@staticmethod
def _decode_rsp_dict(body: bytes) -> dict:
def _decode_rsp_dict(
body: bytes,
*,
max_depth: int = 5,
keep_bytes: bool = False,
) -> dict:
"""把 RPC 响应的 tRsp 解成通用 dict(未建模的接口用它取字段)。"""
try:
wup_resp = WupResponse()
@@ -825,14 +830,34 @@ class HuyaWssClient:
except Exception: # noqa: BLE001 响应解析失败按空结构处理
return {}
data = wup_resp.newdata.get("tRsp") or wup_resp.newdata.get("tResp")
return decode_struct_bytes(data) if isinstance(data, bytes) else {}
return (
decode_struct_bytes(
data,
max_depth=max_depth,
keep_bytes=keep_bytes,
)
if isinstance(data, bytes)
else {}
)
@classmethod
def _raw_rsp_from_body(cls, body: bytes):
def _raw_rsp_from_body(
cls,
body: bytes,
*,
max_depth: int = 5,
keep_bytes: bool = False,
):
"""响应 → ShopRawRsp(code/message + 通用解码结构)。"""
from .shop_structs import ShopRawRsp
return ShopRawRsp.from_payload(cls._decode_rsp_dict(body))
return ShopRawRsp.from_payload(
cls._decode_rsp_dict(
body,
max_depth=max_depth,
keep_bytes=keep_bytes,
)
)
async def call_rpc_raw(
self,
@@ -1385,15 +1410,30 @@ class HuyaWssClient:
cookie: str,
source_id: str = "yellowcarlist",
page_code: str = POINTS_PAGE_CODE,
*,
deep: bool = False,
):
"""PlayMallUI.queryAllocation — 积分中心页面配额查询。"""
"""PlayMallUI.queryAllocation — 积分中心页面配额查询。
``deep=True`` 时保留 ``tag2[].tag5`` 原始字节并放宽解码深度,
供 ``parse_points_center_gifts`` 解析完整商品列表。
"""
from .shop_structs import PlayMallQueryAllocationReq
req = PlayMallQueryAllocationReq()
req.userId = self._build_biz_user(uid, cookie)
req.appInfo = self._build_play_mall_app(source_id)
req.pageCode = page_code
return await self.call_rpc_raw("PlayMallUI", "queryAllocation", req)
if not deep:
return await self.call_rpc_raw("PlayMallUI", "queryAllocation", req)
body = await self.call_rpc("PlayMallUI", "queryAllocation", req, None)
if body is None:
return None
return self._raw_rsp_from_body(
body,
max_depth=40,
keep_bytes=True,
)
async def play_mall_get_my_promotion(
self,