feat(huya): 统一积分兑换并完善兑换记录

This commit is contained in:
yml
2026-11-13 19:03:55 +08:00
parent b89ee4fd18
commit 711be0e2b6
17 changed files with 2064 additions and 193 deletions
+47 -7
View File
@@ -10,6 +10,10 @@
from __future__ import annotations
from ..huya_defaults import (
HUYA_DEFAULT_POINTS_PAGE_CODE,
HUYA_DEFAULT_POINTS_SOURCE_ID,
)
from .huya_runner_bind import HUYA_BIND_ROOM_ID, HUYA_BIND_ZT_UUID
from .huya_runner_core import HUYA_RECHARGE_SOURCE_ID
@@ -20,7 +24,7 @@ EXCHANGE_TARGET_ESPORTS = "esports"
#: 未指定目标时使用的默认页(保持历史行为:精英宝典)
DEFAULT_EXCHANGE_TARGET = EXCHANGE_TARGET_ELITE
#: 精英宝典复用绑定/充值活动 uuid;电竞宝典为独立的 zt 活动 uuid
#: 旧 zt 活动 uuid 仅保留给旧调用兼容;精英宝典现统一走积分中心页。
HUYA_ELITE_ZT_UUID = HUYA_BIND_ZT_UUID
HUYA_ESPORTS_ZT_UUID = "50ea007f"
@@ -52,25 +56,61 @@ def _zt_exchange_url(zt_uuid: str, room_pid: str) -> str:
)
def exchange_target_url(key: str, room_pid: str) -> str:
"""返回指定目标页地址;pid 由调用方(路由)归一化,空值在这里会拼出无 pid 的地址。"""
def _points_exchange_url(
room_pid: str,
*,
page_code: str = HUYA_DEFAULT_POINTS_PAGE_CODE,
source_id: str = HUYA_DEFAULT_POINTS_SOURCE_ID,
) -> str:
pid = str(room_pid or "").strip()
return (
"https://m-shop.huya.com/points.html"
f"?pagecode={page_code}"
f"&sourceId={source_id}"
f"&pid={pid}"
f"&anchorUid={pid}"
f"&roomid={HUYA_BIND_ROOM_ID}"
)
def exchange_target_url(
key: str,
room_pid: str,
*,
points_page_code: str = HUYA_DEFAULT_POINTS_PAGE_CODE,
points_source_id: str = HUYA_DEFAULT_POINTS_SOURCE_ID,
) -> str:
"""返回指定目标页地址;pid 由调用方(路由)归一化,空值在这里会拼出无 pid 的地址。"""
if key == EXCHANGE_TARGET_LIVE_ROOM:
return f"https://www.huya.com/{HUYA_BIND_ROOM_ID}"
if key == EXCHANGE_TARGET_ELITE:
return _zt_exchange_url(HUYA_ELITE_ZT_UUID, pid)
return _points_exchange_url(
room_pid,
page_code=points_page_code,
source_id=points_source_id,
)
if key == EXCHANGE_TARGET_ESPORTS:
return _zt_exchange_url(HUYA_ESPORTS_ZT_UUID, pid)
return _zt_exchange_url(HUYA_ESPORTS_ZT_UUID, str(room_pid or "").strip())
raise ValueError(f"不支持的兑换目标:{key}")
def exchange_target_options(room_pid: str) -> list[dict[str, str]]:
def exchange_target_options(
room_pid: str,
*,
points_page_code: str = HUYA_DEFAULT_POINTS_PAGE_CODE,
points_source_id: str = HUYA_DEFAULT_POINTS_SOURCE_ID,
) -> list[dict[str, str]]:
"""返回三个可选目标页,顺序固定,供前端选择器渲染。"""
return [
{
"key": key,
"label": EXCHANGE_TARGET_LABELS[key],
"url": exchange_target_url(key, room_pid),
"url": exchange_target_url(
key,
room_pid,
points_page_code=points_page_code,
points_source_id=points_source_id,
),
}
for key in EXCHANGE_TARGET_KEYS
]