refactor: 收口跨平台重复业务实现
This commit is contained in:
+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