安全接入配置改造回溯点
自动发布开发环境 Nacos 配置 / publish (push) Successful in 27s

This commit is contained in:
2026-10-30 17:08:00 +08:00
parent 7b9a5e4d1c
commit 9a2c158fdd
29 changed files with 928 additions and 121 deletions
@@ -102,17 +102,17 @@
<div class="pane-head">
<div>
<h2>服务接入</h2>
<p>维护后台地图选点和短信验证码使用的服务渠道。</p>
<p>维护加密保存的地图密钥、微信审核回调和短信服务渠道。</p>
</div>
<span />
</div>
<div class="setting-group">
<div class="setting-group__head setting-group__head--with-action"><strong>地图服务</strong><span>MAP</span><a-button size="small" type="primary" :loading="savingMap" @click="saveMapConfig">保存地图设置</a-button></div>
<div class="setting-group__head setting-group__head--with-action"><strong>地图服务</strong><span>安全接入</span><a-button size="small" type="primary" :loading="savingMap" @click="saveMapConfig">保存地图设置</a-button></div>
<div class="setting-row">
<div class="setting-copy"><strong>默认地图渠道</strong><span>店铺选点和后台地图展示使用的默认渠道。</span></div>
<div class="setting-control"><a-select v-model:value="mapForms.provider.configValue" :options="mapProviderOptions" /></div>
<span class="status-pill">{{ mapEnabled ? '已配置' : '停用' }}</span>
<div class="setting-control"><a-select v-model:value="mapProvider" :options="mapProviderOptions" /></div>
<span class="status-pill" :class="{ 'is-muted': !mapEnabled }">{{ mapEnabled ? '启用' : '停用' }}</span>
</div>
<div v-for="item in mapKeyRows" :key="item.key" class="setting-row">
<div class="setting-copy">
@@ -131,14 +131,65 @@
</strong>
<span>{{ item.description }}</span>
</div>
<div class="setting-control setting-control--password"><a-input-password v-model:value="mapForms[item.key].configValue" :placeholder="item.placeholder" /></div>
<span class="status-pill" :class="{ 'is-muted': !mapForms[item.key].configValue }">{{ mapForms[item.key].configValue ? '已填写' : '待配置' }}</span>
<div class="setting-control setting-control--password">
<a-input-password v-model:value="mapSecrets[item.key]" :placeholder="item.placeholder" autocomplete="new-password" />
<a-button v-if="mapConfigured(item.key)" size="small" type="text" danger @click="toggleMapSecretClear(item.key)">{{ clearMapSecrets[item.key] ? '撤销清除' : '清除' }}</a-button>
</div>
<span class="status-pill" :class="{ 'is-muted': !mapConfigured(item.key) || clearMapSecrets[item.key] }">{{ clearMapSecrets[item.key] ? '保存后清除' : mapConfigured(item.key) ? '已配置' : '待配置' }}</span>
</div>
<div class="setting-row setting-row--last">
<div class="setting-copy"><strong>地图服务状态</strong><span>停用后店铺地图选点不会调用已保存的渠道。</span></div>
<div class="setting-control"><a-switch v-model:checked="mapEnabled" checked-children="启用" un-checked-children="停用" /></div>
<span :class="['status-pill', { 'is-muted': !mapEnabled }]">{{ mapEnabled ? '启用' : '停用' }}</span>
</div>
<p class="secure-note">密钥以 AES-256-GCM 加密保存在当前环境数据库,设置接口不回传密钥。地图打开时才通过管理员认证接口按当前渠道读取;Web Key 会在浏览器地图 SDK 请求中使用,请在地图开放平台限制可用域名,并为 DEV、SIT、PROD 分别创建 Key。<span v-if="secureStatus && !secureStatus.encryptionKeyConfigured" class="secure-note__warning">服务端加密主密钥尚未配置,需先由部署维护人员设置后才能保存。</span></p>
</div>
<div class="setting-group">
<div class="setting-group__head setting-group__head--with-action"><strong>微信内容审核</strong><span>安全回调</span><a-button size="small" type="primary" :loading="savingModeration" @click="saveModerationConfig">保存审核设置</a-button></div>
<div class="setting-row">
<div class="setting-copy"><strong>审核渠道</strong><span>未启用或配置不完整时,内容保持隔离,不会自动放行。</span></div>
<div class="setting-control"><a-select v-model:value="moderationProvider" :options="moderationProviderOptions" /></div>
<span class="status-pill" :class="{ 'is-muted': !secureStatus?.moderationReady }">{{ secureStatus?.moderationReady ? '已就绪' : '待配置' }}</span>
</div>
<div class="setting-row">
<div class="setting-copy"><strong>微信服务器回调 URL</strong><span>复制到微信公众平台「开发管理 → 开发设置 → 消息推送」的 URL。</span></div>
<div class="setting-control setting-control--joined">
<a-input v-model:value="moderationCallbackUrl" readonly />
<a-button @click="copyCallbackUrl"><CopyOutlined />复制</a-button>
</div>
<span class="status-pill" :class="{ 'is-muted': !isPublicHttpsCallback }">{{ isPublicHttpsCallback ? '当前环境 HTTPS' : '本地地址不可验证' }}</span>
</div>
<div class="setting-row">
<div class="setting-copy"><strong>回调 Token</strong><span>在微信消息推送配置中填写的 Token,留空表示不修改已保存值。</span></div>
<div class="setting-control setting-control--password">
<a-input-password v-model:value="moderationSecrets.callbackToken" autocomplete="new-password" placeholder="填写新的 Token,留空保持原值" />
<a-button v-if="secureStatus?.moderationCallbackTokenConfigured" size="small" type="text" danger @click="toggleModerationSecretClear('callbackToken')">{{ clearModerationSecrets.callbackToken ? '撤销清除' : '清除' }}</a-button>
</div>
<span class="status-pill" :class="{ 'is-muted': !secureStatus?.moderationCallbackTokenConfigured || clearModerationSecrets.callbackToken }">{{ clearModerationSecrets.callbackToken ? '保存后清除' : secureStatus?.moderationCallbackTokenConfigured ? '已配置' : '待配置' }}</span>
</div>
<div class="setting-row setting-row--last">
<div class="setting-copy"><strong>EncodingAESKey</strong><span>微信平台生成的 43 位密钥;消息加密方式必须选择「安全模式」。</span></div>
<div class="setting-control setting-control--password">
<a-input-password v-model:value="moderationSecrets.encodingAesKey" autocomplete="new-password" placeholder="填写 43 位 EncodingAESKey,留空保持原值" />
<a-button v-if="secureStatus?.moderationEncodingAesKeyConfigured" size="small" type="text" danger @click="toggleModerationSecretClear('encodingAesKey')">{{ clearModerationSecrets.encodingAesKey ? '撤销清除' : '清除' }}</a-button>
</div>
<span class="status-pill" :class="{ 'is-muted': !secureStatus?.moderationEncodingAesKeyConfigured || clearModerationSecrets.encodingAesKey }">{{ clearModerationSecrets.encodingAesKey ? '保存后清除' : secureStatus?.moderationEncodingAesKeyConfigured ? '已配置' : '待配置' }}</span>
</div>
<div class="secure-guide">
<strong>微信平台填写指引</strong>
<ol>
<li>进入小程序公众平台的「开发管理 → 开发设置 → 消息推送」,将上方 URL、Token、EncodingAESKey 填入对应项。</li>
<li>消息加密方式选择「安全模式」,保存后使用微信平台的 URL 验证;确认审核用 AppID 与当前环境小程序一致。</li>
<li>将此环境 Core 的公网出口 IP 加入小程序接口 IP 白名单;图片审核还要求对象存储签名 URL 可由微信公网 HTTPS 访问。</li>
</ol>
<div class="secure-guide__links">
<a href="https://mp.weixin.qq.com/" target="_blank" rel="noopener noreferrer">打开微信公众平台 <ExportOutlined /></a>
<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html" target="_blank" rel="noopener noreferrer">消息推送配置说明 <ExportOutlined /></a>
</div>
<span v-if="!isPublicHttpsCallback" class="secure-note__warning">当前地址为本地或非 HTTPS 地址,不能用于微信服务器验证。请在对应环境的正式 HTTPS 域名后台填写。</span>
<span v-if="secureStatus && !secureStatus.encryptionKeyConfigured" class="secure-note__warning">安全接入加密主密钥尚未配置,Token 与 AESKey 不会保存。</span>
</div>
</div>
<div class="setting-group">
@@ -185,11 +236,11 @@
</template>
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import { computed, onMounted, reactive, ref } from 'vue'
import { useRoute } from 'vue-router'
import { message } from 'ant-design-vue'
import { ApiOutlined, ExportOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons-vue'
import { adminSystemParameterConfigApi, type SystemParameterConfigVO } from '@/api/admin'
import { ApiOutlined, CopyOutlined, ExportOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons-vue'
import { adminSecureIntegrationConfigApi, adminSystemParameterConfigApi, type SecureIntegrationConfigVO, type SystemParameterConfigVO } from '@/api/admin'
import { loadCachedAdminUserInfo } from '@/utils/admin-session'
type SettingsSection = 'runtime' | 'services' | 'account'
@@ -203,12 +254,21 @@ const savingReviewNotice = ref(false)
const savingManagerReviewMode = ref(false)
const savingShopValidity = ref(false)
const savingMap = ref(false)
const savingModeration = ref(false)
const savingSmsProvider = ref(false)
const defaultPasswordEnabled = ref(true)
const reviewNoticeEnabled = ref(true)
const managerAutoApproveEnabled = ref(false)
const shopDefaultValidDays = ref('30')
const mapEnabled = ref(true)
const mapProvider = ref<'TENCENT' | 'AMAP'>('TENCENT')
const secureStatus = ref<SecureIntegrationConfigVO | null>(null)
const mapSecrets = reactive<Record<MapKey, string>>({ tencentWeb: '', amapWeb: '', amapMini: '' })
const clearMapSecrets = reactive<Record<MapKey, boolean>>({ tencentWeb: false, amapWeb: false, amapMini: false })
const moderationProvider = ref<'DISABLED' | 'MOCK' | 'WECHAT'>('DISABLED')
const moderationCallbackUrl = ref('')
const moderationSecrets = reactive({ callbackToken: '', encodingAesKey: '' })
const clearModerationSecrets = reactive({ callbackToken: false, encodingAesKey: false })
const smsProviderOptions = [
{ label: 'Spug 短信', value: 'SPUG' },
{ label: '阿里云短信认证服务', value: 'ALIYUN_SMS_VERIFY' }
@@ -217,15 +277,22 @@ const mapProviderOptions = [
{ label: '腾讯地图', value: 'TENCENT' },
{ label: '高德地图', value: 'AMAP' }
]
const moderationProviderOptions = computed(() => [
{ label: '未启用(失败关闭)', value: 'DISABLED' },
...(secureStatus.value?.mockProviderAllowed ? [{ label: '本地模拟审核', value: 'MOCK' as const }] : []),
{ label: '微信内容安全审核', value: 'WECHAT' }
])
const isPublicHttpsCallback = computed(() => /^https:\/\//i.test(moderationCallbackUrl.value)
&& !/localhost|127\.0\.0\.1/i.test(moderationCallbackUrl.value))
const sections = [
{ key: 'runtime' as const, label: '运行参数', icon: SettingOutlined },
{ key: 'services' as const, label: '服务接入', icon: ApiOutlined },
{ key: 'account' as const, label: '当前账号', icon: UserOutlined }
]
const mapKeyRows: Array<{ key: MapKey; label: string; description: string; placeholder: string; url: string }> = [
{ key: 'tencentWeb', label: '腾讯 Web Key', description: '用于后台腾讯地图选点和 Web 展示。', placeholder: '填写腾讯 Web Key', url: 'https://lbs.qq.com/dev/console/key/manage' },
{ key: 'amapWeb', label: '高德 Web Key', description: '用于后台高德地图选点和 Web 展示。', placeholder: '填写高德 Web Key', url: 'https://console.amap.com/dev/key/app' },
{ key: 'amapMini', label: '高德小程序 Key', description: '供 Salon 小程序后续地图能力使用。', placeholder: '填写高德小程序 Key', url: 'https://console.amap.com/dev/key/app' }
{ key: 'tencentWeb', label: '腾讯 Web Key', description: '用于后台腾讯地图选点。', placeholder: '填写腾讯 Web Key;留空保持原值', url: 'https://lbs.qq.com/dev/console/key/manage' },
{ key: 'amapWeb', label: '高德 Web Key', description: '用于后台高德地图选点。', placeholder: '填写高德 Web Key;留空保持原值', url: 'https://console.amap.com/dev/key/app' },
{ key: 'amapMini', label: '高德小程序 Key', description: '供 Salon 小程序地图能力使用。', placeholder: '填写高德小程序 Key;留空保持原值', url: 'https://console.amap.com/dev/key/app' }
]
const defaultPasswordForm = reactive<SystemParameterConfigVO>({
@@ -248,24 +315,28 @@ const smsProviderForm = reactive<SystemParameterConfigVO>({
configGroup: 'SMS', configKey: 'SMS_PROVIDER', configName: '短信供应商', configValue: 'SPUG', enabled: 1,
remark: '全局切换短信供应商时同步验证码模板和 MessageHub 通道'
})
const mapForms = reactive<Record<MapKey | 'provider', SystemParameterConfigVO>>({
provider: { configGroup: 'MAP', configKey: 'MAP_PROVIDER', configName: '当前地图渠道', configValue: 'TENCENT', enabled: 1, remark: 'TENCENT 或 AMAP;决定后台店铺选点默认使用哪个地图渠道' },
tencentWeb: { configGroup: 'MAP', configKey: 'TENCENT_MAP_KEY', configName: '腾讯 Web Key', configValue: '', enabled: 1, remark: '用于后台腾讯地图选点和 Web 展示' },
amapWeb: { configGroup: 'MAP', configKey: 'AMAP_WEB_KEY', configName: '高德 Web Key', configValue: '', enabled: 1, remark: '用于后台高德地图选点和 Web 展示' },
amapMini: { configGroup: 'MAP', configKey: 'AMAP_MINI_KEY', configName: '高德小程序 Key', configValue: '', enabled: 1, remark: '供 Salon 小程序地图能力使用' }
})
const userInfo = ref(loadCachedAdminUserInfo())
const callbackPath = '/api/integration/wechat/content-moderation/callback'
const defaultCallbackUrl = () => `${window.location.origin}${callbackPath}`
const mapConfigured = (key: MapKey) => {
if (clearMapSecrets[key]) return false
if (mapSecrets[key]) return true
if (!secureStatus.value) return false
return key === 'tencentWeb' ? secureStatus.value.tencentWebKeyConfigured
: key === 'amapWeb' ? secureStatus.value.amapWebKeyConfigured
: secureStatus.value.amapMiniKeyConfigured
}
const load = async () => {
loading.value = true
try {
const [userConfigs, smsConfigs, workbenchConfigs, shopConfigs, mapConfigs] = await Promise.all([
const [userConfigs, smsConfigs, workbenchConfigs, shopConfigs, secureConfig] = await Promise.all([
adminSystemParameterConfigApi.listConfigs('USER'),
adminSystemParameterConfigApi.listConfigs('SMS'),
adminSystemParameterConfigApi.listConfigs('WORKBENCH'),
adminSystemParameterConfigApi.listConfigs('SHOP'),
adminSystemParameterConfigApi.listConfigs('MAP')
adminSecureIntegrationConfigApi.getConfig()
])
const defaultPassword = userConfigs.find(item => item.configKey === 'DEFAULT_PASSWORD')
if (defaultPassword) {
@@ -289,13 +360,16 @@ const load = async () => {
Object.assign(shopValidityForm, shopValidity)
shopDefaultValidDays.value = String(shopValidity.configValue || '30')
}
const mapByKey = Object.fromEntries(mapConfigs.map(item => [item.configKey, item])) as Record<string, SystemParameterConfigVO | undefined>
if (mapByKey.MAP_PROVIDER) Object.assign(mapForms.provider, mapByKey.MAP_PROVIDER)
if (mapByKey.TENCENT_MAP_KEY) Object.assign(mapForms.tencentWeb, mapByKey.TENCENT_MAP_KEY)
if (mapByKey.AMAP_WEB_KEY) Object.assign(mapForms.amapWeb, mapByKey.AMAP_WEB_KEY)
if (mapByKey.AMAP_MINI_KEY) Object.assign(mapForms.amapMini, mapByKey.AMAP_MINI_KEY)
mapForms.provider.configValue = mapForms.provider.configValue === 'AMAP' ? 'AMAP' : 'TENCENT'
mapEnabled.value = mapForms.provider.enabled === 1
secureStatus.value = secureConfig
mapProvider.value = secureConfig.mapProvider === 'AMAP' ? 'AMAP' : 'TENCENT'
mapEnabled.value = Boolean(secureConfig.mapEnabled)
moderationProvider.value = secureConfig.moderationProvider || 'DISABLED'
moderationCallbackUrl.value = secureConfig.moderationCallbackUrl || defaultCallbackUrl()
mapSecrets.tencentWeb = ''
mapSecrets.amapWeb = ''
mapSecrets.amapMini = ''
moderationSecrets.callbackToken = ''
moderationSecrets.encodingAesKey = ''
userInfo.value = loadCachedAdminUserInfo()
} catch (error) {
message.error(error instanceof Error ? error.message : '系统设置加载失败')
@@ -379,18 +453,82 @@ const saveShopValidity = async () => {
const saveMapConfig = async () => {
savingMap.value = true
try {
await adminSystemParameterConfigApi.saveConfig({ ...mapForms.provider, configValue: String(mapForms.provider.configValue).toUpperCase(), enabled: mapEnabled.value ? 1 : 0 })
await adminSystemParameterConfigApi.saveConfig({ ...mapForms.tencentWeb, enabled: mapEnabled.value ? 1 : 0 })
await adminSystemParameterConfigApi.saveConfig({ ...mapForms.amapWeb, enabled: mapEnabled.value ? 1 : 0 })
await adminSystemParameterConfigApi.saveConfig({ ...mapForms.amapMini, enabled: mapEnabled.value ? 1 : 0 })
message.success('地图配置已保存')
const result = await adminSecureIntegrationConfigApi.saveMapConfig({
mapProvider: mapProvider.value,
mapEnabled: mapEnabled.value,
tencentWebKey: mapSecrets.tencentWeb,
amapWebKey: mapSecrets.amapWeb,
amapMiniKey: mapSecrets.amapMini,
clearTencentWebKey: clearMapSecrets.tencentWeb,
clearAmapWebKey: clearMapSecrets.amapWeb,
clearAmapMiniKey: clearMapSecrets.amapMini
})
secureStatus.value = result
Object.keys(mapSecrets).forEach(key => { mapSecrets[key as MapKey] = '' })
Object.keys(clearMapSecrets).forEach(key => { clearMapSecrets[key as MapKey] = false })
message.success('地图密钥已加密保存')
} catch (error) {
message.error(error instanceof Error ? error.message : '地图配置保存失败')
message.error(error instanceof Error ? error.message : '安全地图配置保存失败')
} finally {
savingMap.value = false
}
}
const saveModerationConfig = async () => {
if (moderationProvider.value === 'WECHAT') {
if (!isPublicHttpsCallback.value) {
message.warning('微信审核回调必须使用公网可访问的 HTTPS 地址')
return
}
if (moderationSecrets.callbackToken && (moderationSecrets.callbackToken.length < 3 || moderationSecrets.callbackToken.length > 32)) {
message.warning('微信回调 Token 需要为 3-32 个字符')
return
}
if (moderationSecrets.encodingAesKey && !/^[A-Za-z0-9+/]{43}$/.test(moderationSecrets.encodingAesKey)) {
message.warning('EncodingAESKey 需要为 43 位字符')
return
}
const hasToken = secureStatus.value?.moderationCallbackTokenConfigured && !clearModerationSecrets.callbackToken
const hasAesKey = secureStatus.value?.moderationEncodingAesKeyConfigured && !clearModerationSecrets.encodingAesKey
if ((!hasToken && !moderationSecrets.callbackToken) || (!hasAesKey && !moderationSecrets.encodingAesKey)) {
message.warning('启用微信审核前,请填写回调 Token 和 EncodingAESKey')
return
}
}
savingModeration.value = true
try {
secureStatus.value = await adminSecureIntegrationConfigApi.saveModerationConfig({
moderationProvider: moderationProvider.value,
moderationCallbackUrl: moderationCallbackUrl.value,
moderationCallbackToken: moderationSecrets.callbackToken,
moderationEncodingAesKey: moderationSecrets.encodingAesKey,
clearModerationCallbackToken: clearModerationSecrets.callbackToken,
clearModerationEncodingAesKey: clearModerationSecrets.encodingAesKey
})
moderationSecrets.callbackToken = ''
moderationSecrets.encodingAesKey = ''
clearModerationSecrets.callbackToken = false
clearModerationSecrets.encodingAesKey = false
message.success('内容审核接入设置已保存')
} catch (error) {
message.error(error instanceof Error ? error.message : '内容审核设置保存失败')
} finally {
savingModeration.value = false
}
}
const toggleMapSecretClear = (key: MapKey) => { clearMapSecrets[key] = !clearMapSecrets[key] }
const toggleModerationSecretClear = (key: 'callbackToken' | 'encodingAesKey') => { clearModerationSecrets[key] = !clearModerationSecrets[key] }
const copyCallbackUrl = async () => {
try {
await navigator.clipboard.writeText(moderationCallbackUrl.value)
message.success('回调 URL 已复制')
} catch {
message.error('复制失败,请手动选择并复制回调 URL')
}
}
const saveSmsProvider = async () => {
const confirmed = window.confirm('保存后会同步全部短信验证码场景的模板、通道和发送方式,确认切换吗?')
if (!confirmed) return
@@ -448,6 +586,9 @@ onMounted(() => {
.setting-control > :deep(.ant-select) { width: 100%; }
.setting-control--password > :deep(.ant-input-affix-wrapper) { flex: 1; width: auto; min-width: 100px; }
.setting-control--password { min-width: 0; }
.setting-control--joined { min-width: 0; }
.setting-control--joined > :deep(.ant-input) { flex: 1; min-width: 0; }
.setting-control--joined > :deep(.ant-btn) { flex: 0 0 auto; }
.setting-control--number { width: min(220px, 100%); }
.control-note { color: var(--admin-mobile-muted); font-size: 11px; white-space: nowrap; }
.setting-row > .control-note { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
@@ -458,6 +599,16 @@ onMounted(() => {
.status-pill.is-muted::before { background: var(--admin-mobile-muted); }
.warning-note { display: inline-flex; align-items: center; gap: 5px; color: #a66d22; font-size: 11px; white-space: nowrap; }
.warning-note::before { content: '!'; display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; border-radius: 50%; background: #fff3d9; font-size: 10px; font-weight: 800; }
.secure-note { margin: 0; padding: 12px 14px; color: var(--admin-mobile-muted); font-size: 12px; line-height: 1.65; background: color-mix(in srgb, var(--theme-primary) 7%, var(--theme-card-bg)); }
.secure-note__warning { display: block; margin-top: 6px; color: #8a4b0d; font-weight: 650; }
.secure-guide { margin: 0 12px 12px; padding: 14px 16px; background: color-mix(in srgb, var(--admin-mobile-accent-soft) 55%, var(--theme-card-bg)); color: var(--admin-mobile-ink); font-size: 12px; line-height: 1.65; }
.secure-guide > strong { font-size: 13px; }
.secure-guide ol { margin: 8px 0 10px; padding-left: 19px; color: var(--admin-mobile-muted); }
.secure-guide li + li { margin-top: 4px; }
.secure-guide__links { display: flex; flex-wrap: wrap; gap: 14px; }
.secure-guide__links a { display: inline-flex; align-items: center; gap: 5px; color: var(--theme-primary-action); text-decoration: none; }
.secure-guide__links a:hover { text-decoration: underline; }
.secure-guide__links a:focus-visible { outline: 2px solid color-mix(in srgb, var(--theme-primary) 55%, transparent); outline-offset: 2px; }
.section-footnote { margin: 12px 2px 0; color: var(--admin-mobile-muted); font-size: 11px; }
@media (max-width: 760px) {
.settings-header { align-items: flex-start; }