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:
yml2213
2026-10-15 14:56:30 +08:00
parent ec07e4fc06
commit f540dcfc29
7 changed files with 1535 additions and 253 deletions
+292
View File
@@ -5,6 +5,8 @@
来源:m-shop.yaoguo.com 的 jce/ShopFacade.js、api/orderui.ts、api/mall/PlayMallNewHome.ts
"""
from typing import Any
from .taf_protocol import TafInputStream, TafOutputStream, TafStruct, TafType
@@ -1094,3 +1096,293 @@ class PayOrderRes(TafStruct):
"pay_url": self.payUrl,
"amount": self.amount,
}
# ============================================================
# 积分中心(m-shop.huya.com/points.html)新增 RPC
#
# 来源:2026-10-13「开通精英宝典 / 购买幸运币」WSS 抓包逐字段解出。
# 浏览器实际链路顺序:
# getGoodsInfoV5 → getSupplierInfoV5 → listPayChannelV5 → checkHyProtocolV5
# → acceptHyProtocolV5 → calcOrderPromotion → checkUserBuyAuth
# → createOrderV5 → payOrderSubmitV5 → orderDetailV5(轮询)
# 这些接口的响应层次较深且随商品变化,统一用 ShopRawRsp 暴露通用解码结果,
# 不凭空猜测未确认的字段名。
# ============================================================
class ShopRawRsp:
"""未逐字段建模的商城响应:暴露 code/message 与通用解码后的原始结构。"""
def __init__(self, code: int = 0, message: str = "", payload: dict | None = None):
self.code = code
self.message = message
self.payload = payload or {}
def value(self, *path):
"""按通用解码的 tag 路径取值,例如 value("tag2", "tag0", "tag1")。"""
node: Any = self.payload
for key in path:
if not isinstance(node, dict):
return None
node = node.get(key)
return node
def to_dict(self) -> dict:
return {"code": self.code, "message": self.message, "payload": self.payload}
class PlayMallAppInfo(TafStruct):
"""PlayMallUI 系接口的应用信息。
与 ShopAppInfo 字段不同(抓包实证):
tag0 sAppId, tag1 渠道号(1001), tag2 0, tag3 "", tag5 scene(7),
tag6 sourceId, tag7 ""
"""
def __init__(self):
self.sAppId: str = "huya" # tag 0
self.channelId: int = 1001 # tag 1 抓包固定 1001
self.flag2: int = 0 # tag 2 抓包固定 0
self.blank3: str = "" # tag 3 抓包为空串
self.scene: int = 7 # tag 5 抓包固定 7
self.sourceId: str = "yellowcarlist" # tag 6
self.blank7: str = "" # tag 7 抓包为空串
def write_to(self, os: TafOutputStream):
os.write_string(0, self.sAppId)
os.write_int32(1, self.channelId)
os.write_int32(2, self.flag2)
os.write_string(3, self.blank3)
os.write_int32(5, self.scene)
os.write_string(6, self.sourceId)
os.write_string(7, self.blank7)
def read_from(self, ins: TafInputStream):
pass
class GetSupplierInfoReqV5(ShopAppRequest):
"""shopMiddleUI.getSupplierInfoV5 请求。"""
def __init__(self):
super().__init__()
self.supplierId: int = 0 # tag 2
def write_to(self, os: TafOutputStream):
os.write_struct(0, self.userId)
os.write_struct(1, self.shopAppInfo)
os.write_int64(2, self.supplierId)
class AcceptHyProtocolReq(ShopAppRequest):
"""shopMiddleUI.acceptHyProtocolV5 请求(同意虎牙商城协议)。"""
def __init__(self):
super().__init__()
self.protocolVersion: int = 1 # tag 2 抓包固定 1
def write_to(self, os: TafOutputStream):
os.write_struct(0, self.userId)
os.write_struct(1, self.shopAppInfo)
os.write_int32(2, self.protocolVersion)
class CalcOrderPromotionExtra(TafStruct):
"""calcOrderPromotion tag12 子结构(抓包全零/空)。"""
def __init__(self):
self.flag0: int = 0 # tag 0
self.flag1: int = 0 # tag 1
self.flag2: int = 0 # tag 2
self.ids: list = [] # tag 3
def write_to(self, os: TafOutputStream):
os.write_int32(0, self.flag0)
os.write_int32(1, self.flag1)
os.write_int32(2, self.flag2)
os.write_list(3, self.ids)
def read_from(self, ins: TafInputStream):
pass
class CalcOrderPromotionReqV5(ShopAppRequest):
"""shopMiddleUI.calcOrderPromotion 请求。
tag7/tag8/tag9/tag10 在抓包中恒为 1/1/1/0,语义未确认,按抓包原值写出。
tag2 与 tag14 都是 spuId 去掉 ``hy-`` 前缀后的数字。
"""
def __init__(self):
super().__init__()
self.spuNum: int = 0 # tag 2
self.skuId: int = 0 # tag 3
self.itemCount: int = 1 # tag 4
self.pid: int = 0 # tag 5
self.couponUserIds: list = [] # tag 6
self.flag7: int = 1 # tag 7 抓包固定 1
self.flag8: int = 1 # tag 8 抓包固定 1
self.flag9: int = 1 # tag 9 抓包固定 1
self.flag10: int = 0 # tag 10 抓包固定 0
self.extra: CalcOrderPromotionExtra | None = None # tag 12
self.flag13: int = 0 # tag 13
self.spuNum2: int = 0 # tag 14 与 tag2 同值
self.gameId: int = 0 # tag 15 游戏 ID(和平精英 9815)
self.list16: list = [] # tag 16
def write_to(self, os: TafOutputStream):
os.write_struct(0, self.userId)
os.write_struct(1, self.shopAppInfo)
os.write_int64(2, self.spuNum)
os.write_int64(3, self.skuId)
os.write_int32(4, self.itemCount)
os.write_int64(5, self.pid)
os.write_list(6, self.couponUserIds)
os.write_int32(7, self.flag7)
os.write_int32(8, self.flag8)
os.write_int32(9, self.flag9)
os.write_int32(10, self.flag10)
os.write_struct(12, self.extra or CalcOrderPromotionExtra())
os.write_int32(13, self.flag13)
os.write_int64(14, self.spuNum2)
os.write_int64(15, self.gameId)
os.write_list(16, self.list16)
def read_from(self, ins: TafInputStream):
pass
class PlayMallQueryAllocationReq(TafStruct):
"""PlayMallUI.queryAllocation 请求(积分中心页面配额查询)。"""
def __init__(self):
self.userId = UserId() # tag 0
self.appInfo = PlayMallAppInfo() # tag 1
self.pageCode: str = "" # tag 2
self.blank3: str = "" # tag 3
self.flag4: int = 0 # tag 4
self.flag5: int = 1 # tag 5 抓包固定 1
self.flag6: int = 24 # tag 6 抓包固定 24
self.blank7: str = "" # tag 7
self.data8: bytes = b"" # tag 8 空字节数组
self.flag9: int = 0 # tag 9
self.flag10: int = 0 # tag 10
self.flags11: list[int] = [6, 19] # tag 11 抓包固定 [6, 19]
self.flag12: int = 0 # tag 12
def write_to(self, os: TafOutputStream):
os.write_struct(0, self.userId)
os.write_struct(1, self.appInfo)
os.write_string(2, self.pageCode)
os.write_string(3, self.blank3)
os.write_int32(4, self.flag4)
os.write_int32(5, self.flag5)
os.write_int32(6, self.flag6)
os.write_string(7, self.blank7)
os.write_bytes(8, self.data8)
os.write_int32(9, self.flag9)
os.write_int32(10, self.flag10)
os.write_list(11, self.flags11)
os.write_int32(12, self.flag12)
def read_from(self, ins: TafInputStream):
pass
class PromotionGoodsKey(TafStruct):
"""getMyPromotion tag6 子结构(供应商 + 商品 + 价格)。"""
def __init__(self):
self.supplierId: int = 0 # tag 0
self.spuNum: int = 0 # tag 1
self.skuId: int = 0 # tag 2
self.price: int = 0 # tag 3
self.flag4: int = 1 # tag 4 抓包固定 1
self.list5: list = [] # tag 5
self.gameId: int = 0 # tag 6
self.spuNum2: int = 0 # tag 7 与 tag1 同值
def write_to(self, os: TafOutputStream):
os.write_int64(0, self.supplierId)
os.write_int64(1, self.spuNum)
os.write_int64(2, self.skuId)
os.write_int64(3, self.price)
os.write_int32(4, self.flag4)
os.write_list(5, self.list5)
os.write_int64(6, self.gameId)
os.write_int64(7, self.spuNum2)
def read_from(self, ins: TafInputStream):
pass
class PlayMallGetMyPromotionReq(TafStruct):
"""PlayMallUI.getMyPromotion 请求(查询用户可用返利/促销)。"""
def __init__(self):
self.userId = UserId() # tag 0
self.appInfo = PlayMallAppInfo() # tag 1
self.flag2: int = 1 # tag 2 抓包固定 1
self.flag3: int = 1 # tag 3 抓包固定 1
self.flag4: int = 10 # tag 4 抓包固定 10
self.flag5: int = 0 # tag 5
self.goods: PromotionGoodsKey | None = None # tag 6
self.list7: list = [] # tag 7
self.scene: str = "shop" # tag 8 抓包固定 "shop"
self.blank9: str = "" # tag 9
self.list10: list = [] # tag 10
def write_to(self, os: TafOutputStream):
os.write_struct(0, self.userId)
os.write_struct(1, self.appInfo)
os.write_int32(2, self.flag2)
os.write_int32(3, self.flag3)
os.write_int32(4, self.flag4)
os.write_int32(5, self.flag5)
os.write_struct(6, self.goods or PromotionGoodsKey())
os.write_list(7, self.list7)
os.write_string(8, self.scene)
os.write_string(9, self.blank9)
os.write_list(10, self.list10)
def read_from(self, ins: TafInputStream):
pass
class GetUserProfileReq(TafStruct):
"""huyauserui.getUserProfile 请求(tag1 为要查询的 uid)。"""
def __init__(self):
self.userId = UserId() # tag 0
self.targetUid: int = 0 # tag 1
def write_to(self, os: TafOutputStream):
os.write_struct(0, self.userId)
os.write_int64(1, self.targetUid)
def read_from(self, ins: TafInputStream):
pass
class FollowWeChatStatusReq(TafStruct):
"""wupui.getUserFollowWeChatOfficialStatus 请求(tag1 抓包固定 1)。"""
def __init__(self):
self.userId = UserId() # tag 0
self.flag1: int = 1 # tag 1 抓包固定 1
def write_to(self, os: TafOutputStream):
os.write_struct(0, self.userId)
os.write_int32(1, self.flag1)
def read_from(self, ins: TafInputStream):
pass
def shop_spu_number(spu_id: str) -> int:
"""把商品 ID(``hy-8328015``)转成接口需要的数字形式(``8328015``)。"""
text = str(spu_id or "").strip()
if "-" in text:
text = text.rsplit("-", 1)[-1]
return int(text) if text.isdigit() else 0