feat(semi-auto): 缺角色ID时引导客户联系客服并拦截确认
This commit is contained in:
@@ -14,3 +14,33 @@ export function resolveBindingRoleId(roleId: unknown, huyaUid: unknown): string
|
||||
|
||||
return /^\d+$/.test(uid) ? uid : rawRoleId
|
||||
}
|
||||
|
||||
/** 只有纯数字角色 ID 才能和客户填写的游戏编号做可信比对。 */
|
||||
export function isNumericBindingRoleId(value: unknown): boolean {
|
||||
return /^\d+$/.test(String(value ?? '').trim())
|
||||
}
|
||||
|
||||
export type BindingRoleInfo = {
|
||||
resolvedRoleId: string
|
||||
roleIdVerified: boolean
|
||||
hasBoundRole: boolean
|
||||
/** 平台返回了绑定角色,但没有可核对的数字角色 ID → 必须人工核实。 */
|
||||
requiresSupport: boolean
|
||||
}
|
||||
|
||||
/** 统一计算「绑定角色 + 可核对角色 ID」的展示状态,避免前后端各自判断。 */
|
||||
export function describeBindingRole(
|
||||
roleName: unknown,
|
||||
roleId: unknown,
|
||||
huyaUid: unknown,
|
||||
): BindingRoleInfo {
|
||||
const resolvedRoleId = resolveBindingRoleId(roleId, huyaUid)
|
||||
const roleIdVerified = isNumericBindingRoleId(resolvedRoleId)
|
||||
const hasBoundRole = String(roleName ?? '').trim().length > 0
|
||||
return {
|
||||
resolvedRoleId,
|
||||
roleIdVerified,
|
||||
hasBoundRole,
|
||||
requiresSupport: hasBoundRole && !roleIdVerified,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,10 @@ export type ConnectorBindingSession = {
|
||||
bindGameRole: string
|
||||
bindGameRoleId: string
|
||||
bindGameChannel: string
|
||||
/** 平台返回的角色 ID 是否可核对(纯数字);false 时需引导客户联系客服人工核实。 */
|
||||
roleIdVerified?: boolean
|
||||
/** 已绑定角色但缺少可核对角色 ID:客户页应提示联系客服,禁止直接确认绑定。 */
|
||||
requiresSupport?: boolean
|
||||
hasExistingBinding?: boolean
|
||||
rebindRequested?: boolean
|
||||
rebindUnchanged?: boolean
|
||||
|
||||
@@ -12,7 +12,7 @@ import path from 'node:path'
|
||||
import { runtimeConfig } from '../../../config/runtime.js'
|
||||
import { createHttpError } from '../../../utils/http.js'
|
||||
import { logWarn } from '../../../utils/logger.js'
|
||||
import { resolveBindingRoleId } from '../binding-role-id.js'
|
||||
import { describeBindingRole } from '../binding-role-id.js'
|
||||
import type {
|
||||
ConnectorBindingSession,
|
||||
ConnectorBrowserTicket,
|
||||
@@ -833,8 +833,12 @@ export class HuyaNativeConnector {
|
||||
const hasExistingBinding = hasExistingHuyaBinding(roleResponse)
|
||||
session.binding.hasExistingBinding = hasExistingBinding
|
||||
applyRebindMeta(session, roleResponse, this.now())
|
||||
if (role.role && !options.forceRebind) {
|
||||
this.markRoleReady(session, role, hasExistingBinding && !session.binding.rebindRequested)
|
||||
// 只有平台明确「已绑定」才允许直接确认;没有绑定(即使残留角色名)必须走扫码绑定。
|
||||
if (hasExistingBinding && !options.forceRebind) {
|
||||
this.markRoleReady(session, role, true)
|
||||
if (!role.role) {
|
||||
session.binding.message = '当前账号已有绑定角色,但平台未返回角色信息,请联系客服人工核实'
|
||||
}
|
||||
if (session.binding.rebindRequested) {
|
||||
session.binding.message = session.binding.rebindUnchanged
|
||||
? rebindFailureMessage(
|
||||
@@ -1069,7 +1073,7 @@ export class HuyaNativeConnector {
|
||||
const hasExistingBinding = hasExistingHuyaBinding(response)
|
||||
session.binding.hasExistingBinding = hasExistingBinding
|
||||
applyRebindMeta(session, response, this.now())
|
||||
if (role.role) {
|
||||
if (role.role && hasExistingBinding) {
|
||||
const rebindRequested = session.binding.rebindRequested
|
||||
const roleKey = bindingRoleKey(role)
|
||||
const changedRole =
|
||||
@@ -1112,6 +1116,10 @@ export class HuyaNativeConnector {
|
||||
if (rebindRequested) {
|
||||
session.binding.message = '已识别换绑角色,请确认换绑'
|
||||
}
|
||||
} else if (hasExistingBinding) {
|
||||
// 平台标记已绑定,但没有返回角色信息(或角色ID不可核对):必须人工核实,不能生成二维码。
|
||||
this.markRoleReady(session, role, true)
|
||||
session.binding.message = '当前账号已有绑定角色,但平台未返回角色信息,请联系客服人工核实'
|
||||
} else if (
|
||||
!session.binding.rebindRequested &&
|
||||
session.binding.bindConfirmState === 'rejected'
|
||||
@@ -1449,6 +1457,13 @@ export class HuyaNativeConnector {
|
||||
session.binding.role = role.role
|
||||
session.binding.roleId = role.roleId || ''
|
||||
session.binding.channel = role.channel
|
||||
const roleInfo = describeBindingRole(role.role, role.roleId, session.uid)
|
||||
if (roleInfo.requiresSupport) {
|
||||
session.binding.message = existingBinding
|
||||
? '当前账号已有绑定角色,但未获取到可核对的角色ID,请联系客服人工核实'
|
||||
: '已识别绑定角色,但未获取到可核对的角色ID,请联系客服人工核实'
|
||||
return
|
||||
}
|
||||
session.binding.message = existingBinding
|
||||
? '当前账号已有绑定角色,请确认直接使用'
|
||||
: '绑定角色已识别,请确认绑定'
|
||||
@@ -1526,6 +1541,9 @@ export class HuyaNativeConnector {
|
||||
|
||||
private bindingView(session: NativeSession): ConnectorBindingSession {
|
||||
const binding = session.binding
|
||||
const roleInfo = describeBindingRole(binding.role, binding.roleId, session.uid)
|
||||
const requiresSupport =
|
||||
roleInfo.requiresSupport || (binding.hasExistingBinding === true && !roleInfo.roleIdVerified)
|
||||
return {
|
||||
sessionId: session.sessionId,
|
||||
status: binding.status,
|
||||
@@ -1534,8 +1552,10 @@ export class HuyaNativeConnector {
|
||||
qrUrl: binding.qrUrl,
|
||||
bindGameAccount: binding.account,
|
||||
bindGameRole: binding.role,
|
||||
bindGameRoleId: resolveBindingRoleId(binding.roleId, session.uid),
|
||||
bindGameRoleId: roleInfo.resolvedRoleId,
|
||||
bindGameChannel: binding.channel,
|
||||
roleIdVerified: roleInfo.roleIdVerified,
|
||||
requiresSupport,
|
||||
hasExistingBinding: binding.hasExistingBinding,
|
||||
rebindRequested: binding.rebindRequested,
|
||||
rebindUnchanged: binding.rebindUnchanged,
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { describe, it } from 'node:test'
|
||||
|
||||
import { resolveBindingRoleId } from './binding-role-id.js'
|
||||
import {
|
||||
describeBindingRole,
|
||||
isNumericBindingRoleId,
|
||||
resolveBindingRoleId,
|
||||
} from './binding-role-id.js'
|
||||
import {
|
||||
compareBindingRole,
|
||||
detectServerZone,
|
||||
@@ -58,6 +62,45 @@ describe('待确认角色 UID 取数(huyaUid)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('绑定角色可核对性(缺角色ID)', () => {
|
||||
it('数字角色 ID 可直接核对', () => {
|
||||
const info = describeBindingRole('大鲨鱼伊塞53', '1192083858', '')
|
||||
assert.equal(info.roleIdVerified, true)
|
||||
assert.equal(info.requiresSupport, false)
|
||||
})
|
||||
|
||||
it('加密角色 ID 但 UID 是数字时可核对', () => {
|
||||
const info = describeBindingRole(
|
||||
'大鲨鱼伊塞53',
|
||||
'834ee3e75a1bfc9f65fb6b966bac7ef318e68ea',
|
||||
'1199608910400',
|
||||
)
|
||||
assert.equal(info.resolvedRoleId, '1199608910400')
|
||||
assert.equal(info.roleIdVerified, true)
|
||||
assert.equal(info.requiresSupport, false)
|
||||
})
|
||||
|
||||
it('有角色但没有可核对数字 ID 时需要联系客服', () => {
|
||||
const info = describeBindingRole('Mock测试角色', 'mock-role-abc', 'mock-huya-abc')
|
||||
assert.equal(info.roleIdVerified, false)
|
||||
assert.equal(info.requiresSupport, true)
|
||||
})
|
||||
|
||||
it('没有角色名时不需要人工核实', () => {
|
||||
const info = describeBindingRole('', '', '')
|
||||
assert.equal(info.hasBoundRole, false)
|
||||
assert.equal(info.requiresSupport, false)
|
||||
})
|
||||
|
||||
it('只接受纯数字角色 ID 参与核对', () => {
|
||||
assert.equal(isNumericBindingRoleId('1192083858'), true)
|
||||
assert.equal(isNumericBindingRoleId(' 1192083858 '), true)
|
||||
assert.equal(isNumericBindingRoleId('mock-role-abc'), false)
|
||||
assert.equal(isNumericBindingRoleId(''), false)
|
||||
assert.equal(isNumericBindingRoleId(null), false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('区服解析', () => {
|
||||
it('安卓 + 微信识别为安卓V区', () => {
|
||||
assert.equal(detectServerZone('安卓(android) · 微信'), '安卓V区')
|
||||
|
||||
@@ -56,6 +56,7 @@ import {
|
||||
upsertSemiAutoCredentialWithClient,
|
||||
} from './semi-auto-credential-service.js'
|
||||
import { querySemiAutoTraces } from './semi-auto-trace.js'
|
||||
import { isNumericBindingRoleId } from './binding-role-id.js'
|
||||
|
||||
const SEMI_AUTO_PLATFORMS = new Set(['huya', 'weibo'])
|
||||
type SemiAutoPlatform = 'huya' | 'weibo'
|
||||
@@ -1102,6 +1103,9 @@ async function updateBindingTask(
|
||||
) {
|
||||
const mapped = mapBindingUpdate(session)
|
||||
const comparison = compareBindingRole(task, mapped)
|
||||
const roleIdVerified = isNumericBindingRoleId(mapped.bindGameRoleId)
|
||||
const requiresSupport =
|
||||
(Boolean(mapped.bindGameRole) || mapped.hasExistingBinding === true) && !roleIdVerified
|
||||
const executionStatus: ExecutionStatus =
|
||||
mapped.status === 'confirmed'
|
||||
? 'waiting_operator'
|
||||
@@ -1178,6 +1182,8 @@ async function updateBindingTask(
|
||||
bindGameRole: mapped.bindGameRole,
|
||||
bindGameRoleId: mapped.bindGameRoleId,
|
||||
bindGameChannel: mapped.bindGameChannel,
|
||||
roleIdVerified,
|
||||
requiresSupport,
|
||||
hasExistingBinding: mapped.hasExistingBinding,
|
||||
rebindRequested: mapped.rebindRequested,
|
||||
rebindUnchanged: mapped.rebindUnchanged,
|
||||
@@ -1405,6 +1411,19 @@ export async function confirmPublicBinding(
|
||||
},
|
||||
)
|
||||
}
|
||||
// 已绑定角色但没有可核对的数字角色 ID:不能只按角色名放行,必须人工核实(客户页会提示联系客服)。
|
||||
const boundRolePresent =
|
||||
Boolean(String(session.bindGameRole || '').trim()) || session.hasExistingBinding === true
|
||||
if (
|
||||
task.platform === 'huya' &&
|
||||
boundRolePresent &&
|
||||
!isNumericBindingRoleId(session.bindGameRoleId)
|
||||
) {
|
||||
throw createHttpError('平台未返回可核对的角色ID,请联系客服人工核实后再确认绑定', {
|
||||
statusCode: 409,
|
||||
errorCode: 'semi_auto_binding_role_id_missing',
|
||||
})
|
||||
}
|
||||
const comparison = compareBindingRole(task, session)
|
||||
if (comparison.verdict === 'mismatch') {
|
||||
throw createHttpError(comparison.message, {
|
||||
|
||||
Reference in New Issue
Block a user