修复(半自动履约): 按虎牙HAR修正换绑冷却时间

This commit is contained in:
yml
2026-11-20 16:06:02 +08:00
parent e17d1ac8ab
commit 4eda3f6972
4 changed files with 42 additions and 16 deletions
@@ -328,7 +328,7 @@ test('冷却计算和目标匹配器保持唯一实现', () => {
const availability = resolveHuyaRoleRebindAvailability(
role({
changeBindDay: 7,
changeBindTime: Math.floor((NOW - 2 * DAY_MS) / 1000),
changeBindTime: Math.floor((NOW + 4 * DAY_MS) / 1000),
}),
NOW,
)
@@ -338,6 +338,31 @@ test('冷却计算和目标匹配器保持唯一实现', () => {
assert.equal(classifyHuyaRebindFailure('当前绑定账号暂不可换绑'), 'account')
})
test('changeBindTime 已到当前时间时不再重复叠加 7 天窗口', () => {
const available = resolveHuyaRoleRebindAvailability(
role({
changeBindDay: 7,
changeBindTime: Math.floor((NOW - 1_000) / 1000),
}),
NOW,
)
assert.equal(available.blocked, false)
assert.equal(available.availableAt, '')
assert.equal(available.remainingDays, 0)
const nextAvailableAt = NOW + 7 * DAY_MS
const blocked = resolveHuyaRoleRebindAvailability(
role({
changeBindDay: 7,
changeBindTime: Math.floor(nextAvailableAt / 1000),
}),
NOW,
)
assert.equal(blocked.blocked, true)
assert.equal(blocked.availableAt, new Date(nextAvailableAt).toISOString())
assert.equal(blocked.remainingDays, 7)
})
test('数据库角色快照分别保留加密 token 与平台角色 UID', () => {
const snapshots = roleSnapshotsFromLegacyFields({
bindGameRole: TARGET.roleName,
@@ -253,9 +253,8 @@ export function resolveHuyaRoleRebindAvailability(
const windowDays = hasPlatformWindow ? Math.round(configuredDays) : DEFAULT_REBIND_WINDOW_DAYS
const changeBindTime = Number(role.changeBindTime || 0)
if (Number.isFinite(changeBindTime) && changeBindTime > 0) {
const changedAtMs = changeBindTime > 1e12 ? changeBindTime : changeBindTime * 1000
const offsetDays = hasPlatformWindow ? Math.max(windowDays - 1, 0) : DEFAULT_REBIND_WINDOW_DAYS
const availableAtMs = changedAtMs + offsetDays * DAY_MS
// 2026-11-20 换绑 HAR 实证:该字段是平台给出的“下次可换绑时间”,不是上次换绑时间。
const availableAtMs = changeBindTime > 1e12 ? changeBindTime : changeBindTime * 1000
if (availableAtMs > nowMs) {
return {
blocked: true,
@@ -293,6 +292,7 @@ export function resolveHuyaRebindCooldownResponse(
if (!response || (response.status !== undefined && response.status !== 200)) {
return { days: 0, nextRebindAt: '' }
}
const changeBindTime = Number(response.accountData?.changeBindTime || 0)
const availability = resolveHuyaRoleRebindAvailability(
{
isBindAccount: true,
@@ -300,7 +300,7 @@ export function resolveHuyaRebindCooldownResponse(
roleName: '',
roleToken: '',
channel: '',
changeBindTime: Number(response.accountData?.changeBindTime || 0),
changeBindTime,
changeBindDay: Number(response.changeBindDay || 0),
},
nowMs,
@@ -311,7 +311,7 @@ export function resolveHuyaRebindCooldownResponse(
nextRebindAt: availability.availableAt,
}
}
if (availability.windowDays > 0) {
if (!changeBindTime && availability.windowDays > 0) {
return {
days: availability.windowDays,
nextRebindAt: iso(nowMs + availability.windowDays * DAY_MS),
@@ -3,33 +3,32 @@ import test from 'node:test'
import { resolveRebindCooldown } from './huya-native-connector.js'
// 2026-11-16 12:12:24 +08:00,对应任务 34 的初次绑定时间。
// 2026-11-16 12:12:24 +08:00
const NOW = Date.UTC(2026, 10, 16, 4, 12, 24)
const DAY_MS = 24 * 60 * 60 * 1000
test('换绑冷却:changeBindTime 为初次绑定时间时,下次换绑为 7 天后', () => {
test('换绑冷却:changeBindTime 已到当前时间时立即可换绑', () => {
const result = resolveRebindCooldown(
{
status: 200,
changeBindDay: 0,
changeBindDay: 7,
accountData: { changeBindTime: Math.floor(NOW / 1000) },
},
NOW,
)
assert.equal(result.days, 7)
assert.equal(result.nextRebindAt.slice(0, 10), '2026-11-23')
assert.equal(result.days, 0)
assert.equal(result.nextRebindAt, '')
})
test('换绑冷却:按虎牙日界推算(11-16 绑定 → 11-23 才能换绑)', () => {
// 实测 task 34:changeBindTime = 1794844800 = 2026-11-17 00:00 +08:00,changeBindDay = 7。
test('换绑冷却:changeBindTime 是下一次可换绑时间,不再重复叠加 7 天', () => {
// 2026-11-20 HAR:换绑成功后 changeBindTime 直接返回 7 天后的可换绑时间。
const now = Date.UTC(2026, 10, 16, 6, 31) // 2026-11-16 14:31 +08:00
const result = resolveRebindCooldown(
{ status: 200, changeBindDay: 7, accountData: { changeBindTime: 1794844800 } },
now,
)
assert.equal(result.days, 7)
// 2026-11-23 00:00 +08:00,与虎牙绑定页「预计下次换绑时间 2026/11/23」一致。
assert.equal(result.nextRebindAt, '2026-11-22T16:00:00.000Z')
assert.equal(result.days, 1)
assert.equal(result.nextRebindAt, '2026-11-16T16:00:00.000Z')
})
test('换绑冷却:changeBindTime 已超过 7 天时不再限制', () => {