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
+366 -110
View File
@@ -19,7 +19,6 @@ import asyncio
import random
import re
import struct
import time
from collections import deque
from collections.abc import Callable
from typing import Any, cast
@@ -43,6 +42,35 @@ WSS_BIZ_UA = "web&1.0.0&huya"
WSS_COOKIE_UA = "webh5&0.0.1&websocket&&diypc_52775"
WSS_SHOP_SCENE = 4
# ============================================================
# 积分中心页面上下文(m-shop.huya.com/points.html)
#
# 2026-10-13「开通精英宝典 / 购买幸运币」抓包实证:servant 仍是 shopMiddleUI,
# 但页面 UA / Origin / Referer / 下单参数与 7.4 的 m-shop.yaoguo.com 通道不同:
# - wsLaunch 带真实 lUid + sGuid,UA 为 h5_/points.html
# - 先 VerifyCookie(0x0A) 再 getConfig,最后用 getConfig 的版本 map 回传(0x17)
# - shopAppInfo.scene = 7,而 createOrderV5 的 src/orderScene = 4
# - 下单 extraParam.bizParams 标记积分中心来源,env 只有空 user_click_seq
# ============================================================
POINTS_PAGE_UA = "webh5&0.0.1&websocket&&h5_/points.html"
POINTS_ORIGIN = "https://m-shop.huya.com"
POINTS_REFERER = (
"https://m-shop.huya.com/points.html"
"?pagecode=heping_baodian_credit_center_page&sourceId=yellowcarlist"
)
POINTS_PAGE_CODE = "heping_baodian_credit_center_page"
POINTS_PAY_CALLBACK = "https://m-shop.huya.com/points.html#/consumer/paycallback"
# wsLaunch 响应里的 host 是动态的(launch.queryHttpDns);此为抓包实测值兼兜底。
SHOP_POINTS_WS_HOST = "d35bf373-ws.va.huya.com"
SUPPLIER_ID_YELLOW_CAR = 87401
GAME_CATEGORY_ID_HUYA = 507
ORDER_BIZ_TYPE = 5
SHOP_APP_SCENE = 7
ORDER_SCENE = 4
PEACE_ELITE_GAME_ID = 9815
# createOrderV5 的 extraParam.bizParams:标记「积分中心」来源,缺了会走成普通商城单。
JIFENCENTER_BIZ_PARAMS = '{ "jifencenter": 1 }'
class _ActivityConfigReq(TafStruct):
def __init__(self, user):
@@ -67,6 +95,12 @@ SEQ_CONFIRM = 0x1D000002
SEQ_BUSINESS = 0x1D000106 # 业务 RPC (HAR 7.4 实证:业务帧固定使用该 seq)
SEQ_ACTIVITY_WSLAUNCH = 0x1D000100
SEQ_ACTIVITY_BIZ = 0x1D000109
# 积分中心通道业务帧(2026-10-13 抓包:AUTH/getConfig/业务统一 0x1d000107,
# 仅 createOrderV5 / payOrderSubmitV5 为 0x1d000108)。
SEQ_POINTS_BIZ = 0x1D000107
SEQ_POINTS_ORDER = 0x1D000108
# 积分中心通道里用 0x1d000108 的两帧
POINTS_ORDER_METHODS = frozenset({"createOrderV5", "payOrderSubmitV5"})
class WssCommand:
@@ -118,13 +152,20 @@ class HuyaWssClient:
self._launch_guid = ""
self._launch_ip = ""
self._activity_mode = False
# 积分中心通道:0x10 组播 + wsLaunch(带 uid) + AUTH + getConfig + 版本回传
self._points_mode = False
# getConfig 下发的版本 map,UpdateUserExps(0x17) 必须原样回传
self._config_versions: dict[str, str] = {}
def _next_biz_seq(self) -> int:
def _next_biz_seq(self, order_frame: bool = False) -> int:
"""业务 RPC 的 frame seq。
浏览器在商城 WSS 上连续发送多个业务 RPC 时,frame seq 都保持
0x1d000106;真正区分请求依赖 WUP requestId。
浏览器在商城 WSS 上连续发送多个业务 RPC 时,frame seq 基本保持固定值;
真正区分请求依赖 WUP requestId。积分中心通道里 createOrderV5 /
payOrderSubmitV5 两帧用 0x1d000108,其余用 0x1d000107(抓包实证)。
"""
if self._points_mode:
return SEQ_POINTS_ORDER if order_frame else SEQ_POINTS_BIZ
return SEQ_ACTIVITY_BIZ if self._activity_mode else SEQ_BUSINESS
def _next_wup_req_id(self) -> int:
@@ -231,8 +272,8 @@ class HuyaWssClient:
return user
@staticmethod
def _build_shop_app(source_id: str = "yellowcarlist", scene: int = WSS_SHOP_SCENE):
"""构造 WSS 业务 ShopAppInfo"""
def _build_shop_app(source_id: str = "yellowcarlist", scene: int = SHOP_APP_SCENE):
"""构造 WSS 业务 ShopAppInfo(积分中心抓包 scene 为 7)"""
from .shop_structs import ShopAppInfo
info = ShopAppInfo()
@@ -243,13 +284,37 @@ class HuyaWssClient:
return info
@staticmethod
def _build_order_env(item_count: int = 1):
"""构造下单/支付环境参数"""
click_time = int(time.time() * 1000)
return {
"user_click_seq": f'[{{"x":258,"y":487,"time":{click_time},"id":""}}]',
"input_1": str(item_count),
}
def _build_play_mall_app(source_id: str = "yellowcarlist"):
"""构造 PlayMallUI 系接口的应用信息(字段序与 ShopAppInfo 不同)"""
from .shop_structs import PlayMallAppInfo
info = PlayMallAppInfo()
info.sourceId = source_id
return info
@staticmethod
def _build_order_env():
"""下单/支付环境参数。
2026-10-13 积分中心抓包:仅一个空点击序列,没有 7.4 那版坐标数组与 input_1。
"""
return {"user_click_seq": "[]"}
@staticmethod
def _build_config_user(uid: int, guid: str, cookie: str):
"""getConfig 的 UserId:带真实 uid/guid/cookie,UA 用页面 UA。"""
from .shop_structs import UserId
user = UserId()
user.lUid = int(uid or 0)
user.sGuid = guid or ""
user.sToken = ""
user.sHuYaUA = POINTS_PAGE_UA
user.sCookie = HuyaWssClient._normalize_biz_cookie(cookie)
user.iTokenType = 0
user.sDeviceInfo = ""
user.sQIMEI = ""
return user
async def connect(
self,
@@ -371,17 +436,22 @@ class HuyaWssClient:
await self.ws.send(msg.encode())
async def initialize(self, uid: int, guid: str, cookie: str):
"""商城端点初始化: heartbeat → wsLaunch → getConfig → confirm
"""商城(积分中心)端点初始化,对齐 2026-10-13 抓包帧序。
商城 wsLaunch 无 lUid/sGuid (匿名), tReq:
tag0 lUid=0, tag1 sGuid="", tag2 sUA="webh5&0.0.1&websocket&&h5_/index.html",
tag3 sAppSrc="HUYA&ZH&2052", tag4 tDeviceInfo={5空串}
RegisterGroup(0x10, live:0)
→ launch.wsLaunch(带真实 lUid + sGuid,UA=h5_/points.html)
→ VerifyCookie(0x0A,页面 UA)
→ mobileui.getConfig(带真实 uid/guid/cookie)
→ UpdateUserExps(0x17),回传 getConfig 下发的版本 map
getConfig 之后浏览器还会补发一次 RegisterGroup;业务 RPC 期间用 0x14 心跳维持。
"""
self.logger("[初始化] 开始 WSS 初始化流程 (商城端点)...")
self.logger("[初始化] 开始 WSS 初始化流程 (积分中心端点)...")
self._points_mode = True
await self.send_heartbeat()
launch_rsp = await self.call_ws_launch_shop()
launch_rsp = await self.call_ws_launch_shop(uid, guid)
if launch_rsp is None:
self.logger("[✗] wsLaunch 无响应,初始化失败")
return False
@@ -389,17 +459,20 @@ class HuyaWssClient:
f"[初始化] wsLaunch OK guid={self._launch_guid} ip={self._launch_ip}"
)
config_rsp = await self.call_get_config_shop()
self.logger(
f"[初始化] getConfig {'OK' if config_rsp is not None else '无响应(可继续)'}"
# wsLaunch 为当前连接签发新的 sGuid:AUTH、getConfig 与后续业务必须复用它。
if self._launch_guid:
guid = self._launch_guid
cookie = self._cookie_with_guid(cookie, guid)
await self.send_auth(
uid, cookie, sequence=SEQ_BUSINESS, guid=guid, ua=POINTS_PAGE_UA
)
if self._launch_guid:
await self.send_register(self._launch_guid)
await self.call_get_config_shop(uid=uid, guid=guid, cookie=cookie)
await self.send_confirm()
await self.send_confirm(self._config_versions)
await asyncio.sleep(0.3)
await asyncio.sleep(0.2)
self.logger("[初始化] 完成 ✓")
return True
@@ -488,15 +561,21 @@ class HuyaWssClient:
user.sCookie = HuyaWssClient._normalize_biz_cookie(cookie)
return user
async def call_ws_launch_shop(self, timeout: float = 10.0):
"""商城版 wsLaunch (匿名, 无 lUid/sGuid, 与 conn4 格式一致)"""
ua = "webh5&0.0.1&websocket&&h5_/index.html"
async def call_ws_launch_shop(
self, uid: int = 0, guid: str = "", timeout: float = 10.0
):
"""商城 wsLaunch。
2026-10-13 积分中心抓包:带真实 lUid 与 sGuid(不再是匿名),
UA 为页面 UA(h5_/points.html),与活动通道的字段布局一致。
"""
ua = POINTS_PAGE_UA
app_src = "HUYA&ZH&2052"
os = TafOutputStream()
os.write_struct_begin(0)
os.write_int64(0, 0) # lUid = 0
os.write_string(1, "") # sGuid = ""
os.write_int64(0, int(uid or 0)) # lUid = 真实 uid
os.write_string(1, guid or "") # sGuid = 真实 guid
os.write_string(2, ua) # sUA
os.write_string(3, app_src) # sAppSrc
os.write_struct_begin(4) # tDeviceInfo
@@ -514,7 +593,7 @@ class HuyaWssClient:
wup_data = wup.encode()
body = self._encode_rpc_body(wup_data)
seq = SEQ_WSLAUNCH
seq = SEQ_ACTIVITY_WSLAUNCH
msg = WssMessage(command=WssCommand.RPC_REQUEST, sequence=seq, body=body)
future = asyncio.Future()
self.rpc_queue.append(future)
@@ -611,6 +690,7 @@ class HuyaWssClient:
cookie: str,
sequence: int = SEQ_WSLAUNCH,
guid: str = "",
ua: str = "",
):
"""cmd 0x0a AUTH — 对齐 9.1 抓包(828 活动帧)。
@@ -624,12 +704,14 @@ class HuyaWssClient:
tag5 STRING1 = "HUYA&ZH&2052"
tag6 STRING1 = ""
+= TAIL_BYTES(tag2 ZERO/tag3 ""/tag4 ZERO/tag5 ZERO/tag6 "")
``ua`` 可覆盖:积分中心页面为 ``h5_/points.html``(2026-10-13 抓包)。
"""
os = TafOutputStream()
if self._activity_mode:
if self._activity_mode or self._points_mode:
os.write_head(3, TafType.ZERO)
os.write_int64(0, int(uid or 0))
os.write_string(1, WSS_COOKIE_UA)
os.write_string(1, ua or WSS_COOKIE_UA)
os.write_string(2, HuyaWssClient._normalize_biz_cookie(cookie))
guid_match = re.search(r"(?:^|;\s*)guid=([^;]+)", cookie or "")
auth_guid = (
@@ -657,61 +739,34 @@ class HuyaWssClient:
)
)
async def call_get_config_shop(self, timeout: float = 10.0):
"""商城版 mobileui.getConfig
async def call_get_config_shop(
self, uid: int = 0, guid: str = "", cookie: str = "", timeout: float = 10.0
):
"""商城/积分中心 mobileui.getConfig。
tReq 结构 (HAR 实证):
tag0: UserId {lUid=0, sGuid="", sUA="", sHuYaUA="webh5&0.0.1&websocket&&h5_/index.html",
sToken="", iTokenType=0, sDeviceInfo="", sCookie=""}
tReq 结构 (2026-10-13 抓包实证):
tag0: UserId {lUid=真实uid, sGuid=真实guid, sHuYaUA=h5_/points.html,
sCookie=完整 Cookie}
tag1: 空Map
tag2: "huya" (sAppId)
tag3: 空List
响应 tag1 是版本 map(实测 ``{"58664":"107263"}``),必须缓存下来,
因为 UpdateUserExps(0x17) 要把它原样回传。
"""
ua = "webh5&0.0.1&websocket&&h5_/index.html"
os = TafOutputStream()
os.write_struct_begin(0)
# tag0: UserId (匿名)
os.write_struct_begin(0)
os.write_int64(0, 0) # lUid = 0
os.write_string(1, "") # sGuid
os.write_string(2, "") # sUA
os.write_string(3, ua) # sHuYaUA
os.write_string(4, "") # sToken
os.write_int32(5, 0) # iTokenType
os.write_string(6, "") # sDeviceInfo
os.write_string(7, "") # sCookie
os.write_struct_end()
os.write_map(1, {}) # tag1: 空Map
os.write_string(2, "huya") # tag2: sAppId
os.write_head(3, TafType.LIST) # tag3: 空List
os.write_int32(0, 0)
os.write_struct_end()
wup = WupRequest()
wup.setServant("mobileui")
wup.setFunc("getConfig")
wup.setRequestId(7)
wup.iTimeout = 0
wup.newdata["tReq"] = os.get_bytes()
wup_data = wup.encode()
body = self._encode_rpc_body(wup_data)
seq = SEQ_GETCONFIG
msg = WssMessage(command=WssCommand.RPC_REQUEST, sequence=seq, body=body)
future = asyncio.Future()
self.rpc_queue.append(future)
self.logger(format_wss_log(body, WssCommand.RPC_REQUEST, seq, "发"))
await self.ws.send(msg.encode())
try:
body = await asyncio.wait_for(future, timeout)
except TimeoutError:
if future in self.rpc_queue:
self.rpc_queue.remove(future)
user = self._build_config_user(uid, guid, cookie)
req = _ActivityConfigReq(user)
body = await self.call_rpc("mobileui", "getConfig", req, None, timeout=timeout)
if body is None:
self.logger("[✗] getConfig 超时")
return None
payload = self._decode_rsp_dict(body)
versions = payload.get("tag1")
if isinstance(versions, dict):
self._config_versions = {
str(key): str(value) for key, value in versions.items()
}
self.logger(f"[初始化] getConfig 下发版本 {self._config_versions or '{}'}")
return body
async def send_register(self, guid_from_launch: str):
@@ -738,10 +793,14 @@ class HuyaWssClient:
self.logger(format_wss_log(body, WssCommand.REGISTER, SEQ_REGISTER, "发"))
await self.ws.send(msg.encode())
async def send_confirm(self):
"""cmd 0x17 CONFIRM_SEND — body = 空Map(tag0) + TAIL"""
async def send_confirm(self, version_map: dict[str, str] | None = None):
"""cmd 0x17 UpdateUserExps — body = 版本 map(tag0) + TAIL
2026-10-13 抓包实证:body 是 getConfig 下发的版本 map
(``{"58664":"107263"}``),不是空 map;不回传会导致业务 RPC 无响应。
"""
os = TafOutputStream()
os.write_map(0, {})
os.write_map(0, version_map or {})
body = os.get_bytes() + TAIL_BYTES
msg = WssMessage(
command=WssCommand.CONFIRM_SEND, sequence=SEQ_CONFIRM, body=body
@@ -749,6 +808,62 @@ class HuyaWssClient:
self.logger(format_wss_log(body, WssCommand.CONFIRM_SEND, SEQ_CONFIRM, "发"))
await self.ws.send(msg.encode())
@staticmethod
def _decode_rsp_dict(body: bytes) -> dict:
"""把 RPC 响应的 tRsp 解成通用 dict(未建模的接口用它取字段)。"""
try:
wup_resp = WupResponse()
wup_resp.decode(HuyaWssClient._extract_wup(body))
except Exception: # noqa: BLE001 响应解析失败按空结构处理
return {}
data = wup_resp.newdata.get("tRsp") or wup_resp.newdata.get("tResp")
if not isinstance(data, bytes) or not data:
return {}
ins = TafInputStream(data)
try:
_tag, dtype = ins.peek_head()
if dtype != TafType.STRUCT_BEGIN:
return {}
ins.read_head()
return _decode_taf_struct(ins)
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return {}
@classmethod
def _raw_rsp_from_body(cls, body: bytes):
"""响应 → ShopRawRsp(code/message + 通用解码结构)。"""
from .shop_structs import ShopRawRsp
payload = cls._decode_rsp_dict(body)
code = 0
message = ""
head = payload.get("tag0")
if isinstance(head, int):
# 扁平响应(acceptHyProtocolV5 / createOrderV5 等)
code = int(head)
if isinstance(payload.get("tag1"), str):
message = payload["tag1"]
elif isinstance(head, dict):
# 嵌套响应(PlayMallUI.getMyPromotion 的 tag0.tag0/tag0.tag1)
if isinstance(head.get("tag0"), int):
code = int(head["tag0"])
if isinstance(head.get("tag1"), str):
message = head["tag1"]
return ShopRawRsp(code=code, message=message, payload=payload)
async def call_rpc_raw(
self,
service: str,
method: str,
req_struct: TafStruct,
timeout: float = 15.0,
):
"""未逐字段建模的 RPC:返回 ShopRawRsp,取不到响应时返回 None。"""
body = await self.call_rpc(service, method, req_struct, None, timeout=timeout)
if body is None:
return None
return self._raw_rsp_from_body(body)
async def call_rpc(
self,
service: str,
@@ -757,7 +872,7 @@ class HuyaWssClient:
rsp_class=None,
timeout: float = 10.0,
):
seq = self._next_biz_seq()
seq = self._next_biz_seq(method in POINTS_ORDER_METHODS)
wup = WupRequest()
wup.setServant(service)
@@ -820,13 +935,13 @@ class HuyaWssClient:
sku_id: int = 0,
game_id: str = "",
source_id: str = "yellowcarlist",
scene: int = WSS_SHOP_SCENE,
app_scene: int = SHOP_APP_SCENE,
):
from .shop_structs import GetGoodsInfoReqV5, GoodsInfoRsp
req = GetGoodsInfoReqV5()
req.userId = self._build_biz_user(uid, cookie)
req.shopAppInfo = self._build_shop_app(source_id, scene)
req.shopAppInfo = self._build_shop_app(source_id, app_scene)
req.pid = pid
req.spuId = spu_id
req.skuId = sku_id
@@ -998,14 +1113,16 @@ class HuyaWssClient:
cookie: str,
spu_id: str,
sku_id: int = 0,
supplier_id: int = 87401,
supplier_id: int = SUPPLIER_ID_YELLOW_CAR,
):
from .shop_structs import ListPayChannelReq, ListPayChannelRsp
req = ListPayChannelReq()
req.userId = self._build_biz_user(uid, cookie)
req.shopAppInfo = self._build_shop_app("yellowcarlist", WSS_SHOP_SCENE)
req.shopAppInfo = self._build_shop_app("yellowcarlist", SHOP_APP_SCENE)
req.supplierId = int(supplier_id or 0)
req.bizType = ORDER_BIZ_TYPE
req.gameCategoryId = GAME_CATEGORY_ID_HUYA
req.spuId = spu_id
req.skuId = int(sku_id or 0)
return await self.call_rpc(
@@ -1017,7 +1134,7 @@ class HuyaWssClient:
req = CheckHyProtocolReq()
req.userId = self._build_biz_user(uid, cookie)
req.shopAppInfo = self._build_shop_app("yellowcarlist", WSS_SHOP_SCENE)
req.shopAppInfo = self._build_shop_app("yellowcarlist", SHOP_APP_SCENE)
return await self.call_rpc(
"shopMiddleUI", "checkHyProtocolV5", req, ShopCodeRsp, timeout=15.0
)
@@ -1034,7 +1151,7 @@ class HuyaWssClient:
req = CheckUserBuyAuthReq()
req.userId = self._build_biz_user(uid, cookie)
req.shopAppInfo = self._build_shop_app("yellowcarlist", WSS_SHOP_SCENE)
req.shopAppInfo = self._build_shop_app("yellowcarlist", SHOP_APP_SCENE)
req.spuId = spu_id
req.skuId = int(sku_id or 0)
return await self.call_rpc(
@@ -1075,14 +1192,14 @@ class HuyaWssClient:
cookie: str,
order_id: int,
source_id: str = "yellowcarlist",
scene: int = WSS_SHOP_SCENE,
app_scene: int = SHOP_APP_SCENE,
):
"""按订单号查询商城订单详情,匹配 9.1 支付后轮询。"""
from .shop_structs import OrderDetailReq, OrderDetailRsp
req = OrderDetailReq()
req.userId = self._build_biz_user(uid, cookie)
req.shopAppInfo = self._build_shop_app(source_id, scene)
req.shopAppInfo = self._build_shop_app(source_id, app_scene)
req.orderId = int(order_id or 0)
return await self.call_rpc(
"shopMiddleUI", "orderDetailV5", req, OrderDetailRsp, timeout=15.0
@@ -1099,8 +1216,10 @@ class HuyaWssClient:
item_count: int = 1,
source_id: str = "yellowcarlist",
game_id: str = "",
scene: int = WSS_SHOP_SCENE,
app_scene: int = SHOP_APP_SCENE,
order_scene: int = ORDER_SCENE,
order_type: int = 6,
biz_params: str = JIFENCENTER_BIZ_PARAMS,
):
from .shop_structs import (
CreateOrderAccountParam,
@@ -1112,24 +1231,28 @@ class HuyaWssClient:
req = CreateOrderReqV5()
req.userId = self._build_biz_user(uid, cookie)
req.shopAppInfo = self._build_shop_app(source_id, scene)
req.shopAppInfo = self._build_shop_app(source_id, app_scene)
req.receiveId = 0
req.pid = pid
req.spuId = spu_id
req.skuId = sku_id
req.itemCount = item_count
req.gameId = game_id or "0"
req.src = scene
# 订单侧的 scene 与 shopAppInfo.scene 是两个值(抓包:src/orderScene=4、appInfo=7)
req.src = order_scene
req.scene = 0
req.sourceId = source_id
req.orderType = order_type
req.extraParam = CreateOrderExtraParam()
req.env = self._build_order_env(item_count)
req.orderScene = scene
extra = CreateOrderExtraParam()
# 标记积分中心来源;缺了会走成普通商城单(抓包实证的固定值)。
extra.bizParams = biz_params
req.extraParam = extra
req.env = self._build_order_env()
req.orderScene = order_scene
req.promotionParam = CreateOrderPromotionParam()
req.accountParam = CreateOrderAccountParam()
req.bizType = 5
req.gameCategoryId = 507
req.bizType = ORDER_BIZ_TYPE
req.gameCategoryId = GAME_CATEGORY_ID_HUYA
req.ext = ""
self.logger(f"[下单] orderType={order_type} (HUYA_VIRTUAL)")
@@ -1146,8 +1269,9 @@ class HuyaWssClient:
pay_type: int = 1,
pid: int = 0,
source_id: str = "yellowcarlist",
scene: int = WSS_SHOP_SCENE,
app_scene: int = SHOP_APP_SCENE,
item_count: int = 1,
callback_url: str = "",
):
from .shop_structs import PayOrderRes
@@ -1155,21 +1279,22 @@ class HuyaWssClient:
os.write_struct_begin(0)
os.write_struct(0, self._build_biz_user(uid, cookie))
os.write_struct(1, self._build_shop_app(source_id, scene))
os.write_struct(1, self._build_shop_app(source_id, app_scene))
os.write_int64(2, order_id)
os.write_string(3, "Zfb" if pay_type == 1 else str(pay_type))
os.write_string(4, "QrCode")
callback_url = (
f"https://m-shop.yaoguo.com/index.html#/consumer/paycallback"
f"?orderId={order_id}&pid={pid}&sourceId={source_id}"
# 积分中心抓包的回调指向 m-shop.huya.com/points.html,不是 yaoguo 域名。
call_back = callback_url or (
f"{POINTS_PAY_CALLBACK}?orderId={order_id}&pid={pid}&sourceId={source_id}"
)
os.write_string(5, callback_url)
os.write_map(6, self._build_order_env(item_count))
os.write_string(5, call_back)
os.write_map(6, self._build_order_env())
os.write_string(7, "null")
os.write_string(8, "")
os.write_struct_end()
seq = self._next_biz_seq()
seq = self._next_biz_seq(True)
wup = WupRequest()
wup.setServant("shopMiddleUI")
@@ -1212,3 +1337,134 @@ class HuyaWssClient:
if result is None:
result = wup_resp.readStruct("tResp", PayOrderRes)
return result
# ============================================================
# 积分中心链路新增 RPC(2026-10-13「开通精英宝典 / 购买幸运币」抓包)
# ============================================================
async def get_supplier_info(
self,
uid: int,
guid: str,
cookie: str,
supplier_id: int = SUPPLIER_ID_YELLOW_CAR,
):
"""shopMiddleUI.getSupplierInfoV5 — 供应商(小店)信息。"""
from .shop_structs import GetSupplierInfoReqV5
req = GetSupplierInfoReqV5()
req.userId = self._build_biz_user(uid, cookie)
req.shopAppInfo = self._build_shop_app("yellowcarlist", SHOP_APP_SCENE)
req.supplierId = int(supplier_id or 0)
return await self.call_rpc_raw("shopMiddleUI", "getSupplierInfoV5", req)
async def accept_hy_protocol(self, uid: int, guid: str, cookie: str):
"""shopMiddleUI.acceptHyProtocolV5 — 同意虎牙商城协议(下单前的必做步骤)。"""
from .shop_structs import AcceptHyProtocolReq, ShopCodeRsp
req = AcceptHyProtocolReq()
req.userId = self._build_biz_user(uid, cookie)
req.shopAppInfo = self._build_shop_app("yellowcarlist", SHOP_APP_SCENE)
return await self.call_rpc(
"shopMiddleUI", "acceptHyProtocolV5", req, ShopCodeRsp, timeout=15.0
)
async def calc_order_promotion(
self,
uid: int,
guid: str,
cookie: str,
pid: int,
spu_id: str,
sku_id: int = 0,
item_count: int = 1,
game_id: int = PEACE_ELITE_GAME_ID,
):
"""shopMiddleUI.calcOrderPromotion — 下单前试算价格/返利。"""
from .shop_structs import CalcOrderPromotionReqV5, shop_spu_number
spu_num = shop_spu_number(spu_id)
req = CalcOrderPromotionReqV5()
req.userId = self._build_biz_user(uid, cookie)
req.shopAppInfo = self._build_shop_app("yellowcarlist", SHOP_APP_SCENE)
req.spuNum = spu_num
req.skuId = int(sku_id or 0)
req.itemCount = int(item_count or 1)
req.pid = int(pid or 0)
req.spuNum2 = spu_num
req.gameId = int(game_id or 0)
return await self.call_rpc_raw("shopMiddleUI", "calcOrderPromotion", req)
async def play_mall_query_allocation(
self,
uid: int,
guid: str,
cookie: str,
source_id: str = "yellowcarlist",
page_code: str = POINTS_PAGE_CODE,
):
"""PlayMallUI.queryAllocation — 积分中心页面配额查询。"""
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)
async def play_mall_get_my_promotion(
self,
uid: int,
guid: str,
cookie: str,
spu_id: str,
sku_id: int = 0,
price: int = 0,
supplier_id: int = SUPPLIER_ID_YELLOW_CAR,
game_id: int = PEACE_ELITE_GAME_ID,
source_id: str = "yellowcarlist",
):
"""PlayMallUI.getMyPromotion — 查询用户可用返利/促销。"""
from .shop_structs import (
PlayMallGetMyPromotionReq,
PromotionGoodsKey,
shop_spu_number,
)
spu_num = shop_spu_number(spu_id)
req = PlayMallGetMyPromotionReq()
req.userId = self._build_biz_user(uid, cookie)
req.appInfo = self._build_play_mall_app(source_id)
goods = PromotionGoodsKey()
goods.supplierId = int(supplier_id or 0)
goods.spuNum = spu_num
goods.skuId = int(sku_id or 0)
goods.price = int(price or 0)
goods.gameId = int(game_id or 0)
goods.spuNum2 = spu_num
req.goods = goods
return await self.call_rpc_raw("PlayMallUI", "getMyPromotion", req)
async def get_user_profile(
self, uid: int, guid: str, cookie: str, target_uid: int = 0
):
"""huyauserui.getUserProfile — 单个用户资料(昵称/头像)。
``target_uid`` 省略时查询自己;响应里资料在 ``tag0.tag0``。
"""
from .shop_structs import GetUserProfileReq
req = GetUserProfileReq()
req.userId = self._build_biz_user(uid, cookie)
req.targetUid = int(target_uid or uid or 0)
return await self.call_rpc_raw("huyauserui", "getUserProfile", req)
async def get_follow_wechat_status(self, uid: int, guid: str, cookie: str):
"""wupui.getUserFollowWeChatOfficialStatus — 是否已关注微信公众号。"""
from .shop_structs import FollowWeChatStatusReq
req = FollowWeChatStatusReq()
req.userId = self._build_biz_user(uid, cookie)
return await self.call_rpc_raw(
"wupui", "getUserFollowWeChatOfficialStatus", req
)