修复(半自动履约): 按虎牙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( const availability = resolveHuyaRoleRebindAvailability(
role({ role({
changeBindDay: 7, changeBindDay: 7,
changeBindTime: Math.floor((NOW - 2 * DAY_MS) / 1000), changeBindTime: Math.floor((NOW + 4 * DAY_MS) / 1000),
}), }),
NOW, NOW,
) )
@@ -338,6 +338,31 @@ test('冷却计算和目标匹配器保持唯一实现', () => {
assert.equal(classifyHuyaRebindFailure('当前绑定账号暂不可换绑'), 'account') 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', () => { test('数据库角色快照分别保留加密 token 与平台角色 UID', () => {
const snapshots = roleSnapshotsFromLegacyFields({ const snapshots = roleSnapshotsFromLegacyFields({
bindGameRole: TARGET.roleName, bindGameRole: TARGET.roleName,
@@ -253,9 +253,8 @@ export function resolveHuyaRoleRebindAvailability(
const windowDays = hasPlatformWindow ? Math.round(configuredDays) : DEFAULT_REBIND_WINDOW_DAYS const windowDays = hasPlatformWindow ? Math.round(configuredDays) : DEFAULT_REBIND_WINDOW_DAYS
const changeBindTime = Number(role.changeBindTime || 0) const changeBindTime = Number(role.changeBindTime || 0)
if (Number.isFinite(changeBindTime) && changeBindTime > 0) { if (Number.isFinite(changeBindTime) && changeBindTime > 0) {
const changedAtMs = changeBindTime > 1e12 ? changeBindTime : changeBindTime * 1000 // 2026-11-20 换绑 HAR 实证:该字段是平台给出的“下次可换绑时间”,不是上次换绑时间。
const offsetDays = hasPlatformWindow ? Math.max(windowDays - 1, 0) : DEFAULT_REBIND_WINDOW_DAYS const availableAtMs = changeBindTime > 1e12 ? changeBindTime : changeBindTime * 1000
const availableAtMs = changedAtMs + offsetDays * DAY_MS
if (availableAtMs > nowMs) { if (availableAtMs > nowMs) {
return { return {
blocked: true, blocked: true,
@@ -293,6 +292,7 @@ export function resolveHuyaRebindCooldownResponse(
if (!response || (response.status !== undefined && response.status !== 200)) { if (!response || (response.status !== undefined && response.status !== 200)) {
return { days: 0, nextRebindAt: '' } return { days: 0, nextRebindAt: '' }
} }
const changeBindTime = Number(response.accountData?.changeBindTime || 0)
const availability = resolveHuyaRoleRebindAvailability( const availability = resolveHuyaRoleRebindAvailability(
{ {
isBindAccount: true, isBindAccount: true,
@@ -300,7 +300,7 @@ export function resolveHuyaRebindCooldownResponse(
roleName: '', roleName: '',
roleToken: '', roleToken: '',
channel: '', channel: '',
changeBindTime: Number(response.accountData?.changeBindTime || 0), changeBindTime,
changeBindDay: Number(response.changeBindDay || 0), changeBindDay: Number(response.changeBindDay || 0),
}, },
nowMs, nowMs,
@@ -311,7 +311,7 @@ export function resolveHuyaRebindCooldownResponse(
nextRebindAt: availability.availableAt, nextRebindAt: availability.availableAt,
} }
} }
if (availability.windowDays > 0) { if (!changeBindTime && availability.windowDays > 0) {
return { return {
days: availability.windowDays, days: availability.windowDays,
nextRebindAt: iso(nowMs + availability.windowDays * DAY_MS), nextRebindAt: iso(nowMs + availability.windowDays * DAY_MS),
@@ -3,33 +3,32 @@ import test from 'node:test'
import { resolveRebindCooldown } from './huya-native-connector.js' 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 NOW = Date.UTC(2026, 10, 16, 4, 12, 24)
const DAY_MS = 24 * 60 * 60 * 1000 const DAY_MS = 24 * 60 * 60 * 1000
test('换绑冷却:changeBindTime 为初次绑定时间时,下次换绑为 7 天后', () => { test('换绑冷却:changeBindTime 已到当前时间时立即可换绑', () => {
const result = resolveRebindCooldown( const result = resolveRebindCooldown(
{ {
status: 200, status: 200,
changeBindDay: 0, changeBindDay: 7,
accountData: { changeBindTime: Math.floor(NOW / 1000) }, accountData: { changeBindTime: Math.floor(NOW / 1000) },
}, },
NOW, NOW,
) )
assert.equal(result.days, 7) assert.equal(result.days, 0)
assert.equal(result.nextRebindAt.slice(0, 10), '2026-11-23') assert.equal(result.nextRebindAt, '')
}) })
test('换绑冷却:按虎牙日界推算(11-16 绑定 → 11-23 才能换绑)', () => { test('换绑冷却:changeBindTime 是下一次可换绑时间,不再重复叠加 7 天', () => {
// 实测 task 34:changeBindTime = 1794844800 = 2026-11-17 00:00 +08:00,changeBindDay = 7。 // 2026-11-20 HAR:换绑成功后 changeBindTime 直接返回 7 天后的可换绑时间。
const now = Date.UTC(2026, 10, 16, 6, 31) // 2026-11-16 14:31 +08:00 const now = Date.UTC(2026, 10, 16, 6, 31) // 2026-11-16 14:31 +08:00
const result = resolveRebindCooldown( const result = resolveRebindCooldown(
{ status: 200, changeBindDay: 7, accountData: { changeBindTime: 1794844800 } }, { status: 200, changeBindDay: 7, accountData: { changeBindTime: 1794844800 } },
now, now,
) )
assert.equal(result.days, 7) assert.equal(result.days, 1)
// 2026-11-23 00:00 +08:00,与虎牙绑定页「预计下次换绑时间 2026/11/23」一致。 assert.equal(result.nextRebindAt, '2026-11-16T16:00:00.000Z')
assert.equal(result.nextRebindAt, '2026-11-22T16:00:00.000Z')
}) })
test('换绑冷却:changeBindTime 已超过 7 天时不再限制', () => { test('换绑冷却:changeBindTime 已超过 7 天时不再限制', () => {
@@ -419,6 +419,8 @@ manual fulfillment
`flowState = confirmed` 且 `canCompleteTask = true` 时才允许进入 `waiting_operator` 或完成履约。 `flowState = confirmed` 且 `canCompleteTask = true` 时才允许进入 `waiting_operator` 或完成履约。
账号侧冷却、目标角色侧冷却、换绑拒绝、目标不一致和绑定标志不完整分别由决策器输出对应的 账号侧冷却、目标角色侧冷却、换绑拒绝、目标不一致和绑定标志不完整分别由决策器输出对应的
`flowState / rebindBlockScope / allowedActions`,各写入口不得自行分类。 `flowState / rebindBlockScope / allowedActions`,各写入口不得自行分类。
2026-11-20 换绑 HAR 实证:`accountData.changeBindTime` 是平台给出的下一次可换绑时间,
`changeBindDay` 是平台配置的天数;不得把 `changeBindTime` 当成上次换绑时间再加一次冷却窗口。
- 外部 Connector 通过签名 Webhook `POST /api/integration/platform-fulfillment/semi-auto/task-state` - 外部 Connector 通过签名 Webhook `POST /api/integration/platform-fulfillment/semi-auto/task-state`
提交登录与绑定快照,事件 ID 使用 `integration_inbox` 幂等;Connector 只提交平台观察到的事实, 提交登录与绑定快照,事件 ID 使用 `integration_inbox` 幂等;Connector 只提交平台观察到的事实,
不得直接声明业务履约完成。每个快照必须携带任务级单调 `stateVersion`;同一任务的旧版本或 不得直接声明业务履约完成。每个快照必须携带任务级单调 `stateVersion`;同一任务的旧版本或