调整(微博绑定): 确认后同样引导截图联系客服,换绑冷却按平台天数并留证

- 客户页抽出统一的「绑定已确认」渲染:标题 + 「请截图本页,把订单号和这张截图发给客服」+
  可复制订单号;虎牙与微博共用同一段文案,删除微博原来的「客服正在安排 / 请耐心等待」。
- 微博换绑冷却:天数只取后端 `rebindCooldownDays`(来自平台 `rebind_remain_days`);
  冷却中且已有绑定角色时禁用「微信绑定 / QQ 绑定」并提示剩余天数,
  「刷新角色状态」不受影响。
- 微博绑定失败原因改为常驻展示(平台原因 + 任务 lastError 去重),
  冷却拒绝不再只弹一个瞬时 toast。
- 后端补留证:微博换绑被平台冷却拒绝时写 `last_error` 并追加
  `weibo_binding_rejected` 事件(channel + 原因),便于客服排障。
- 权威文档补微博第 ⑥ 条:冷却天数只认平台、拒绝需留证、确认后直接引导截图联系客服。
- 测试:新增微博冷却与共用渲染断言(前端 491 全绿),后端补微博留证回归断言(1552 全绿)。
This commit is contained in:
yml
2026-12-02 11:23:33 +08:00
parent 0314955f9b
commit 7d7a996f7d
6 changed files with 278 additions and 96 deletions
@@ -634,10 +634,29 @@ export async function startPublicBinding(
}
assertCustomerProfileReady(task)
if (task.platform === 'weibo') {
const session = await startWeiboBinding(task.connector_session_id, task.connector_mode, {
channel: input.channel === 'qq' ? 'qq' : 'wx',
forceRebind: input.forceRebind === true,
})
let session: ConnectorBindingSession
try {
session = await startWeiboBinding(task.connector_session_id, task.connector_mode, {
channel: input.channel === 'qq' ? 'qq' : 'wx',
forceRebind: input.forceRebind === true,
})
} catch (error) {
// 微博换绑被平台冷却拒绝时同样要留证:客户页要看到天数,后台要能看到原因。
const message = error instanceof Error ? error.message : '生成微博角色绑定二维码失败'
await withTransaction(async (client) => {
const current = await loadTaskForUpdateWithClient(client, task.id)
await convergeSemiAutoTaskState(client, current.id, {
reason: 'weibo_binding_rejected',
actor: 'customer',
patch: { lastError: message },
event: {
eventType: 'weibo_binding_rejected',
detail: { message, channel: input.channel === 'qq' ? 'qq' : 'wx' },
},
})
})
throw error
}
const binding = await updateBindingTask(task, session, 'customer')
const updated = await loadTask(task.id)
return { task: mapTask(updated), binding }
@@ -43,3 +43,14 @@ describe('改完资料后重新从平台核对一次绑定事实', () => {
)
})
})
describe('微博换绑被拒绝也要留证', () => {
it('startPublicBinding 的微博分支会写 last_error 与事件', () => {
const start = customerService.indexOf("if (task.platform === 'weibo') {\n let session")
assert.ok(start > 0, '未找到微博分支的失败留证代码')
const body = customerService.slice(start, start + 1600)
assert.ok(body.includes("reason: 'weibo_binding_rejected'"))
assert.ok(body.includes('patch: { lastError: message }'))
assert.ok(body.includes("eventType: 'weibo_binding_rejected'"))
})
})
@@ -66,6 +66,22 @@ const SERVER_ZONE_OPTIONS = CUSTOMER_SERVER_ZONE_OPTIONS
/** antd v6 语义化 classNames:让区服下拉弹层用页面深色样式 */
const SERVER_ZONE_SELECT_CLASS_NAMES = { popup: { root: 'customer-collect-dropdown' } }
/**
* 绑定失败原因去重收集:平台原因、任务 lastError、本次请求抛错可能说的是同一句话,
* 只按出现顺序保留第一次,空值直接丢弃。
*/
function collectBindingFailureReasons(values: Array<string | null | undefined>) {
const seen = new Set<string>()
const reasons: string[] = []
for (const value of values) {
const text = String(value || '').trim()
if (!text || seen.has(text)) continue
seen.add(text)
reasons.push(text)
}
return reasons
}
export default function CustomerFulfillmentPage({
expectedPlatform,
}: {
@@ -996,6 +1012,42 @@ export default function CustomerFulfillmentPage({
}
}
/**
* 「确认绑定成功」后两个平台必须给出同一段引导:同一段 JSX,只换刷新按钮的文案和动作。
* 客户不需要猜下一步——直接截图本页连订单号一起发给客服。
*/
const renderBindingConfirmedNotice = (options: {
refreshLabel: string
onRefresh: () => void
}) => (
<div className="customer-binding-verify">
<p className="customer-binding-verify-title">绑定已确认</p>
<p className="customer-binding-verify-desc">
请截图本页,把订单号和这张截图发给客服,客服会按截图核对并继续处理。
</p>
<div className="customer-binding-order-no">
<span>订单号</span>
<strong>{orderNo || selectedTask?.orderNo || ''}</strong>
<Button
size="small"
icon={<CopyOutlined />}
onClick={() => void copyOrderNoForSupport('订单号已复制,请连同截图一起发给客服')}
>
复制订单号
</Button>
</div>
<Button
block
size="large"
className="customer-login-alt"
loading={bindingLoading}
onClick={options.onRefresh}
>
{options.refreshLabel}
</Button>
</div>
)
const displayTitle = isWeibo ? '登录并绑定微博游戏角色' : '绑定游戏角色'
const loginQrVisible =
Boolean(selectedTask) && ['qr_pending', 'scanned'].includes(selectedTask.loginStatus)
@@ -1077,31 +1129,36 @@ export default function CustomerFulfillmentPage({
const rebindCooldownDays = Number(bindingInfo?.rebindCooldownDays || 0)
const rebindCooldownText =
rebindCooldownDays > 0 ? `当前仍处于虎牙换绑冷却期,剩余约 ${rebindCooldownDays} 天` : ''
// 微博页不涉及虎牙,冷却口径相同但文案不写虎牙。
const weiboRebindCooldownText =
rebindCooldownDays > 0 ? `当前角色仍在换绑冷却期,剩余约 ${rebindCooldownDays} 天` : ''
// 微博页不涉及虎牙,冷却口径相同但文案不写虎牙。天数只认后端 rebindCooldownDays:
// 平台在「还没有绑定角色」时允许首次绑定,这种场景不算冷却,按钮必须保持可用。
const weiboBoundRoleName = String(
bindingInfo?.bindGameRole || selectedTask?.bindGameRole || '',
).trim()
const weiboRebindCooldownBlocked = rebindCooldownDays > 0 && Boolean(weiboBoundRoleName)
const weiboRebindCooldownText = weiboRebindCooldownBlocked
? `当前角色仍在换绑冷却期,剩余约 ${rebindCooldownDays} 天,冷却结束后才能换绑`
: ''
// 虎牙账号/目标角色仍在换绑冷却期:后端已不再给「重新扫码换绑」,页面只提供只读刷新。
const isRebindBlocked =
bindingDecision?.flowState === 'rebind_blocked_account' ||
bindingDecision?.flowState === 'rebind_blocked_target_role'
const canRefreshBindingState = decisionCanRefreshBinding || isRebindBlocked
// 失败原因按「平台确认原因 → 任务原因 → 决策消息」去重,同一句只打印一次。
const bindingFailureReasons = (() => {
const seen = new Set<string>()
const reasons: string[] = []
const push = (value: string | null | undefined) => {
const text = String(value || '').trim()
if (!text || seen.has(text)) return
seen.add(text)
reasons.push(text)
}
push(bindingInfo?.bindConfirmMessage)
push(selectedTask?.bindConfirmMessage)
push(bindingInfo?.rebindConfirmMessage)
push(bindingDecision?.message)
push(selectedTask?.lastError)
return reasons
})()
const bindingFailureReasons = collectBindingFailureReasons([
bindingInfo?.bindConfirmMessage,
selectedTask?.bindConfirmMessage,
bindingInfo?.rebindConfirmMessage,
bindingDecision?.message,
selectedTask?.lastError,
])
// 微博绑定区同一口径:任务 lastError 已在 bindingFailureReasons 里,
// 这里再补上本次请求抛错(例如换绑冷却拒绝)与平台给出的失败消息,
// 保证它们留在页面上的展示位,而不是只弹一条会消失的 toast。
const weiboBindingFailureReasons = collectBindingFailureReasons([
...bindingFailureReasons,
bindingLoadError,
selectedTask?.bindingStatus === 'failed' ? bindingInfo?.message : '',
])
// 只有角色名缺失时才需要人工核实;加密 role token 不再冒充客户游戏角色 UID。
const bindingRequiresSupport = Boolean(
bindingDecision?.requiresSupport || bindingInfo?.requiresSupport,
@@ -1570,6 +1627,25 @@ export default function CustomerFulfillmentPage({
</div>
</div>
) : null}
{/* 失败原因与虎牙同一口径:平台原因 + 任务 lastError + 本次请求抛错,去重后逐条展示。 */}
{weiboBindingFailureReasons.length ? (
<Alert
type="error"
showIcon
message="绑定未成功,原因如下"
description={
<Space direction="vertical" size={2}>
{weiboBindingFailureReasons.map((reason) => (
<span key={reason}>{reason}</span>
))}
</Space>
}
/>
) : null}
{/* 冷却提示放在绑定按钮上方:天数只来自后端 rebindCooldownDays。 */}
{weiboRebindCooldownText ? (
<Alert type="warning" showIcon message={weiboRebindCooldownText} />
) : null}
{bindingInfo?.qrImage ? (
<div className="customer-binding-qr-card">
<Image
@@ -1602,23 +1678,13 @@ export default function CustomerFulfillmentPage({
description="请重新选择微信或 QQ 获取新的绑定二维码。"
/>
) : null}
{bindingLoadError ? (
<Alert
type="error"
showIcon
message={bindingLoadError}
description={bindingInfo?.message}
/>
) : selectedTask.bindingStatus === 'failed' && bindingInfo?.message ? (
<Alert type="error" showIcon message={bindingInfo.message} />
) : null}
<Space direction="vertical" size={10} style={{ width: '100%' }}>
<Button
block
size="large"
type="primary"
loading={bindingLoading}
disabled={bindingSessionExpired}
disabled={bindingSessionExpired || weiboRebindCooldownBlocked}
onClick={() => void handleStartWeiboBinding('wx')}
>
微信绑定
@@ -1627,11 +1693,12 @@ export default function CustomerFulfillmentPage({
block
size="large"
loading={bindingLoading}
disabled={bindingSessionExpired}
disabled={bindingSessionExpired || weiboRebindCooldownBlocked}
onClick={() => void handleStartWeiboBinding('qq')}
>
QQ 绑定
</Button>
{/* 「刷新角色状态」始终可用:冷却只限制换绑,不限制查看当前角色。 */}
<Button
block
size="large"
@@ -1645,9 +1712,6 @@ export default function CustomerFulfillmentPage({
</Space>
</div>
)}
{weiboRebindCooldownText ? (
<Alert type="info" showIcon message={weiboRebindCooldownText} />
) : null}
</section>
) : null}
@@ -2046,61 +2110,28 @@ export default function CustomerFulfillmentPage({
</Space>
) : null}
{bindingDecision?.flowState === 'confirmed' && !profileEditing ? (
<div className="customer-binding-verify">
<p className="customer-binding-verify-title">绑定已确认</p>
<p className="customer-binding-verify-desc">
请截图本页,把订单号和这张截图发给客服,客服会按截图核对并继续处理。
</p>
<div className="customer-binding-order-no">
<span>订单号</span>
<strong>{orderNo || selectedTask?.orderNo || ''}</strong>
<Button
size="small"
icon={<CopyOutlined />}
onClick={() =>
void copyOrderNoForSupport('订单号已复制,请连同截图一起发给客服')
}
>
复制订单号
</Button>
</div>
<Button
block
size="large"
className="customer-login-alt"
loading={bindingLoading}
onClick={() => {
{bindingDecision?.flowState === 'confirmed' && !profileEditing
? renderBindingConfirmedNotice({
refreshLabel: '刷新订单状态',
onRefresh: () => {
setBindingLoading(true)
void load(true).finally(() => setBindingLoading(false))
}}
>
刷新订单状态
</Button>
</div>
) : null}
},
})
: null}
</section>
) : null}
{/* 微博确认后的引导与虎牙完全同一段渲染,只换刷新文案。 */}
{isWeibo &&
selectedTask?.loginStatus === 'authenticated' &&
selectedTask.bindingStatus === 'confirmed' &&
selectedTask.executionStatus !== 'completed' ? (
<div className="customer-auth-state is-waiting">
<div className="customer-auth-state-icon">
<LoadingOutlined spin />
</div>
<h2>客服正在安排</h2>
<p>请耐心等待</p>
<Button
className="customer-auth-secondary-button"
icon={<ReloadOutlined />}
onClick={() => void load()}
>
刷新状态
</Button>
</div>
) : null}
selectedTask.executionStatus !== 'completed'
? renderBindingConfirmedNotice({
refreshLabel: '刷新状态',
onRefresh: () => void load(),
})
: null}
<HuyaChallengeModal
open={Boolean(huyaChallenge)}
@@ -21,20 +21,37 @@ function pickSlice(startMarker: string, endMarker: string) {
}
test('确认成功区块引导客户截图并发给客服,同时给出可复制订单号', () => {
const block = pickSlice(
// 文案与订单号复制只写一份:两个平台共用同一个渲染函数。
const shared = pickSlice('const renderBindingConfirmedNotice = (options: {', 'const displayTitle')
assert.ok(shared.includes('绑定已确认'))
assert.ok(shared.includes('请截图本页'))
assert.ok(shared.includes('发给客服'))
assert.ok(shared.includes('订单号'))
// 订单号直接取页面已有的 orderNo / task.orderNo,不另建字段。
assert.ok(shared.includes('{orderNo || selectedTask?.orderNo || '))
assert.ok(shared.includes('copyOrderNoForSupport('))
assert.ok(shared.includes('{options.refreshLabel}'))
// 页面里「请截图本页」只出现一次,不能再复制出第二套文案。
assert.equal(source.split('请截图本页').length - 1, 1)
const huyaBlock = pickSlice(
"bindingDecision?.flowState === 'confirmed' && !profileEditing",
'{isWeibo &&',
)
assert.ok(block.includes('绑定已确认'))
assert.ok(block.includes('截图'))
assert.ok(block.includes('发给客服'))
assert.ok(block.includes('刷新订单状态'))
assert.ok(block.includes('订单号'))
// 订单号直接取页面已有的 orderNo / task.orderNo,不另建字段。
assert.ok(block.includes('{orderNo || selectedTask?.orderNo || '))
assert.ok(block.includes('copyOrderNoForSupport('))
assert.ok(huyaBlock.includes('renderBindingConfirmedNotice({'))
assert.ok(huyaBlock.includes("refreshLabel: '刷新订单状态'"))
assert.ok(!huyaBlock.includes('请截图本页'))
// 微博 confirmed 与其他平台完全同一个渲染,只换刷新按钮文案。
assert.equal(source.split('renderBindingConfirmedNotice({').length - 1, 2)
assert.ok(source.includes("refreshLabel: '刷新状态'"))
assert.ok(source.includes("selectedTask.bindingStatus === 'confirmed'"))
// 旧文案已被替换。
assert.ok(!source.includes('平台角色绑定已确认,客服正在处理订单'))
assert.ok(!source.includes('客服正在安排'))
assert.ok(!source.includes('请耐心等待'))
})
test('确认按钮不吞掉重新扫码与修改资料两个退回入口', () => {
@@ -0,0 +1,100 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import test from 'node:test'
const root = dirname(fileURLToPath(import.meta.url))
const source = readFileSync(
join(root, '../src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx'),
'utf8',
)
/** 取样一段源码,找不到时直接失败,避免测试静默通过。 */
function pickSlice(startMarker: string, endMarker: string) {
const start = source.indexOf(startMarker)
assert.ok(start >= 0, `源码缺少 ${startMarker}`)
const end = source.indexOf(endMarker, start)
assert.ok(end > start, `源码缺少 ${endMarker}`)
return source.slice(start, end)
}
const weiboBindingCard = () => pickSlice('{showWeiboBindingStage ? (', '{showBindingStage ? (')
test('换绑冷却天数只来自后端 rebindCooldownDays,不用其它字段推算', () => {
// 页面内冷却天数只有一个来源。
assert.ok(
source.includes('const rebindCooldownDays = Number(bindingInfo?.rebindCooldownDays || 0)'),
)
assert.equal(source.split('rebindCooldownDays =').length - 1, 1)
// 不得从平台规则字段或原始天数推算「从现在起还剩几天」。
assert.ok(!source.includes('rebindRemainDays'))
assert.ok(!source.includes('rebindCooldownDays + '))
assert.ok(!source.includes('rebindCooldownDays - '))
assert.ok(!/(platformChangeBindDay|platformChangeBindTime)[^\n]*rebindCooldownDays/.test(source))
assert.ok(!/rebindCooldownDays[^\n]*(platformChangeBindDay|platformChangeBindTime)/.test(source))
})
test('冷却天数 > 0 且已有绑定角色时微信/QQ 按钮 disabled,刷新角色状态仍可用', () => {
const cooldown = pickSlice('const weiboBoundRoleName', 'const isRebindBlocked')
// 判断条件 = 后端天数 > 0 且已经有绑定角色,天数本身直接来自 rebindCooldownDays。
assert.ok(cooldown.includes('bindingInfo?.bindGameRole || selectedTask?.bindGameRole'))
assert.ok(
cooldown.includes(
'const weiboRebindCooldownBlocked = rebindCooldownDays > 0 && Boolean(weiboBoundRoleName)',
),
)
// 文案:剩余约 N 天 + 冷却结束后才能换绑,N 只来自 rebindCooldownDays。
assert.ok(
cooldown.includes(
'当前角色仍在换绑冷却期,剩余约 ${rebindCooldownDays} 天,冷却结束后才能换绑',
),
)
const card = weiboBindingCard()
// 微信绑定 / QQ 绑定两个按钮都受冷却门禁约束。
assert.equal(
card.split('disabled={bindingSessionExpired || weiboRebindCooldownBlocked}').length - 1,
2,
)
const wxStart = card.indexOf('微信绑定')
const qqStart = card.indexOf('QQ 绑定')
assert.ok(wxStart > 0 && qqStart > wxStart)
// 冷却提示必须在两个绑定按钮之前(按钮上方)。
const cooldownNotice = card.indexOf('weiboRebindCooldownText ? (')
assert.ok(cooldownNotice > 0)
assert.ok(cooldownNotice < card.indexOf("handleStartWeiboBinding('wx')"))
// 「刷新角色状态」始终可用:只受登录会话影响,不受冷却影响。
const refreshStart = card.lastIndexOf('刷新角色状态')
assert.ok(refreshStart > 0)
const refreshButton = card.slice(card.lastIndexOf('<Button', refreshStart), refreshStart)
assert.ok(refreshButton.includes('disabled={bindingSessionExpired}'))
assert.ok(!refreshButton.includes('weiboRebindCooldownBlocked'))
assert.ok(refreshButton.includes('onClick={() => void handlePollBindingNow()}'))
})
test('微博绑定失败原因同时展示平台原因与任务 lastError,且同一句不重复', () => {
// 任务 lastError 与平台原因统一由去重收集器完成。
const collected = pickSlice(
'const bindingFailureReasons = collectBindingFailureReasons([',
'const weiboBindingFailureReasons',
)
assert.ok(collected.includes('bindingInfo?.bindConfirmMessage'))
assert.ok(collected.includes('bindingDecision?.message'))
assert.ok(collected.includes('selectedTask?.lastError'))
// 微信/QQ 绑定抛错(如冷却拒绝)写进 bindingLoadError,和平台原因共用同一个展示位。
const weiboReasons = pickSlice('const weiboBindingFailureReasons', 'const bindingRequiresSupport')
assert.ok(weiboReasons.includes('...bindingFailureReasons'))
assert.ok(weiboReasons.includes('bindingLoadError'))
const card = weiboBindingCard()
assert.ok(card.includes('weiboBindingFailureReasons.length'))
assert.ok(card.includes('weiboBindingFailureReasons.map((reason) => ('))
// 不再用单条瞬时提示代替失败原因展示。
assert.ok(!card.includes('message={bindingLoadError}'))
assert.ok(!card.includes('description={bindingInfo?.message}'))
// 去重逻辑只有一份(页面与微博区共用同一函数)。
assert.equal(source.split('const seen = new Set<string>()').length - 1, 1)
assert.ok(source.includes('function collectBindingFailureReasons('))
})
@@ -387,9 +387,13 @@ manual fulfillment
`data.game_role.is_bound / role_name / can_rebind / rebind_remain_days / bind_url`;
③ `is_bound = false` 时使用 `bind_url` 通过来联生成微信或 QQ 小程序绑定二维码,
`is_bound = true` 且角色名变化后才收敛为 `binding_status = confirmed`;
④ 已绑定且 `can_rebind = false` 时不得生成换绑二维码,必须展示冷却剩余天数;
④ 已绑定且 `can_rebind = false` 时不得生成换绑二维码,必须展示冷却剩余天数
(天数只取平台 `rebind_remain_days`,客户页在冷却期内禁用「微信绑定 / QQ 绑定」,不得自行推算);
⑤ 绑定二维码是 10 分钟短期会话状态,不单独落库;Connector 重启后以账号级 CK 恢复会话并重新查询
`game_role`,已绑定事实照常确认,未绑定事实回到重新生成二维码。
`game_role`,已绑定事实照常确认,未绑定事实回到重新生成二维码;
⑥ 与虎牙同口径:换绑被平台冷却拒绝时必须把原因写进 `last_error` 并追加
`weibo_binding_rejected` 事件,客户页要能看到同一句原因;绑定确认后客户页直接展示
「绑定已确认 + 截图本页连同订单号发给客服」,不再展示进度文案让客户自行猜测。
- 斗鱼客户领取页只允许通过订单级 SSE 接收“需要重读”的瞬态信号,不得固定秒级轮询绑定状态。
SSE 不携带订单、角色或 CK 快照;页面收到信号或断线重连后,重新读取 `/api/v1/douyu-fulfillment/<订单号>`
的权威快照。live-hub 快照字段没有实际变化时不得重复广播,避免读接口与 SSE 自激循环。