实现虎牙充值商品列表与支付二维码
This commit is contained in:
@@ -120,6 +120,200 @@ class GetActPrizeListReq(TafStruct):
|
||||
self.sid = ins.read_int32(1, default=self.sid)
|
||||
|
||||
|
||||
class GetActTaskDetailReq(TafStruct):
|
||||
"""webActUI.getActTaskDetail 请求。"""
|
||||
|
||||
def __init__(self):
|
||||
self.userId = ActivityUserId()
|
||||
self.actId: int = 0
|
||||
|
||||
def write_to(self, os: TafOutputStream):
|
||||
os.write_struct(0, self.userId)
|
||||
os.write_int32(1, self.actId)
|
||||
|
||||
def read_from(self, ins: TafInputStream):
|
||||
self.userId = ins.read_struct(0, ActivityUserId) or self.userId
|
||||
self.actId = ins.read_int32(1, default=self.actId)
|
||||
|
||||
|
||||
class ActTaskPrizeInfo(TafStruct):
|
||||
"""活动任务奖励项,刷新充值商品时只取展示需要字段。"""
|
||||
|
||||
def __init__(self):
|
||||
self.actId: int = 0
|
||||
self.taskId: int = 0
|
||||
self.prizeId: int = 0
|
||||
self.name: str = ""
|
||||
self.count: int = 0
|
||||
self.percentText: str = ""
|
||||
self.extra: dict = {}
|
||||
|
||||
def read_from(self, ins: TafInputStream):
|
||||
self.actId = ins.read_int64(0, default=self.actId)
|
||||
self.taskId = ins.read_int64(1, default=self.taskId)
|
||||
self.prizeId = ins.read_int64(2, default=self.prizeId)
|
||||
self.name = ins.read_string(3, default=self.name)
|
||||
self.count = ins.read_int64(4, default=self.count)
|
||||
self.percentText = ins.read_string(9, default=self.percentText)
|
||||
self.extra = ins.read_map(12)
|
||||
while True:
|
||||
pos = ins.buf.tell()
|
||||
tag, dtype = ins.read_head()
|
||||
if dtype == TafType.STRUCT_END:
|
||||
ins.buf.seek(pos)
|
||||
return
|
||||
ins.skip_field(dtype)
|
||||
|
||||
def write_to(self, os: TafOutputStream):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def read_list_item(ins: TafInputStream, _tag: int):
|
||||
item = ActTaskPrizeInfo()
|
||||
item.read_from(ins)
|
||||
_end_tag, dtype = ins.read_head()
|
||||
if dtype != TafType.STRUCT_END:
|
||||
raise ValueError(f"期望任务奖励 STRUCT_END,实际 0x{dtype:02x}")
|
||||
return item
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"act_id": self.actId,
|
||||
"task_id": self.taskId,
|
||||
"prize_id": self.prizeId,
|
||||
"name": self.name,
|
||||
"count": self.count,
|
||||
"percent_text": self.percentText,
|
||||
"extra": dict(self.extra),
|
||||
}
|
||||
|
||||
|
||||
class ActTaskDetailItem(TafStruct):
|
||||
"""活动任务项,字段位置来自 getActTaskDetail 实测响应。"""
|
||||
|
||||
def __init__(self):
|
||||
self.actId: int = 0
|
||||
self.taskId: int = 0
|
||||
self.name: str = ""
|
||||
self.taskStatus: int = 0
|
||||
self.taskType: int = 0
|
||||
self.limitType: int = 0
|
||||
self.taskParams: str = ""
|
||||
self.targetValue: str = ""
|
||||
self.icon: str = ""
|
||||
self.description: str = ""
|
||||
self.prizes: list[ActTaskPrizeInfo] = []
|
||||
self.taskUrl: str = ""
|
||||
self.startTime: str = ""
|
||||
self.endTime: str = ""
|
||||
|
||||
@staticmethod
|
||||
def _extract_spu_id(text: str) -> str:
|
||||
import urllib.parse
|
||||
|
||||
raw = str(text or "")
|
||||
if not raw:
|
||||
return ""
|
||||
query = raw
|
||||
if "?" in raw:
|
||||
query = raw.split("?", 1)[1]
|
||||
if "#" in query and "?" in query.split("#", 1)[1]:
|
||||
query = query.split("#", 1)[1].split("?", 1)[1]
|
||||
params = urllib.parse.parse_qs(query, keep_blank_values=True)
|
||||
for key in ("spuId", "spu_id"):
|
||||
value = params.get(key)
|
||||
if value and value[0]:
|
||||
return value[0]
|
||||
for part in raw.replace("#", "&").split("&"):
|
||||
if part.startswith("spuId="):
|
||||
return urllib.parse.unquote(part.split("=", 1)[1])
|
||||
return ""
|
||||
|
||||
def read_from(self, ins: TafInputStream):
|
||||
self.actId = ins.read_int64(0, default=self.actId)
|
||||
self.taskId = ins.read_int64(1, default=self.taskId)
|
||||
self.name = ins.read_string(2, default=self.name)
|
||||
self.taskStatus = ins.read_int32(3, default=self.taskStatus)
|
||||
self.taskType = ins.read_int32(4, default=self.taskType)
|
||||
self.limitType = ins.read_int32(5, default=self.limitType)
|
||||
self.taskParams = ins.read_string(6, default=self.taskParams)
|
||||
self.targetValue = ins.read_string(7, default=self.targetValue)
|
||||
self.icon = ins.read_string(8, default=self.icon)
|
||||
self.description = ins.read_string(9, default=self.description)
|
||||
self.prizes = ins.read_list(11, item_reader=ActTaskPrizeInfo.read_list_item)
|
||||
self.taskUrl = ins.read_string(12, default=self.taskUrl)
|
||||
self.startTime = ins.read_string(25, default=self.startTime)
|
||||
self.endTime = ins.read_string(26, default=self.endTime)
|
||||
while True:
|
||||
pos = ins.buf.tell()
|
||||
tag, dtype = ins.read_head()
|
||||
if dtype == TafType.STRUCT_END:
|
||||
ins.buf.seek(pos)
|
||||
return
|
||||
ins.skip_field(dtype)
|
||||
|
||||
def write_to(self, os: TafOutputStream):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def read_list_item(ins: TafInputStream, _tag: int):
|
||||
item = ActTaskDetailItem()
|
||||
item.read_from(ins)
|
||||
_end_tag, dtype = ins.read_head()
|
||||
if dtype != TafType.STRUCT_END:
|
||||
raise ValueError(f"期望任务 STRUCT_END,实际 0x{dtype:02x}")
|
||||
return item
|
||||
|
||||
@property
|
||||
def spu_id(self) -> str:
|
||||
return self._extract_spu_id(self.taskUrl) or self._extract_spu_id(self.taskParams)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"act_id": self.actId,
|
||||
"task_id": self.taskId,
|
||||
"name": self.name,
|
||||
"task_status": self.taskStatus,
|
||||
"task_type": self.taskType,
|
||||
"limit_type": self.limitType,
|
||||
"task_params": self.taskParams,
|
||||
"target_value": self.targetValue,
|
||||
"icon": self.icon,
|
||||
"description": self.description,
|
||||
"task_url": self.taskUrl,
|
||||
"spu_id": self.spu_id,
|
||||
"start_time": self.startTime,
|
||||
"end_time": self.endTime,
|
||||
"prizes": [item.to_dict() for item in self.prizes],
|
||||
}
|
||||
|
||||
|
||||
class GetActTaskDetailResp(TafStruct):
|
||||
"""webActUI.getActTaskDetail 响应。"""
|
||||
|
||||
def __init__(self):
|
||||
self.status: int = 0
|
||||
self.msg: str = ""
|
||||
self.tasks: list[ActTaskDetailItem] = []
|
||||
|
||||
def read_from(self, ins: TafInputStream):
|
||||
self.status = ins.read_int32(0, default=self.status)
|
||||
self.msg = ins.read_string(1, default=self.msg)
|
||||
self.tasks = ins.read_list(2, item_reader=ActTaskDetailItem.read_list_item)
|
||||
|
||||
def write_to(self, os: TafOutputStream):
|
||||
pass
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
tasks = [item.to_dict() for item in self.tasks]
|
||||
return {
|
||||
"status": self.status,
|
||||
"msg": self.msg,
|
||||
"task_count": len(tasks),
|
||||
"tasks": tasks,
|
||||
}
|
||||
|
||||
|
||||
class ActPrizeItem(TafStruct):
|
||||
"""活动商品项,字段位置来自 getActPrizeList 实测响应。"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user