refactor: 收口跨平台重复业务实现
This commit is contained in:
+122
-133
@@ -286,6 +286,15 @@ class HuyaHttpClient:
|
||||
info.sourceId = source_id
|
||||
return info
|
||||
|
||||
@staticmethod
|
||||
def _build_play_mall_app(source_id: str = "yellowcarlist"):
|
||||
"""构造 PlayMallUI 请求的 PlayMallAppInfo。"""
|
||||
from .shop_structs import PlayMallAppInfo
|
||||
|
||||
info = PlayMallAppInfo()
|
||||
info.sourceId = source_id
|
||||
return info
|
||||
|
||||
@staticmethod
|
||||
def _build_order_env():
|
||||
"""构造下单/支付环境参数。
|
||||
@@ -462,16 +471,17 @@ class HuyaHttpClient:
|
||||
self, uid: int, cookie: str, act_id: int, timeout: float = 15.0
|
||||
):
|
||||
"""读取当前用户任务状态,而不是只读取任务定义。"""
|
||||
from .activity_structs import GetActUserTaskDetailReq, GetActUserTaskDetailResp
|
||||
from .rpc_requests import activity_user_task_detail_request
|
||||
|
||||
req = GetActUserTaskDetailReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.actId = int(act_id or 0)
|
||||
rpc = activity_user_task_detail_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
act_id,
|
||||
)
|
||||
return self.call_rpc(
|
||||
"webActUI",
|
||||
"getActUserTaskDetail",
|
||||
req,
|
||||
GetActUserTaskDetailResp,
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
uid=uid,
|
||||
cookie=cookie,
|
||||
timeout=timeout,
|
||||
@@ -479,16 +489,17 @@ class HuyaHttpClient:
|
||||
|
||||
def query_user_score(self, uid: int, cookie: str, sid: int, timeout: float = 15.0):
|
||||
"""查询活动可用积分。"""
|
||||
from .activity_structs import GetUserScoreReq, GetUserScoreResp
|
||||
from .rpc_requests import activity_score_request
|
||||
|
||||
req = GetUserScoreReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.sid = sid
|
||||
rpc = activity_score_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
sid,
|
||||
)
|
||||
return self.call_rpc(
|
||||
"webActUI",
|
||||
"getUserScore",
|
||||
req,
|
||||
GetUserScoreResp,
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
uid=uid,
|
||||
cookie=cookie,
|
||||
timeout=timeout,
|
||||
@@ -498,16 +509,17 @@ class HuyaHttpClient:
|
||||
self, uid: int, cookie: str, sid: int, timeout: float = 15.0
|
||||
):
|
||||
"""查询用户兑换记录。"""
|
||||
from .activity_structs import GetUserPrizeRecordsReq, GetUserPrizeRecordsResp
|
||||
from .rpc_requests import activity_records_request
|
||||
|
||||
req = GetUserPrizeRecordsReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.sid = sid
|
||||
rpc = activity_records_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
sid,
|
||||
)
|
||||
return self.call_rpc(
|
||||
"webActUI",
|
||||
"getUserPrizeRecords",
|
||||
req,
|
||||
GetUserPrizeRecordsResp,
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
uid=uid,
|
||||
cookie=cookie,
|
||||
timeout=timeout,
|
||||
@@ -517,17 +529,18 @@ class HuyaHttpClient:
|
||||
self, uid: int, cookie: str, sid: int, pid: int, timeout: float = 15.0
|
||||
):
|
||||
"""兑换活动积分商品。"""
|
||||
from .activity_structs import ScoreExchangePrizeReq, ScoreExchangePrizeResp
|
||||
from .rpc_requests import activity_exchange_request
|
||||
|
||||
req = ScoreExchangePrizeReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.sid = int(sid or 0)
|
||||
req.pid = int(pid or 0)
|
||||
rpc = activity_exchange_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
sid,
|
||||
pid,
|
||||
)
|
||||
return self.call_rpc(
|
||||
"webActUI",
|
||||
"scoreExchangePrize",
|
||||
req,
|
||||
ScoreExchangePrizeResp,
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
uid=uid,
|
||||
cookie=cookie,
|
||||
timeout=timeout,
|
||||
@@ -537,17 +550,18 @@ class HuyaHttpClient:
|
||||
self, uid: int, cookie: str, sid: int, pid: int, timeout: float = 15.0
|
||||
):
|
||||
"""查询单个兑换奖品详情和服务端限制。"""
|
||||
from .activity_structs import GetActPrizeDetailReq, GetActPrizeDetailResp
|
||||
from .rpc_requests import activity_prize_detail_request
|
||||
|
||||
req = GetActPrizeDetailReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.sid = int(sid or 0)
|
||||
req.pid = int(pid or 0)
|
||||
rpc = activity_prize_detail_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
sid,
|
||||
pid,
|
||||
)
|
||||
return self.call_rpc(
|
||||
"webActUI",
|
||||
"getActPrizeDetail",
|
||||
req,
|
||||
GetActPrizeDetailResp,
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
uid=uid,
|
||||
cookie=cookie,
|
||||
timeout=timeout,
|
||||
@@ -557,16 +571,17 @@ class HuyaHttpClient:
|
||||
self, uid: int, cookie: str, act_id: int, timeout: float = 15.0
|
||||
):
|
||||
"""查询活动任务详情,用于发现充值商品 SPU。"""
|
||||
from .activity_structs import GetActTaskDetailReq, GetActTaskDetailResp
|
||||
from .rpc_requests import activity_task_detail_request
|
||||
|
||||
req = GetActTaskDetailReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.actId = int(act_id or 0)
|
||||
rpc = activity_task_detail_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
act_id,
|
||||
)
|
||||
return self.call_rpc(
|
||||
"webActUI",
|
||||
"getActTaskDetail",
|
||||
req,
|
||||
GetActTaskDetailResp,
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
uid=uid,
|
||||
cookie=cookie,
|
||||
timeout=timeout,
|
||||
@@ -922,17 +937,24 @@ class HuyaHttpClient:
|
||||
source_id="yellowcarlist",
|
||||
app_scene=SHOP_APP_SCENE,
|
||||
):
|
||||
from .shop_structs import GetGoodsInfoReqV5, GoodsInfoRsp
|
||||
from .rpc_requests import goods_info_request
|
||||
|
||||
req = GetGoodsInfoReqV5()
|
||||
req.userId = self._build_shop_user(uid, cookie)
|
||||
req.shopAppInfo = self._build_shop_app(source_id, app_scene)
|
||||
req.pid = pid
|
||||
req.spuId = spu_id
|
||||
req.skuId = sku_id
|
||||
req.gameId = game_id
|
||||
rpc = goods_info_request(
|
||||
self._build_shop_user(uid, cookie),
|
||||
self._build_shop_app(source_id, app_scene),
|
||||
pid=pid,
|
||||
spu_id=spu_id,
|
||||
sku_id=sku_id,
|
||||
game_id=game_id,
|
||||
)
|
||||
return self.call_rpc(
|
||||
"shopMiddleUI", "getGoodsInfoV5", req, GoodsInfoRsp, uid, guid, cookie
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
uid,
|
||||
guid,
|
||||
cookie,
|
||||
)
|
||||
|
||||
def list_pay_channels(
|
||||
@@ -1156,45 +1178,23 @@ class HuyaHttpClient:
|
||||
2026-11-13 HAR:积分足够时官方只发这一单,不再调用
|
||||
``scoreExchangePrize`` 或 ``payOrderSubmitV5``。
|
||||
"""
|
||||
from .shop_structs import (
|
||||
CreateOrderAccountParam,
|
||||
CreateOrderExtraParam,
|
||||
CreateOrderItemReqV6,
|
||||
CreateOrderPromotionParam,
|
||||
CreateOrderReqV6,
|
||||
CreateOrderRspV6,
|
||||
from .rpc_requests import create_order_v6_request
|
||||
|
||||
rpc = create_order_v6_request(
|
||||
self._build_shop_user(uid, cookie),
|
||||
self._build_shop_app(source_id, SHOP_APP_SCENE),
|
||||
pid=pid,
|
||||
items=items,
|
||||
source_id=source_id,
|
||||
game_id=game_id,
|
||||
biz_params=biz_params,
|
||||
)
|
||||
|
||||
req = CreateOrderReqV6()
|
||||
req.userId = self._build_shop_user(uid, cookie)
|
||||
req.shopAppInfo = self._build_shop_app(source_id, SHOP_APP_SCENE)
|
||||
req.items = []
|
||||
for item in items:
|
||||
row = CreateOrderItemReqV6()
|
||||
row.spuId = str(item.get("spu_id") or "")
|
||||
row.skuId = int(item.get("sku_id") or 0)
|
||||
row.itemCount = int(item.get("item_count") or 1)
|
||||
row.goodsType = int(item.get("goods_type") or 0)
|
||||
row.virtualType = int(item.get("virtual_type") or 0)
|
||||
req.items.append(row)
|
||||
req.pid = int(pid or 0)
|
||||
req.gameId = str(game_id or "0")
|
||||
req.src = 2
|
||||
req.orderType = 6
|
||||
extra = CreateOrderExtraParam()
|
||||
extra.bizParams = biz_params
|
||||
req.extraParam = extra
|
||||
req.sourceId = source_id
|
||||
req.env = self._build_order_env()
|
||||
req.orderScene = 3
|
||||
req.promotionParam = CreateOrderPromotionParam()
|
||||
req.accountParam = CreateOrderAccountParam()
|
||||
|
||||
result: Any = self.call_rpc(
|
||||
"shopMiddleUI",
|
||||
"createOrderV6",
|
||||
req,
|
||||
CreateOrderRspV6,
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
uid,
|
||||
guid,
|
||||
cookie,
|
||||
@@ -1430,25 +1430,21 @@ class HuyaHttpClient:
|
||||
``deep=True`` 时保留 ``tag2[].tag5`` 的原始字节并放宽解码深度,
|
||||
供 :func:`core.huya.shop_structs.parse_points_center_gifts` 解析商品列表。
|
||||
"""
|
||||
from .shop_structs import PlayMallQueryAllocationReq
|
||||
from .rpc_requests import play_mall_allocation_request
|
||||
|
||||
req = PlayMallQueryAllocationReq()
|
||||
req.userId = self._build_shop_user(uid, cookie)
|
||||
req.pageCode = page_code
|
||||
req.appInfo.sourceId = source_id
|
||||
req.appInfo.scene = int(scene or 7)
|
||||
if waterfall_tab_id not in (None, ""):
|
||||
req.blank7 = json.dumps(
|
||||
{"waterfallTabId": str(waterfall_tab_id)},
|
||||
separators=(",", ":"),
|
||||
)
|
||||
req.flag9 = int(page_id or 0)
|
||||
req.flags11 = []
|
||||
rpc = play_mall_allocation_request(
|
||||
self._build_shop_user(uid, cookie),
|
||||
self._build_play_mall_app(source_id),
|
||||
page_code=page_code,
|
||||
scene=scene,
|
||||
page_id=page_id,
|
||||
waterfall_tab_id=waterfall_tab_id,
|
||||
)
|
||||
resp = self.call_rpc(
|
||||
"PlayMallUI",
|
||||
"queryAllocation",
|
||||
req,
|
||||
None,
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
uid,
|
||||
guid,
|
||||
cookie,
|
||||
@@ -1476,29 +1472,22 @@ class HuyaHttpClient:
|
||||
timeout: float = 15.0,
|
||||
):
|
||||
"""PlayMallUI.getMyPromotion(返利/促销查询)。"""
|
||||
from .shop_structs import (
|
||||
PlayMallGetMyPromotionReq,
|
||||
PromotionGoodsKey,
|
||||
shop_spu_number,
|
||||
)
|
||||
from .rpc_requests import play_mall_promotion_request
|
||||
|
||||
spu_num = shop_spu_number(spu_id)
|
||||
req = PlayMallGetMyPromotionReq()
|
||||
req.userId = self._build_shop_user(uid, cookie)
|
||||
req.appInfo.sourceId = 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
|
||||
rpc = play_mall_promotion_request(
|
||||
self._build_shop_user(uid, cookie),
|
||||
self._build_play_mall_app(source_id),
|
||||
spu_id=spu_id,
|
||||
sku_id=sku_id,
|
||||
price=price,
|
||||
supplier_id=supplier_id,
|
||||
game_id=game_id,
|
||||
)
|
||||
resp = self.call_rpc(
|
||||
"PlayMallUI",
|
||||
"getMyPromotion",
|
||||
req,
|
||||
None,
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
uid,
|
||||
guid,
|
||||
cookie,
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
"""HTTP/WSS 共用的虎牙 RPC 请求构造。
|
||||
|
||||
两个传输客户端仍各自处理同步/异步发送与响应解码;这里只保存业务参数到
|
||||
TAF 请求结构体的唯一映射,防止字段默认值在两条链路中发生漂移。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from .activity_structs import (
|
||||
GetActPrizeDetailReq,
|
||||
GetActPrizeDetailResp,
|
||||
GetActTaskDetailReq,
|
||||
GetActTaskDetailResp,
|
||||
GetActUserTaskDetailReq,
|
||||
GetActUserTaskDetailResp,
|
||||
GetUserPrizeRecordsReq,
|
||||
GetUserPrizeRecordsResp,
|
||||
GetUserScoreReq,
|
||||
GetUserScoreResp,
|
||||
ScoreExchangePrizeReq,
|
||||
ScoreExchangePrizeResp,
|
||||
)
|
||||
from .shop_structs import (
|
||||
CreateOrderAccountParam,
|
||||
CreateOrderExtraParam,
|
||||
CreateOrderItemReqV6,
|
||||
CreateOrderPromotionParam,
|
||||
CreateOrderReqV6,
|
||||
CreateOrderRspV6,
|
||||
GetGoodsInfoReqV5,
|
||||
GoodsInfoRsp,
|
||||
PlayMallGetMyPromotionReq,
|
||||
PlayMallQueryAllocationReq,
|
||||
PromotionGoodsKey,
|
||||
shop_spu_number,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RpcRequest:
|
||||
service: str
|
||||
method: str
|
||||
request: Any
|
||||
response_type: Any = None
|
||||
|
||||
|
||||
def activity_score_request(user: Any, sid: int) -> RpcRequest:
|
||||
request = GetUserScoreReq()
|
||||
request.userId = user
|
||||
request.sid = int(sid or 0)
|
||||
return RpcRequest("webActUI", "getUserScore", request, GetUserScoreResp)
|
||||
|
||||
|
||||
def activity_records_request(user: Any, sid: int) -> RpcRequest:
|
||||
request = GetUserPrizeRecordsReq()
|
||||
request.userId = user
|
||||
request.sid = int(sid or 0)
|
||||
return RpcRequest(
|
||||
"webActUI",
|
||||
"getUserPrizeRecords",
|
||||
request,
|
||||
GetUserPrizeRecordsResp,
|
||||
)
|
||||
|
||||
|
||||
def activity_exchange_request(user: Any, sid: int, pid: int) -> RpcRequest:
|
||||
request = ScoreExchangePrizeReq()
|
||||
request.userId = user
|
||||
request.sid = int(sid or 0)
|
||||
request.pid = int(pid or 0)
|
||||
return RpcRequest("webActUI", "scoreExchangePrize", request, ScoreExchangePrizeResp)
|
||||
|
||||
|
||||
def activity_prize_detail_request(user: Any, sid: int, pid: int) -> RpcRequest:
|
||||
request = GetActPrizeDetailReq()
|
||||
request.userId = user
|
||||
request.sid = int(sid or 0)
|
||||
request.pid = int(pid or 0)
|
||||
return RpcRequest(
|
||||
"webActUI",
|
||||
"getActPrizeDetail",
|
||||
request,
|
||||
GetActPrizeDetailResp,
|
||||
)
|
||||
|
||||
|
||||
def activity_task_detail_request(user: Any, act_id: int) -> RpcRequest:
|
||||
request = GetActTaskDetailReq()
|
||||
request.userId = user
|
||||
request.actId = int(act_id or 0)
|
||||
return RpcRequest("webActUI", "getActTaskDetail", request, GetActTaskDetailResp)
|
||||
|
||||
|
||||
def activity_user_task_detail_request(user: Any, act_id: int) -> RpcRequest:
|
||||
request = GetActUserTaskDetailReq()
|
||||
request.userId = user
|
||||
request.actId = int(act_id or 0)
|
||||
return RpcRequest(
|
||||
"webActUI",
|
||||
"getActUserTaskDetail",
|
||||
request,
|
||||
GetActUserTaskDetailResp,
|
||||
)
|
||||
|
||||
|
||||
def goods_info_request(
|
||||
user: Any,
|
||||
shop_app: Any,
|
||||
*,
|
||||
pid: int,
|
||||
spu_id: str,
|
||||
sku_id: int = 0,
|
||||
game_id: str = "",
|
||||
) -> RpcRequest:
|
||||
request = GetGoodsInfoReqV5()
|
||||
request.userId = user
|
||||
request.shopAppInfo = shop_app
|
||||
request.pid = pid
|
||||
request.spuId = spu_id
|
||||
request.skuId = sku_id
|
||||
request.gameId = game_id
|
||||
return RpcRequest("shopMiddleUI", "getGoodsInfoV5", request, GoodsInfoRsp)
|
||||
|
||||
|
||||
def play_mall_allocation_request(
|
||||
user: Any,
|
||||
app_info: Any,
|
||||
*,
|
||||
page_code: str,
|
||||
scene: int,
|
||||
page_id: int = 0,
|
||||
waterfall_tab_id: int | str | None = None,
|
||||
) -> RpcRequest:
|
||||
request = PlayMallQueryAllocationReq()
|
||||
request.userId = user
|
||||
request.appInfo = app_info
|
||||
request.appInfo.scene = int(scene or 0)
|
||||
request.pageCode = page_code
|
||||
if waterfall_tab_id not in (None, ""):
|
||||
request.blank7 = json.dumps(
|
||||
{"waterfallTabId": str(waterfall_tab_id)},
|
||||
separators=(",", ":"),
|
||||
)
|
||||
request.flag9 = int(page_id or 0)
|
||||
request.flags11 = []
|
||||
return RpcRequest("PlayMallUI", "queryAllocation", request)
|
||||
|
||||
|
||||
def play_mall_promotion_request(
|
||||
user: Any,
|
||||
app_info: Any,
|
||||
*,
|
||||
spu_id: str,
|
||||
sku_id: int = 0,
|
||||
price: int = 0,
|
||||
supplier_id: int = 0,
|
||||
game_id: int = 0,
|
||||
) -> RpcRequest:
|
||||
spu_num = shop_spu_number(spu_id)
|
||||
request = PlayMallGetMyPromotionReq()
|
||||
request.userId = user
|
||||
request.appInfo = app_info
|
||||
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
|
||||
request.goods = goods
|
||||
return RpcRequest("PlayMallUI", "getMyPromotion", request)
|
||||
|
||||
|
||||
def create_order_v6_request(
|
||||
user: Any,
|
||||
shop_app: Any,
|
||||
*,
|
||||
pid: int,
|
||||
items: list[dict],
|
||||
source_id: str,
|
||||
game_id: str = "0",
|
||||
biz_params: str,
|
||||
) -> RpcRequest:
|
||||
request = CreateOrderReqV6()
|
||||
request.userId = user
|
||||
request.shopAppInfo = shop_app
|
||||
request.items = []
|
||||
for item in items:
|
||||
row = CreateOrderItemReqV6()
|
||||
row.spuId = str(item.get("spu_id") or "")
|
||||
row.skuId = int(item.get("sku_id") or 0)
|
||||
row.itemCount = int(item.get("item_count") or 1)
|
||||
row.goodsType = int(item.get("goods_type") or 0)
|
||||
row.virtualType = int(item.get("virtual_type") or 0)
|
||||
request.items.append(row)
|
||||
request.pid = int(pid or 0)
|
||||
request.gameId = str(game_id or "0")
|
||||
request.src = 2
|
||||
request.orderType = 6
|
||||
extra = CreateOrderExtraParam()
|
||||
extra.bizParams = biz_params
|
||||
request.extraParam = extra
|
||||
request.sourceId = source_id
|
||||
request.env = {"user_click_seq": "[]"}
|
||||
request.orderScene = 3
|
||||
request.promotionParam = CreateOrderPromotionParam()
|
||||
request.accountParam = CreateOrderAccountParam()
|
||||
return RpcRequest("shopMiddleUI", "createOrderV6", request, CreateOrderRspV6)
|
||||
+121
-111
@@ -16,7 +16,6 @@
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
from collections.abc import Callable
|
||||
@@ -984,18 +983,23 @@ class HuyaWssClient:
|
||||
source_id: str = "yellowcarlist",
|
||||
app_scene: int = SHOP_APP_SCENE,
|
||||
):
|
||||
from .shop_structs import GetGoodsInfoReqV5, GoodsInfoRsp
|
||||
from .rpc_requests import goods_info_request
|
||||
|
||||
req = GetGoodsInfoReqV5()
|
||||
req.userId = self._build_biz_user(uid, cookie)
|
||||
req.shopAppInfo = self._build_shop_app(source_id, app_scene)
|
||||
req.pid = pid
|
||||
req.spuId = spu_id
|
||||
req.skuId = sku_id
|
||||
req.gameId = game_id
|
||||
rpc = goods_info_request(
|
||||
self._build_biz_user(uid, cookie),
|
||||
self._build_shop_app(source_id, app_scene),
|
||||
pid=pid,
|
||||
spu_id=spu_id,
|
||||
sku_id=sku_id,
|
||||
game_id=game_id,
|
||||
)
|
||||
|
||||
return await self.call_rpc(
|
||||
"shopMiddleUI", "getGoodsInfoV5", req, GoodsInfoRsp, timeout=15.0
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
timeout=15.0,
|
||||
)
|
||||
|
||||
async def get_act_info(self, act_id: int):
|
||||
@@ -1006,63 +1010,89 @@ class HuyaWssClient:
|
||||
return await self.call_rpc("webActUI", "getActInfo", req, GetActInfoResp)
|
||||
|
||||
async def get_act_task_detail(self, uid: int, cookie: str, act_id: int):
|
||||
from .activity_structs import GetActTaskDetailReq, GetActTaskDetailResp
|
||||
from .rpc_requests import activity_task_detail_request
|
||||
|
||||
req = GetActTaskDetailReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.actId = int(act_id or 0)
|
||||
rpc = activity_task_detail_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
act_id,
|
||||
)
|
||||
return await self.call_rpc(
|
||||
"webActUI", "getActTaskDetail", req, GetActTaskDetailResp
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
)
|
||||
|
||||
async def get_act_user_task_detail(self, uid: int, cookie: str, act_id: int):
|
||||
from .activity_structs import GetActUserTaskDetailReq, GetActUserTaskDetailResp
|
||||
from .rpc_requests import activity_user_task_detail_request
|
||||
|
||||
req = GetActUserTaskDetailReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.actId = int(act_id or 0)
|
||||
rpc = activity_user_task_detail_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
act_id,
|
||||
)
|
||||
return await self.call_rpc(
|
||||
"webActUI", "getActUserTaskDetail", req, GetActUserTaskDetailResp
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
)
|
||||
|
||||
async def get_user_score(self, uid: int, cookie: str, sid: int):
|
||||
from .activity_structs import GetUserScoreReq, GetUserScoreResp
|
||||
from .rpc_requests import activity_score_request
|
||||
|
||||
req = GetUserScoreReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.sid = int(sid or 0)
|
||||
return await self.call_rpc("webActUI", "getUserScore", req, GetUserScoreResp)
|
||||
rpc = activity_score_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
sid,
|
||||
)
|
||||
return await self.call_rpc(
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
)
|
||||
|
||||
async def get_act_prize_detail(self, uid: int, cookie: str, sid: int, pid: int):
|
||||
from .activity_structs import GetActPrizeDetailReq, GetActPrizeDetailResp
|
||||
from .rpc_requests import activity_prize_detail_request
|
||||
|
||||
req = GetActPrizeDetailReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.sid = int(sid or 0)
|
||||
req.pid = int(pid or 0)
|
||||
rpc = activity_prize_detail_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
sid,
|
||||
pid,
|
||||
)
|
||||
return await self.call_rpc(
|
||||
"webActUI", "getActPrizeDetail", req, GetActPrizeDetailResp
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
)
|
||||
|
||||
async def score_exchange_prize(self, uid: int, cookie: str, sid: int, pid: int):
|
||||
from .activity_structs import ScoreExchangePrizeReq, ScoreExchangePrizeResp
|
||||
from .rpc_requests import activity_exchange_request
|
||||
|
||||
req = ScoreExchangePrizeReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.sid = int(sid or 0)
|
||||
req.pid = int(pid or 0)
|
||||
rpc = activity_exchange_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
sid,
|
||||
pid,
|
||||
)
|
||||
return await self.call_rpc(
|
||||
"webActUI", "scoreExchangePrize", req, ScoreExchangePrizeResp
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
)
|
||||
|
||||
async def get_user_prize_records(self, uid: int, cookie: str, sid: int):
|
||||
from .activity_structs import GetUserPrizeRecordsReq, GetUserPrizeRecordsResp
|
||||
from .rpc_requests import activity_records_request
|
||||
|
||||
req = GetUserPrizeRecordsReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.sid = int(sid or 0)
|
||||
rpc = activity_records_request(
|
||||
self._build_activity_user(uid, cookie),
|
||||
sid,
|
||||
)
|
||||
return await self.call_rpc(
|
||||
"webActUI", "getUserPrizeRecords", req, GetUserPrizeRecordsResp
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
)
|
||||
|
||||
async def check_user_bind_game_account(
|
||||
@@ -1311,44 +1341,22 @@ class HuyaWssClient:
|
||||
biz_params: str = JIFENCENTER_BIZ_PARAMS,
|
||||
):
|
||||
"""积分兑换多商品下单(``shopMiddleUI.createOrderV6``)。"""
|
||||
from .shop_structs import (
|
||||
CreateOrderAccountParam,
|
||||
CreateOrderExtraParam,
|
||||
CreateOrderItemReqV6,
|
||||
CreateOrderPromotionParam,
|
||||
CreateOrderReqV6,
|
||||
CreateOrderRspV6,
|
||||
)
|
||||
from .rpc_requests import create_order_v6_request
|
||||
|
||||
req = CreateOrderReqV6()
|
||||
req.userId = self._build_biz_user(uid, cookie)
|
||||
req.shopAppInfo = self._build_shop_app(source_id, SHOP_APP_SCENE)
|
||||
req.items = []
|
||||
for item in items:
|
||||
row = CreateOrderItemReqV6()
|
||||
row.spuId = str(item.get("spu_id") or "")
|
||||
row.skuId = int(item.get("sku_id") or 0)
|
||||
row.itemCount = int(item.get("item_count") or 1)
|
||||
row.goodsType = int(item.get("goods_type") or 0)
|
||||
row.virtualType = int(item.get("virtual_type") or 0)
|
||||
req.items.append(row)
|
||||
req.pid = int(pid or 0)
|
||||
req.gameId = str(game_id or "0")
|
||||
req.src = 2
|
||||
req.orderType = 6
|
||||
extra = CreateOrderExtraParam()
|
||||
extra.bizParams = biz_params
|
||||
req.extraParam = extra
|
||||
req.sourceId = source_id
|
||||
req.env = self._build_order_env()
|
||||
req.orderScene = 3
|
||||
req.promotionParam = CreateOrderPromotionParam()
|
||||
req.accountParam = CreateOrderAccountParam()
|
||||
rpc = create_order_v6_request(
|
||||
self._build_biz_user(uid, cookie),
|
||||
self._build_shop_app(source_id, SHOP_APP_SCENE),
|
||||
pid=pid,
|
||||
items=items,
|
||||
source_id=source_id,
|
||||
game_id=game_id,
|
||||
biz_params=biz_params,
|
||||
)
|
||||
return await self.call_rpc(
|
||||
"shopMiddleUI",
|
||||
"createOrderV6",
|
||||
req,
|
||||
CreateOrderRspV6,
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
timeout=15.0,
|
||||
)
|
||||
|
||||
@@ -1508,23 +1516,28 @@ class HuyaWssClient:
|
||||
``deep=True`` 时保留 ``tag2[].tag5`` 原始字节并放宽解码深度,
|
||||
供 ``parse_points_center_gifts`` 解析完整商品列表。
|
||||
"""
|
||||
from .shop_structs import PlayMallQueryAllocationReq
|
||||
from .rpc_requests import play_mall_allocation_request
|
||||
|
||||
req = PlayMallQueryAllocationReq()
|
||||
req.userId = self._build_biz_user(uid, cookie)
|
||||
req.appInfo = self._build_play_mall_app(source_id)
|
||||
req.appInfo.scene = int(scene or SHOP_APP_SCENE)
|
||||
req.pageCode = page_code
|
||||
if waterfall_tab_id not in (None, ""):
|
||||
req.blank7 = json.dumps(
|
||||
{"waterfallTabId": str(waterfall_tab_id)},
|
||||
separators=(",", ":"),
|
||||
)
|
||||
req.flag9 = int(page_id or 0)
|
||||
req.flags11 = []
|
||||
rpc = play_mall_allocation_request(
|
||||
self._build_biz_user(uid, cookie),
|
||||
self._build_play_mall_app(source_id),
|
||||
page_code=page_code,
|
||||
scene=scene,
|
||||
page_id=page_id,
|
||||
waterfall_tab_id=waterfall_tab_id,
|
||||
)
|
||||
if not deep:
|
||||
return await self.call_rpc_raw("PlayMallUI", "queryAllocation", req)
|
||||
body = await self.call_rpc("PlayMallUI", "queryAllocation", req, None)
|
||||
return await self.call_rpc_raw(
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
)
|
||||
body = await self.call_rpc(
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
rpc.response_type,
|
||||
)
|
||||
if body is None:
|
||||
return None
|
||||
return self._raw_rsp_from_body(
|
||||
@@ -1546,25 +1559,22 @@ class HuyaWssClient:
|
||||
source_id: str = "yellowcarlist",
|
||||
):
|
||||
"""PlayMallUI.getMyPromotion — 查询用户可用返利/促销。"""
|
||||
from .shop_structs import (
|
||||
PlayMallGetMyPromotionReq,
|
||||
PromotionGoodsKey,
|
||||
shop_spu_number,
|
||||
)
|
||||
from .rpc_requests import play_mall_promotion_request
|
||||
|
||||
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)
|
||||
rpc = play_mall_promotion_request(
|
||||
self._build_biz_user(uid, cookie),
|
||||
self._build_play_mall_app(source_id),
|
||||
spu_id=spu_id,
|
||||
sku_id=sku_id,
|
||||
price=price,
|
||||
supplier_id=supplier_id,
|
||||
game_id=game_id,
|
||||
)
|
||||
return await self.call_rpc_raw(
|
||||
rpc.service,
|
||||
rpc.method,
|
||||
rpc.request,
|
||||
)
|
||||
|
||||
async def get_user_profile(
|
||||
self, uid: int, guid: str, cookie: str, target_uid: int = 0
|
||||
|
||||
Reference in New Issue
Block a user