安全接入配置改造回溯点
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<h1>系统设置</h1>
|
||||
<p>集中管理后台运行参数、服务接入和当前账号。</p>
|
||||
</div>
|
||||
<span class="settings-health"><i />配置服务正常</span>
|
||||
<span class="settings-health"><i />当前环境设置</span>
|
||||
</header>
|
||||
|
||||
<div class="settings-layout">
|
||||
@@ -142,7 +142,7 @@
|
||||
<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>
|
||||
<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><span v-else-if="secureStatus?.mapLegacyMigrationPending" class="secure-note__warning">检测到旧版地图参数尚未完成加密迁移;主密钥配置后重新打开本页,系统会自动转存并清空旧明文值,请核对各 Key 显示为已配置后再启用地图。</span></p>
|
||||
</div>
|
||||
|
||||
<div class="setting-group">
|
||||
@@ -153,15 +153,20 @@
|
||||
<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 class="setting-copy"><strong>小程序凭据</strong><span>服务端需配置当前环境的 AppID 与 AppSecret,用于请求微信审核接口。</span></div>
|
||||
<div class="setting-value">{{ secureStatus?.wechatMiniAppConfigured ? `${secureStatus.wechatMiniAppId} · AppSecret 已配置` : `${secureStatus?.wechatMiniAppId || 'AppID 未配置'} · AppSecret 待配置` }}</div>
|
||||
<span class="status-pill" :class="{ 'is-muted': !secureStatus?.wechatMiniAppConfigured }">{{ secureStatus?.wechatMiniAppConfigured ? '已就绪' : '待配置' }}</span>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-copy"><strong>回调 Token</strong><span>在微信消息推送配置中填写的 Token,留空表示不修改已保存值。</span></div>
|
||||
<div class="setting-copy"><strong>微信服务器回调 URL</strong><span>复制到微信公众平台「开发管理 → 开发设置 → 消息推送」的 URL。</span></div>
|
||||
<div class="setting-control setting-control--joined">
|
||||
<a-input v-model:value="moderationCallbackUrl" :placeholder="defaultCallbackUrl()" />
|
||||
<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>3-32 位英文字母或数字;留空表示不修改已保存值。</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>
|
||||
@@ -179,15 +184,17 @@
|
||||
<div class="secure-guide">
|
||||
<strong>微信平台填写指引</strong>
|
||||
<ol>
|
||||
<li>进入小程序公众平台的「开发管理 → 开发设置 → 消息推送」,将上方 URL、Token、EncodingAESKey 填入对应项。</li>
|
||||
<li>消息加密方式选择「安全模式」,保存后使用微信平台的 URL 验证;确认审核用 AppID 与当前环境小程序一致。</li>
|
||||
<li>先在本页选择「未启用(失败关闭)」,填写 Token、EncodingAESKey 和公网 URL 后保存;再将相同信息填入微信公众平台。</li>
|
||||
<li>在微信平台选择「安全模式」并完成 URL 验证;确认审核用 AppID 与本页显示的当前环境一致。</li>
|
||||
<li>URL 验证通过后回到本页将审核渠道切换为「微信内容安全审核」并保存,内容审核才会调用微信接口。</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="!isPublicHttpsCallback" class="secure-note__warning">请输入正式环境的公网 HTTPS 域名,并保留完整回调路径;本地地址、IP 地址或路径不匹配时无法验证。</span>
|
||||
<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>
|
||||
@@ -241,6 +248,7 @@ import { useRoute } from 'vue-router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { ApiOutlined, CopyOutlined, ExportOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
import { adminSecureIntegrationConfigApi, adminSystemParameterConfigApi, type SecureIntegrationConfigVO, type SystemParameterConfigVO } from '@/api/admin'
|
||||
import { ADMIN_API_BASE_URL } from '@/config/api'
|
||||
import { loadCachedAdminUserInfo } from '@/utils/admin-session'
|
||||
|
||||
type SettingsSection = 'runtime' | 'services' | 'account'
|
||||
@@ -282,8 +290,27 @@ const moderationProviderOptions = computed(() => [
|
||||
...(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 isPublicHttpsCallback = computed(() => {
|
||||
try {
|
||||
const url = new URL(moderationCallbackUrl.value)
|
||||
const host = url.hostname.toLowerCase().replace(/\.$/, '')
|
||||
const ipLiteral = host.includes(':') || /^\d{1,3}(\.\d{1,3}){3}$/.test(host)
|
||||
return url.protocol === 'https:'
|
||||
&& (!url.port || url.port === '443')
|
||||
&& !url.username
|
||||
&& !url.password
|
||||
&& !url.search
|
||||
&& !url.hash
|
||||
&& url.pathname === callbackPath
|
||||
&& !ipLiteral
|
||||
&& host !== 'localhost'
|
||||
&& !host.endsWith('.localhost')
|
||||
&& !host.endsWith('.local')
|
||||
&& !host.endsWith('.internal')
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
})
|
||||
const sections = [
|
||||
{ key: 'runtime' as const, label: '运行参数', icon: SettingOutlined },
|
||||
{ key: 'services' as const, label: '服务接入', icon: ApiOutlined },
|
||||
@@ -318,7 +345,14 @@ const smsProviderForm = reactive<SystemParameterConfigVO>({
|
||||
const userInfo = ref(loadCachedAdminUserInfo())
|
||||
|
||||
const callbackPath = '/api/integration/wechat/content-moderation/callback'
|
||||
const defaultCallbackUrl = () => `${window.location.origin}${callbackPath}`
|
||||
const defaultCallbackUrl = () => {
|
||||
try {
|
||||
const apiUrl = new URL(ADMIN_API_BASE_URL, window.location.origin)
|
||||
return `${apiUrl.origin}${callbackPath}`
|
||||
} catch {
|
||||
return `${window.location.origin}${callbackPath}`
|
||||
}
|
||||
}
|
||||
const mapConfigured = (key: MapKey) => {
|
||||
if (clearMapSecrets[key]) return false
|
||||
if (mapSecrets[key]) return true
|
||||
@@ -451,6 +485,11 @@ const saveShopValidity = async () => {
|
||||
}
|
||||
|
||||
const saveMapConfig = async () => {
|
||||
const activeSecretClear = mapProvider.value === 'AMAP' ? clearMapSecrets.amapWeb : clearMapSecrets.tencentWeb
|
||||
if (mapEnabled.value && activeSecretClear) {
|
||||
message.warning('当前默认渠道的 Key 已标记清除,请同时停用地图服务后再保存')
|
||||
return
|
||||
}
|
||||
savingMap.value = true
|
||||
try {
|
||||
const result = await adminSecureIntegrationConfigApi.saveMapConfig({
|
||||
@@ -480,14 +519,6 @@ const saveModerationConfig = async () => {
|
||||
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)) {
|
||||
@@ -495,6 +526,14 @@ const saveModerationConfig = async () => {
|
||||
return
|
||||
}
|
||||
}
|
||||
if (moderationSecrets.callbackToken && !/^[A-Za-z0-9]{3,32}$/.test(moderationSecrets.callbackToken)) {
|
||||
message.warning('回调 Token 需要为 3-32 位英文字母或数字')
|
||||
return
|
||||
}
|
||||
if (moderationSecrets.encodingAesKey && !/^[A-Za-z0-9+/]{43}$/.test(moderationSecrets.encodingAesKey)) {
|
||||
message.warning('EncodingAESKey 需要为 43 位字符')
|
||||
return
|
||||
}
|
||||
savingModeration.value = true
|
||||
try {
|
||||
secureStatus.value = await adminSecureIntegrationConfigApi.saveModerationConfig({
|
||||
|
||||
Reference in New Issue
Block a user