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,
|
||||
|
||||
Reference in New Issue
Block a user