重构虎牙精英宝典协议与支付状态链路

This commit is contained in:
yml2213
2026-09-01 11:31:15 +08:00
parent 955ba45488
commit 684e16a07a
12 changed files with 937 additions and 51 deletions
+340
View File
@@ -107,6 +107,84 @@ class GetUserScoreResp(TafStruct):
}
class GetActInfoReq(TafStruct):
"""webActUI.getActInfo 请求。"""
def __init__(self):
self.actId = 0
self.actUuid = ""
self.appSource = ""
def write_to(self, os: TafOutputStream):
os.write_int64(0, self.actId)
os.write_string(1, self.actUuid)
os.write_string(2, self.appSource)
def read_from(self, ins: TafInputStream):
self.actId = ins.read_int64(0, default=self.actId)
self.actUuid = ins.read_string(1, default=self.actUuid)
self.appSource = ins.read_string(2, default=self.appSource)
class ActInfoItem(TafStruct):
def __init__(self):
self.actId = 0
self.name = ""
self.startTime = 0
self.endTime = 0
self.moduleId = 0
self.outerActId = ""
self.gameIdList = ""
self.gid = 0
def read_from(self, ins: TafInputStream):
for tag, attr, reader in (
(0, "actId", ins.read_int64), (1, "name", ins.read_string),
(2, "startTime", ins.read_int64), (3, "endTime", ins.read_int64),
(4, "moduleId", ins.read_int64), (5, "outerActId", ins.read_string),
(6, "gameIdList", ins.read_string), (8, "gid", ins.read_int64),
):
setattr(self, attr, reader(tag, default=getattr(self, attr)))
def write_to(self, os: TafOutputStream):
os.write_int64(0, self.actId)
os.write_string(1, self.name)
os.write_int64(2, self.startTime)
os.write_int64(3, self.endTime)
os.write_int64(4, self.moduleId)
os.write_string(5, self.outerActId)
os.write_string(6, self.gameIdList)
os.write_int64(8, self.gid)
def to_dict(self) -> dict:
return {"act_id": self.actId, "name": self.name, "start_time": self.startTime,
"end_time": self.endTime, "module_id": self.moduleId,
"outer_act_id": self.outerActId, "game_id_list": self.gameIdList,
"gid": self.gid}
class GetActInfoResp(TafStruct):
def __init__(self):
self.status = 0
self.msg = ""
self.info: ActInfoItem | None = None
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.info = ins.read_struct(2, ActInfoItem)
def write_to(self, os: TafOutputStream):
os.write_int32(0, self.status)
os.write_string(1, self.msg)
if self.info:
os.write_struct(2, self.info)
def to_dict(self) -> dict:
return {"status": self.status, "msg": self.msg,
"info": self.info.to_dict() if self.info else None}
class GetActPrizeListReq(TafStruct):
"""webActUI.getActPrizeList 请求。"""
@@ -170,6 +248,180 @@ class ScoreExchangePrizeReq(TafStruct):
self.isRole = ins.read_int32(6, default=self.isRole)
class GetActPrizeDetailReq(TafStruct):
"""webActUI.getActPrizeDetail 请求。"""
def __init__(self):
self.userId = ActivityUserId()
self.sid: int = 0
self.pid: int = 0
def write_to(self, os: TafOutputStream):
os.write_struct(0, self.userId)
os.write_int32(1, self.sid)
os.write_int32(2, self.pid)
def read_from(self, ins: TafInputStream):
self.userId = ins.read_struct(0, ActivityUserId) or self.userId
self.sid = ins.read_int32(1, default=self.sid)
self.pid = ins.read_int32(2, default=self.pid)
class ActPrizeDetailItem(TafStruct):
"""兑换详情中的奖品和服务端限制字段。"""
def __init__(self):
self.prizeId = 0
self.name = ""
self.score = 0
self.icon = ""
self.frequency = 0
self.frequencyLimit = 0
self.num = 0
self.status = 0
self.leftNum = 0
self.isShowNum = 0
self.percent = ""
self.newScore = 0
self.categoryId = ""
self.usedNum = 0
self.goodType = 0
self.commonPrizeId = 0
self.updateTime = 0
self.isCanExchange = 0
self.exchangeStartTime = 0
self.exchangeEndTime = 0
self.startTimeSlot = ""
self.endTimeSlot = ""
self.isTodayLimit = 0
self.isUserLimit = 0
def read_from(self, ins: TafInputStream):
readers = {
0: ("prizeId", ins.read_int64), 2: ("name", ins.read_string),
3: ("score", ins.read_int64), 5: ("icon", ins.read_string),
6: ("frequency", ins.read_int32), 7: ("frequencyLimit", ins.read_int32),
8: ("num", ins.read_int64), 9: ("status", ins.read_int32),
10: ("leftNum", ins.read_int64), 11: ("isShowNum", ins.read_int32),
12: ("percent", ins.read_string), 13: ("newScore", ins.read_int64),
14: ("categoryId", ins.read_string), 17: ("usedNum", ins.read_int64),
18: ("goodType", ins.read_int32), 22: ("commonPrizeId", ins.read_int64),
23: ("updateTime", ins.read_int64), 24: ("isCanExchange", ins.read_int32),
25: ("exchangeStartTime", ins.read_int64), 26: ("exchangeEndTime", ins.read_int64),
27: ("startTimeSlot", ins.read_string), 28: ("endTimeSlot", ins.read_string),
29: ("isTodayLimit", ins.read_int32), 30: ("isUserLimit", ins.read_int32),
}
while True:
pos = ins.buf.tell()
tag, dtype = ins.read_head()
if dtype == TafType.STRUCT_END:
ins.buf.seek(pos)
return
item = readers.get(tag)
if item is None:
ins.skip_field(dtype)
continue
name, reader = item
ins.buf.seek(pos)
setattr(self, name, reader(tag, default=getattr(self, name)))
def write_to(self, os: TafOutputStream):
os.write_int64(0, self.prizeId)
os.write_string(2, self.name)
os.write_int64(3, self.score)
os.write_string(5, self.icon)
os.write_int32(6, self.frequency)
os.write_int32(7, self.frequencyLimit)
os.write_int64(8, self.num)
os.write_int32(9, self.status)
os.write_int64(10, self.leftNum)
os.write_int32(11, self.isShowNum)
os.write_string(12, self.percent)
os.write_int64(13, self.newScore)
os.write_string(14, self.categoryId)
os.write_int64(17, self.usedNum)
os.write_int32(18, self.goodType)
os.write_int64(22, self.commonPrizeId)
os.write_int64(23, self.updateTime)
os.write_int32(24, self.isCanExchange)
os.write_int64(25, self.exchangeStartTime)
os.write_int64(26, self.exchangeEndTime)
os.write_string(27, self.startTimeSlot)
os.write_string(28, self.endTimeSlot)
os.write_int32(29, self.isTodayLimit)
os.write_int32(30, self.isUserLimit)
def to_dict(self) -> dict:
return {
"product_id": str(self.prizeId), "name": self.name, "score": self.score,
"icon": self.icon, "frequency": self.frequency,
"frequency_limit": self.frequencyLimit, "num": self.num,
"status": self.status, "left_num": self.leftNum,
"is_show_num": self.isShowNum, "percent": self.percent,
"new_score": self.newScore, "category_id": self.categoryId,
"used_num": self.usedNum, "good_type": self.goodType,
"common_prize_id": self.commonPrizeId, "update_time": self.updateTime,
"is_can_exchange": self.isCanExchange,
"exchange_start_time": self.exchangeStartTime,
"exchange_end_time": self.exchangeEndTime,
"start_time_slot": self.startTimeSlot, "end_time_slot": self.endTimeSlot,
"is_today_limit": self.isTodayLimit, "is_user_limit": self.isUserLimit,
}
class GetActPrizeDetailResp(TafStruct):
"""webActUI.getActPrizeDetail 响应。"""
def __init__(self):
self.status = 0
self.msg = ""
self.prize: ActPrizeDetailItem | None = None
self.detailStatus = 0
def read_from(self, ins: TafInputStream):
self.status = ins.read_int32(0, default=self.status)
self.msg = ins.read_string(1, default=self.msg)
outer = ins.read_struct(2, _ActPrizeDetailEnvelope)
if outer:
self.prize = outer.prize
self.detailStatus = outer.detailStatus
def write_to(self, os: TafOutputStream):
os.write_int32(0, self.status)
os.write_string(1, self.msg)
envelope = _ActPrizeDetailEnvelope()
envelope.prize = self.prize
envelope.detailStatus = self.detailStatus
os.write_struct(2, envelope)
def to_dict(self) -> dict:
return {"status": self.status, "msg": self.msg,
"prize": self.prize.to_dict() if self.prize else None,
"detail_status": self.detailStatus}
class _ActPrizeDetailEnvelope(TafStruct):
def __init__(self):
self.prize: ActPrizeDetailItem | None = None
self.detailStatus = 0
def read_from(self, ins: TafInputStream):
self.prize = ins.read_struct(0, ActPrizeDetailItem)
self.detailStatus = ins.read_int32(1, default=self.detailStatus)
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):
if self.prize:
os.write_struct(0, self.prize)
os.write_int32(1, self.detailStatus)
class ExchangeInfo(TafStruct):
"""积分兑换结果信息。"""
@@ -384,6 +636,94 @@ class GetActTaskDetailReq(TafStruct):
self.actId = ins.read_int32(1, default=self.actId)
class GetActUserTaskDetailReq(TafStruct):
"""webActUI.getActUserTaskDetail 请求。"""
def __init__(self):
self.userId = ActivityUserId()
self.actId = 0
def write_to(self, os: TafOutputStream):
os.write_struct(0, self.userId)
os.write_int64(1, self.actId)
def read_from(self, ins: TafInputStream):
self.userId = ins.read_struct(0, ActivityUserId) or self.userId
self.actId = ins.read_int64(1, default=self.actId)
class UserActTaskItem(TafStruct):
def __init__(self):
self.actId = 0
self.taskId = 0
self.taskStatus = 0
self.prizeStatus = 0
self.taskValue = ""
self.taskCount = 0
self.prizeCount = 0
self.subTaskDetail = 0
self.extraStatus = 0
def read_from(self, ins: TafInputStream):
for tag, attr, reader in (
(0, "actId", ins.read_int64), (1, "taskId", ins.read_int64),
(2, "taskStatus", ins.read_int32), (3, "prizeStatus", ins.read_int32),
(4, "taskValue", ins.read_string), (5, "taskCount", ins.read_int64),
(6, "prizeCount", ins.read_int64), (8, "subTaskDetail", ins.read_int64),
(9, "extraStatus", ins.read_int64),
):
setattr(self, attr, reader(tag, default=getattr(self, attr)))
def write_to(self, os: TafOutputStream):
os.write_int64(0, self.actId)
os.write_int64(1, self.taskId)
os.write_int32(2, self.taskStatus)
os.write_int32(3, self.prizeStatus)
os.write_string(4, self.taskValue)
os.write_int64(5, self.taskCount)
os.write_int64(6, self.prizeCount)
os.write_int64(8, self.subTaskDetail)
os.write_int64(9, self.extraStatus)
@staticmethod
def read_list_item(ins: TafInputStream, _tag: int):
item = UserActTaskItem()
item.read_from(ins)
_end, 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,
"task_status": self.taskStatus, "prize_status": self.prizeStatus,
"task_value": self.taskValue, "task_count": self.taskCount,
"prize_count": self.prizeCount, "sub_task_detail": self.subTaskDetail,
"extra_status": self.extraStatus}
class GetActUserTaskDetailResp(TafStruct):
def __init__(self):
self.status = 0
self.msg = ""
self.tasks: list[UserActTaskItem] = []
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=UserActTaskItem.read_list_item)
def write_to(self, os: TafOutputStream):
os.write_int32(0, self.status)
os.write_string(1, self.msg)
os.write_list(2, self.tasks)
def to_dict(self) -> dict:
return {"status": self.status, "msg": self.msg,
"task_count": len(self.tasks),
"tasks": [item.to_dict() for item in self.tasks]}
class ActTaskPrizeInfo(TafStruct):
"""活动任务奖励项,刷新充值商品时只取展示需要字段。"""