重构虎牙精英宝典协议与支付状态链路
This commit is contained in:
@@ -28,6 +28,7 @@ PC_UA = (
|
||||
"Chrome/149.0.0.0 Safari/537.36"
|
||||
)
|
||||
HTTP_HUYA_UA = "webh5&0.0.1&websocket&&diypc_52775"
|
||||
SHOP_BIZ_UA = "web&1.0.0&huya"
|
||||
|
||||
|
||||
class WSConnectParaInfo(TafStruct):
|
||||
@@ -200,6 +201,22 @@ class HuyaHttpClient:
|
||||
user.sQIMEI = ""
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
def _build_shop_user(uid: int, cookie: str):
|
||||
"""构造商城业务 UserId;与 9.1 商城 WSS 帧保持一致。"""
|
||||
from .shop_structs import UserId
|
||||
|
||||
user = UserId()
|
||||
user.lUid = int(uid or 0)
|
||||
user.sGuid = ""
|
||||
user.sToken = ""
|
||||
user.sHuYaUA = SHOP_BIZ_UA
|
||||
user.sCookie = HuyaHttpClient._normalize_cookie(cookie)
|
||||
user.iTokenType = 0
|
||||
user.sDeviceInfo = ""
|
||||
user.sQIMEI = ""
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
def _build_shop_app(source_id: str = "yellowcarlist", scene: int = 7):
|
||||
"""构造 HTTP 业务 ShopAppInfo。"""
|
||||
@@ -331,6 +348,32 @@ class HuyaHttpClient:
|
||||
|
||||
# ---------- 业务便捷方法 ----------
|
||||
|
||||
def get_act_info(
|
||||
self, act_id: int, act_uuid: str = "", app_source: str = "", timeout: float = 15.0
|
||||
):
|
||||
"""读取活动主信息,用于驱动当前活动配置。"""
|
||||
from .activity_structs import GetActInfoReq, GetActInfoResp
|
||||
|
||||
req = GetActInfoReq()
|
||||
req.actId = int(act_id or 0)
|
||||
req.actUuid = act_uuid
|
||||
req.appSource = app_source
|
||||
return self.call_rpc("webActUI", "getActInfo", req, GetActInfoResp, timeout=timeout)
|
||||
|
||||
def get_act_user_task_detail(
|
||||
self, uid: int, cookie: str, act_id: int, timeout: float = 15.0
|
||||
):
|
||||
"""读取当前用户任务状态,而不是只读取任务定义。"""
|
||||
from .activity_structs import GetActUserTaskDetailReq, GetActUserTaskDetailResp
|
||||
|
||||
req = GetActUserTaskDetailReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.actId = int(act_id or 0)
|
||||
return self.call_rpc(
|
||||
"webActUI", "getActUserTaskDetail", req, GetActUserTaskDetailResp,
|
||||
uid=uid, cookie=cookie, timeout=timeout,
|
||||
)
|
||||
|
||||
def query_user_score(self, uid: int, cookie: str, sid: int, timeout: float = 15.0):
|
||||
"""查询活动可用积分。"""
|
||||
from .activity_structs import GetUserScoreReq, GetUserScoreResp
|
||||
@@ -406,6 +449,26 @@ class HuyaHttpClient:
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
def get_act_prize_detail(
|
||||
self, uid: int, cookie: str, sid: int, pid: int, timeout: float = 15.0
|
||||
):
|
||||
"""查询单个兑换奖品详情和服务端限制。"""
|
||||
from .activity_structs import GetActPrizeDetailReq, GetActPrizeDetailResp
|
||||
|
||||
req = GetActPrizeDetailReq()
|
||||
req.userId = self._build_activity_user(uid, cookie)
|
||||
req.sid = int(sid or 0)
|
||||
req.pid = int(pid or 0)
|
||||
return self.call_rpc(
|
||||
"webActUI",
|
||||
"getActPrizeDetail",
|
||||
req,
|
||||
GetActPrizeDetailResp,
|
||||
uid=uid,
|
||||
cookie=cookie,
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
def get_act_task_detail(
|
||||
self, uid: int, cookie: str, act_id: int, timeout: float = 15.0
|
||||
):
|
||||
@@ -778,7 +841,7 @@ class HuyaHttpClient:
|
||||
from .shop_structs import GetGoodsInfoReqV5, GoodsInfoRsp
|
||||
|
||||
req = GetGoodsInfoReqV5()
|
||||
req.userId = self._build_user(uid, guid, cookie)
|
||||
req.userId = self._build_shop_user(uid, cookie)
|
||||
req.shopAppInfo = self._build_shop_app(source_id, scene)
|
||||
req.pid = pid
|
||||
req.spuId = spu_id
|
||||
@@ -803,7 +866,7 @@ class HuyaHttpClient:
|
||||
from .shop_structs import QueryUserOrderListReq, QueryUserOrderListRsp
|
||||
|
||||
req = QueryUserOrderListReq()
|
||||
req.userId = self._build_user(uid, guid, cookie)
|
||||
req.userId = self._build_shop_user(uid, cookie)
|
||||
req.offset = int(offset or 0)
|
||||
req.orderType = int(order_type or 1)
|
||||
req.pageSize = int(page_size or 10)
|
||||
@@ -833,6 +896,27 @@ class HuyaHttpClient:
|
||||
)
|
||||
return fallback if fallback is not None else result
|
||||
|
||||
def order_detail(
|
||||
self, uid: int, guid: str, cookie: str, order_id: int, timeout: float = 15.0
|
||||
):
|
||||
"""按订单号查询商城订单详情(最新商城支付链路)。"""
|
||||
from .shop_structs import OrderDetailReq, OrderDetailRsp
|
||||
|
||||
req = OrderDetailReq()
|
||||
req.userId = self._build_shop_user(uid, cookie)
|
||||
req.shopAppInfo = self._build_shop_app("yellowcarlist", 4)
|
||||
req.orderId = int(order_id or 0)
|
||||
return self.call_rpc(
|
||||
"shopMiddleUI",
|
||||
"orderDetailV5",
|
||||
req,
|
||||
OrderDetailRsp,
|
||||
uid,
|
||||
guid,
|
||||
cookie,
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
def create_order(
|
||||
self,
|
||||
uid,
|
||||
@@ -862,7 +946,7 @@ class HuyaHttpClient:
|
||||
last_result = None
|
||||
for ot in types_to_try:
|
||||
req = CreateOrderReqV5()
|
||||
req.userId = self._build_user(uid, guid, cookie)
|
||||
req.userId = self._build_shop_user(uid, cookie)
|
||||
req.shopAppInfo = self._build_shop_app(source_id, scene)
|
||||
req.receiveId = 0
|
||||
req.pid = pid
|
||||
@@ -926,7 +1010,7 @@ class HuyaHttpClient:
|
||||
os = TafOutputStream()
|
||||
os.write_struct_begin(0)
|
||||
|
||||
os.write_struct(0, self._build_user(uid, guid, cookie))
|
||||
os.write_struct(0, self._build_shop_user(uid, cookie))
|
||||
os.write_struct(1, self._build_shop_app(source_id, scene))
|
||||
os.write_int64(2, order_id)
|
||||
os.write_string(3, self._normalize_pay_channel(pay_type))
|
||||
|
||||
Reference in New Issue
Block a user