feat: 微信审核回调支持跨环境转发与补偿重试
This commit is contained in:
@@ -1594,11 +1594,27 @@ export interface SecureIntegrationConfigVO {
|
||||
wechatMiniAppConfigured: boolean
|
||||
wechatMiniAppId: string
|
||||
mockProviderAllowed: boolean
|
||||
moderationForwardEnabled?: boolean
|
||||
moderationForwardTargets?: Record<string, string>
|
||||
moderationForwardSecretConfigured?: boolean
|
||||
moderationForwardRecent?: ModerationForwardRecordVO[]
|
||||
encryptionKeyConfigured: boolean
|
||||
updatedAt?: string
|
||||
probeResults?: IntegrationProbeResultVO[]
|
||||
}
|
||||
|
||||
export interface ModerationForwardRecordVO {
|
||||
id: IdType
|
||||
traceId: string
|
||||
sourceEnv?: string
|
||||
targetEnv?: string
|
||||
status: 'PENDING' | 'SUCCESS' | 'RETRY' | 'FAILED' | 'NO_ENV' | 'TARGET_MISSING' | string
|
||||
retryCount?: number
|
||||
lastError?: string
|
||||
createdAt?: string
|
||||
updatedAt?: string
|
||||
}
|
||||
|
||||
export interface IntegrationProbeCheckVO {
|
||||
name: string
|
||||
status: 'PASS' | 'WARN' | 'FAIL' | 'PENDING'
|
||||
@@ -1640,6 +1656,10 @@ export interface SecureIntegrationConfigUpdate {
|
||||
moderationEncodingAesKey?: string
|
||||
clearModerationCallbackToken?: boolean
|
||||
clearModerationEncodingAesKey?: boolean
|
||||
moderationForwardEnabled?: boolean
|
||||
moderationForwardTargets?: Record<string, string>
|
||||
moderationForwardSecret?: string
|
||||
clearModerationForwardSecret?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1664,7 +1684,8 @@ export const adminSecureIntegrationConfigApi = {
|
||||
probe: (data: IntegrationProbeRequest) => adminApi.post<IntegrationProbeResultVO>('/system-settings/secure-integration/probe', data) as unknown as Promise<IntegrationProbeResultVO>,
|
||||
getMapRuntimeConfig: () => adminApi.get<{ provider: 'TENCENT' | 'AMAP'; enabled: string; key: string }>('/system-settings/secure-integration/map-runtime') as unknown as Promise<{ provider: 'TENCENT' | 'AMAP'; enabled: string; key: string }>,
|
||||
saveMapConfig: (data: SecureIntegrationConfigUpdate) => adminApi.post<SecureIntegrationConfigVO>('/system-settings/secure-integration/map', data) as unknown as Promise<SecureIntegrationConfigVO>,
|
||||
saveModerationConfig: (data: SecureIntegrationConfigUpdate) => adminApi.post<SecureIntegrationConfigVO>('/system-settings/secure-integration/content-moderation', data) as unknown as Promise<SecureIntegrationConfigVO>
|
||||
saveModerationConfig: (data: SecureIntegrationConfigUpdate) => adminApi.post<SecureIntegrationConfigVO>('/system-settings/secure-integration/content-moderation', data) as unknown as Promise<SecureIntegrationConfigVO>,
|
||||
saveModerationForwardConfig: (data: SecureIntegrationConfigUpdate) => adminApi.post<SecureIntegrationConfigVO>('/system-settings/secure-integration/content-moderation-forward', data) as unknown as Promise<SecureIntegrationConfigVO>
|
||||
}
|
||||
|
||||
export interface WorkbenchRegistrationApplication {
|
||||
|
||||
@@ -306,6 +306,61 @@
|
||||
<span v-else-if="secureStatus && !secureStatus.moderationCallbackReady" class="control-note">回调资料仍不完整,暂时不能进行微信 URL 验证。</span>
|
||||
<span v-if="secureStatus && !secureStatus.encryptionKeyConfigured" class="secure-note__warning">安全接入加密主密钥尚未配置,Token 与 AESKey 不会保存。</span>
|
||||
</div>
|
||||
|
||||
<div class="settings-subsection">
|
||||
<div class="settings-subsection__head">
|
||||
<div>
|
||||
<strong>跨环境回调转发</strong>
|
||||
<span class="tag">CROSS ENV</span>
|
||||
<p class="control-note">微信只向一个环境推送异步图片审核结果;命中不到本地任务时,按回调 extra 中的部署环境标识转发到真正创建任务的环境。默认关闭。</p>
|
||||
</div>
|
||||
<a-button size="small" :loading="savingModerationForward" @click="saveModerationForwardConfig">保存转发设置</a-button>
|
||||
</div>
|
||||
<div class="field-grid cols-2">
|
||||
<article class="field">
|
||||
<div class="field__head"><span class="field__label">启用跨环境转发</span></div>
|
||||
<p class="field__desc">关闭时未命中本地任务的回调只记录不转发。</p>
|
||||
<div class="field__control"><a-switch v-model:checked="moderationForwardEnabled" /></div>
|
||||
<div class="field__foot">
|
||||
<span class="status-pill" :class="{ 'is-muted': !moderationForwardEnabled }">{{ moderationForwardEnabled ? '已启用' : '未启用' }}</span>
|
||||
</div>
|
||||
</article>
|
||||
<article class="field">
|
||||
<div class="field__head"><span class="field__label">共享密钥</span></div>
|
||||
<p class="field__desc">16-128 位,仅用于服务端 HMAC-SHA256 转发验签,不写日志;各环境需配置相同密钥。</p>
|
||||
<div class="field__control field__control--password">
|
||||
<a-input-password v-model:value="moderationForwardSecret" autocomplete="new-password" :placeholder="secureStatus?.moderationForwardSecretConfigured && !clearModerationForwardSecret ? '••••••••' : '填写共享密钥,留空保持原值'" @update:value="clearModerationForwardSecret = false" />
|
||||
<a-button v-if="secureStatus?.moderationForwardSecretConfigured" size="small" type="text" danger @click="clearModerationForwardSecret = !clearModerationForwardSecret">{{ clearModerationForwardSecret ? '撤销清除' : '清除' }}</a-button>
|
||||
</div>
|
||||
<div class="field__foot">
|
||||
<span class="status-pill" :class="{ 'is-muted': !secureStatus?.moderationForwardSecretConfigured || clearModerationForwardSecret }">{{ clearModerationForwardSecret ? '保存后清除' : secureStatus?.moderationForwardSecretConfigured ? '已配置' : '待配置' }}</span>
|
||||
</div>
|
||||
</article>
|
||||
<article v-for="env in forwardEnvTargets" :key="env.key" class="field field--wide">
|
||||
<div class="field__head"><span class="field__label">{{ env.label }}回调地址</span></div>
|
||||
<p class="field__desc">必须精确指向 /api/integration/wechat/content-moderation/callback;HTTP 仅允许内网主机。</p>
|
||||
<div class="field__control">
|
||||
<a-input v-model:value="moderationForwardTargets[env.key]" :placeholder="`例如 https://${env.key}.example.com/api/integration/wechat/content-moderation/callback`" />
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<div class="forward-recent">
|
||||
<div class="forward-recent__head">
|
||||
<strong>最近转发结果</strong>
|
||||
<span class="control-note">NO_ENV / TARGET_MISSING 不自动重试,补齐配置或人工处理后可重放。</span>
|
||||
</div>
|
||||
<div v-if="!(secureStatus?.moderationForwardRecent || []).length" class="control-note">暂无转发记录</div>
|
||||
<ul v-else class="forward-recent__list">
|
||||
<li v-for="item in secureStatus?.moderationForwardRecent" :key="String(item.id)">
|
||||
<span class="status-pill" :class="{ 'is-muted': item.status !== 'SUCCESS' }">{{ forwardStatusLabel(item.status) }}</span>
|
||||
<span class="forward-recent__env">{{ item.sourceEnv || '-' }} → {{ item.targetEnv || '-' }}</span>
|
||||
<span class="forward-recent__trace" :title="item.traceId">{{ item.traceId }}</span>
|
||||
<span class="forward-recent__time">{{ formatProbeTime(item.createdAt) }}</span>
|
||||
<span v-if="item.lastError" class="forward-recent__error">{{ item.lastError }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -473,6 +528,16 @@ const moderationProvider = ref<'DISABLED' | 'MOCK' | 'WECHAT'>('DISABLED')
|
||||
const moderationCallbackUrl = ref('')
|
||||
const moderationSecrets = reactive({ callbackToken: '', encodingAesKey: '' })
|
||||
const clearModerationSecrets = reactive({ callbackToken: false, encodingAesKey: false })
|
||||
const moderationForwardEnabled = ref(false)
|
||||
const moderationForwardTargets = reactive<Record<'dev' | 'sit' | 'prod', string>>({ dev: '', sit: '', prod: '' })
|
||||
const moderationForwardSecret = ref('')
|
||||
const clearModerationForwardSecret = ref(false)
|
||||
const savingModerationForward = ref(false)
|
||||
const forwardEnvTargets = [
|
||||
{ key: 'dev' as const, label: 'DEV' },
|
||||
{ key: 'sit' as const, label: 'SIT' },
|
||||
{ key: 'prod' as const, label: 'PROD' }
|
||||
]
|
||||
const smsProviderOptions = [
|
||||
{ label: 'Spug 短信', value: 'SPUG' },
|
||||
{ label: '阿里云短信认证服务', value: 'ALIYUN_SMS_VERIFY' }
|
||||
@@ -630,6 +695,12 @@ const load = async () => {
|
||||
mapEnabled.value = Boolean(secureConfig.mapEnabled)
|
||||
moderationProvider.value = secureConfig.moderationProvider || 'DISABLED'
|
||||
moderationCallbackUrl.value = secureConfig.moderationCallbackUrl || defaultCallbackUrl()
|
||||
moderationForwardEnabled.value = Boolean(secureConfig.moderationForwardEnabled)
|
||||
moderationForwardTargets.dev = secureConfig.moderationForwardTargets?.dev || ''
|
||||
moderationForwardTargets.sit = secureConfig.moderationForwardTargets?.sit || ''
|
||||
moderationForwardTargets.prod = secureConfig.moderationForwardTargets?.prod || ''
|
||||
moderationForwardSecret.value = ''
|
||||
clearModerationForwardSecret.value = false
|
||||
mapSecrets.tencentWeb = ''
|
||||
mapSecrets.amapWeb = ''
|
||||
mapSecrets.amapMini = ''
|
||||
@@ -955,6 +1026,46 @@ const saveModerationConfig = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const forwardStatusLabel = (status?: string) => ({
|
||||
PENDING: '待转发', SUCCESS: '已转发', RETRY: '待重试', FAILED: '失败',
|
||||
NO_ENV: '无法认领', TARGET_MISSING: '目标未配置'
|
||||
} as Record<string, string>)[status || ''] || '未知'
|
||||
|
||||
const saveModerationForwardConfig = async () => {
|
||||
if (moderationForwardSecret.value && !/^[A-Za-z0-9+/=_\-]{16,128}$/.test(moderationForwardSecret.value)) {
|
||||
message.warning('共享密钥需要为 16-128 位字母、数字或常用符号')
|
||||
return
|
||||
}
|
||||
if (moderationForwardEnabled.value) {
|
||||
const hasSecret = moderationForwardSecret.value.trim()
|
||||
|| (secureStatus.value?.moderationForwardSecretConfigured && !clearModerationForwardSecret.value)
|
||||
if (!hasSecret) {
|
||||
message.warning('启用跨环境转发前,请填写共享密钥')
|
||||
return
|
||||
}
|
||||
if (!Object.values(moderationForwardTargets).some(value => value.trim())) {
|
||||
message.warning('启用跨环境转发前,至少填写一个目标环境地址')
|
||||
return
|
||||
}
|
||||
}
|
||||
savingModerationForward.value = true
|
||||
try {
|
||||
secureStatus.value = await adminSecureIntegrationConfigApi.saveModerationForwardConfig({
|
||||
moderationForwardEnabled: moderationForwardEnabled.value,
|
||||
moderationForwardTargets: { ...moderationForwardTargets },
|
||||
moderationForwardSecret: moderationForwardSecret.value,
|
||||
clearModerationForwardSecret: clearModerationForwardSecret.value
|
||||
})
|
||||
moderationForwardSecret.value = ''
|
||||
clearModerationForwardSecret.value = false
|
||||
message.success('跨环境转发设置已保存')
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '跨环境转发设置保存失败')
|
||||
} finally {
|
||||
savingModerationForward.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const toggleMapSecretClear = (key: MapKey) => { clearMapSecrets[key] = !clearMapSecrets[key] }
|
||||
const toggleModerationSecretClear = (key: 'callbackToken' | 'encodingAesKey') => { clearModerationSecrets[key] = !clearModerationSecrets[key] }
|
||||
|
||||
@@ -1174,5 +1285,59 @@ onMounted(() => {
|
||||
.svc__desc { white-space: normal; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
|
||||
.field__save { margin-left: 0; }
|
||||
}
|
||||
.settings-subsection {
|
||||
margin-top: 18px;
|
||||
padding-top: 16px;
|
||||
border-top: 1px dashed var(--border-color, #e5e7eb);
|
||||
}
|
||||
.settings-subsection__head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.settings-subsection__head strong { font-size: 14px; }
|
||||
.settings-subsection__head .tag { margin-left: 8px; }
|
||||
.settings-subsection__head p { margin: 4px 0 0; }
|
||||
.forward-recent { margin-top: 14px; }
|
||||
.forward-recent__head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.forward-recent__list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
.forward-recent__list li {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 7px 10px;
|
||||
border: 1px solid var(--border-color, #e5e7eb);
|
||||
border-radius: 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.forward-recent__trace {
|
||||
flex: 1 1 180px;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
}
|
||||
.forward-recent__time { color: var(--text-color-secondary, #6b7280); }
|
||||
.forward-recent__error { color: var(--danger-color, #c0392b); }
|
||||
@media (max-width: 760px) {
|
||||
.settings-subsection__head { flex-direction: column; align-items: stretch; }
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user