feat: 重做协作台账状态机并支持充值核账
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
from typing import Any
|
||||
|
||||
from .frame_decoder import decode_value_bytes
|
||||
from .taf_protocol import TafInputStream, TafOutputStream, TafStruct, TafType
|
||||
|
||||
|
||||
@@ -1150,6 +1151,107 @@ class ShopRawRsp:
|
||||
return {"code": self.code, "message": self.message, "payload": self.payload}
|
||||
|
||||
|
||||
def _as_int(value: Any) -> int | None:
|
||||
"""尽力把 TAF 解出来的数字转成 int;空值/脏值返回 None。"""
|
||||
if value is None or isinstance(value, bool):
|
||||
return None
|
||||
try:
|
||||
return int(value)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
|
||||
def _as_text(value: Any) -> str:
|
||||
return str(value).strip() if value is not None else ""
|
||||
|
||||
|
||||
def parse_points_center_gifts(payload: dict | None) -> list[dict]:
|
||||
"""解析 ``PlayMallUI.queryAllocation`` 响应里的积分中心商品。
|
||||
|
||||
真机(2026-10-19 HAR)结构::
|
||||
|
||||
payload.tag2[0].tag5 # SIMPLE_LIST,内容是 TAF LIST
|
||||
→ 分类 tag6
|
||||
→ 商品 tag1.tag0
|
||||
→ tag0 SPU(hy-xxxx)
|
||||
→ tag2 名称
|
||||
→ tag4 分类名
|
||||
→ tag5 图标
|
||||
→ tag9/tag10 金额(分,不是积分)
|
||||
→ tag13 库存
|
||||
→ tag75.tag0.tag2 积分
|
||||
→ tag34.tag26 积分(重复字段,兜底)
|
||||
|
||||
注意:``tag13`` 在这里是库存,不是 ``ActPrizeItem.price`` 的那个 tag13。
|
||||
"""
|
||||
if not isinstance(payload, dict):
|
||||
return []
|
||||
|
||||
gifts: list[dict] = []
|
||||
seen: set[str] = set()
|
||||
for section in payload.get("tag2") or []:
|
||||
if not isinstance(section, dict):
|
||||
continue
|
||||
blob = section.get("tag5")
|
||||
if not isinstance(blob, (bytes, bytearray)):
|
||||
continue
|
||||
categories = decode_value_bytes(bytes(blob), max_depth=40, keep_bytes=True)
|
||||
if not isinstance(categories, list):
|
||||
continue
|
||||
for category in categories:
|
||||
if not isinstance(category, dict):
|
||||
continue
|
||||
category_name = _as_text(category.get("tag1"))
|
||||
for good in category.get("tag6") or []:
|
||||
if not isinstance(good, dict):
|
||||
continue
|
||||
info = good.get("tag1")
|
||||
basic = info.get("tag0") if isinstance(info, dict) else None
|
||||
if not isinstance(basic, dict):
|
||||
continue
|
||||
spu = _as_text(basic.get("tag0"))
|
||||
name = _as_text(basic.get("tag2"))
|
||||
if not spu or not name:
|
||||
continue
|
||||
if spu in seen:
|
||||
continue
|
||||
seen.add(spu)
|
||||
|
||||
score_box = basic.get("tag75")
|
||||
score_info = (
|
||||
score_box.get("tag0") if isinstance(score_box, dict) else None
|
||||
)
|
||||
points = (
|
||||
_as_int(score_info.get("tag2"))
|
||||
if isinstance(score_info, dict)
|
||||
else None
|
||||
)
|
||||
if points is None:
|
||||
game_box = basic.get("tag34")
|
||||
points = (
|
||||
_as_int(game_box.get("tag26"))
|
||||
if isinstance(game_box, dict)
|
||||
else None
|
||||
)
|
||||
|
||||
stock = _as_int(basic.get("tag13"))
|
||||
gifts.append(
|
||||
{
|
||||
"product_id": spu,
|
||||
"name": name[:256],
|
||||
"price": points,
|
||||
"remain_text": f"剩{stock}" if stock is not None else "",
|
||||
"stock": stock,
|
||||
"score": points,
|
||||
"category_name": (_as_text(basic.get("tag4")) or category_name)[
|
||||
:64
|
||||
],
|
||||
"icon": _as_text(basic.get("tag5"))[:512],
|
||||
}
|
||||
)
|
||||
return gifts
|
||||
|
||||
|
||||
class PlayMallAppInfo(TafStruct):
|
||||
"""PlayMallUI 系接口的应用信息。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user