fix(admin): 平台推送地址优先回显已配置的公网域名
- 引入 resolveDouyinMashidaPublicOrigin 从已配置的 claimLinkBase/certLink 提取公网域名 - 更新后台面板 message_url 展示逻辑,即使从 localhost 访问也清晰呈现已配置的公网推送地址 - 向平台订阅推送时使用已解析的公网域名,避免错误推送 localhost - 补充前端单元测试并通过全量构建校验
This commit is contained in:
@@ -53,6 +53,7 @@ import {
|
||||
describeMessageTemplateWarning,
|
||||
describeMissingConfigFields,
|
||||
isLocalDevBaseUrl,
|
||||
resolveDouyinMashidaPublicOrigin,
|
||||
} from '@/utils/douyin-mashida'
|
||||
|
||||
const { Text, Paragraph } = Typography
|
||||
@@ -155,9 +156,14 @@ export function DouyinMashidaPanel() {
|
||||
async function handleSubscribe(disable = false) {
|
||||
setSubscribing(true)
|
||||
try {
|
||||
const targetUrl = buildDouyinMashidaMessageUrl(window.location.origin)
|
||||
const targetOrigin = resolveDouyinMashidaPublicOrigin(
|
||||
config.claimLinkBase,
|
||||
config.certLink,
|
||||
window.location.origin,
|
||||
)
|
||||
const targetUrl = buildDouyinMashidaMessageUrl(targetOrigin)
|
||||
await subscribeAdminDouyinMashidaPush({
|
||||
publicUrl: window.location.origin,
|
||||
publicUrl: targetOrigin,
|
||||
messageUrl: targetUrl,
|
||||
topics: config.handledTopics,
|
||||
disable,
|
||||
@@ -216,7 +222,13 @@ export function DouyinMashidaPanel() {
|
||||
certLink: config.certLink,
|
||||
})
|
||||
const isLocalDev = isLocalDevBaseUrl(config.baseUrl)
|
||||
const messageUrl = buildDouyinMashidaMessageUrl(window.location.origin)
|
||||
const publicOrigin = resolveDouyinMashidaPublicOrigin(
|
||||
config.claimLinkBase,
|
||||
config.certLink,
|
||||
window.location.origin,
|
||||
)
|
||||
const messageUrl = buildDouyinMashidaMessageUrl(publicOrigin)
|
||||
const isMessageUrlLocal = isLocalDevBaseUrl(publicOrigin)
|
||||
const claimLinkPreview = buildDouyinMashidaClaimLinkPreview(config.claimLinkBase)
|
||||
const claimLinkWarning = describeClaimLinkBaseWarning(config.claimLinkBase)
|
||||
const messageTemplateWarning = describeMessageTemplateWarning(config.messageTemplate)
|
||||
@@ -314,14 +326,28 @@ export function DouyinMashidaPanel() {
|
||||
|
||||
{/* 平台推送回调地址展示 */}
|
||||
<div style={{ marginTop: 12, paddingTop: 10, borderTop: '1px dashed #e8e8e8' }}>
|
||||
<Space wrap align="center">
|
||||
<Text type="secondary" style={{ fontSize: 13 }}>
|
||||
平台侧消息推送地址 (message_url):
|
||||
</Text>
|
||||
<Text code copyable={{ text: messageUrl }} style={{ fontSize: 13 }}>
|
||||
{messageUrl}
|
||||
</Text>
|
||||
</Space>
|
||||
<Row gutter={[8, 8]} align="middle">
|
||||
<Col xs={24} lg={6}>
|
||||
<Space>
|
||||
<SendOutlined style={{ color: '#1677ff' }} />
|
||||
<Text strong style={{ fontSize: 13 }}>
|
||||
平台侧消息推送地址 (message_url):
|
||||
</Text>
|
||||
</Space>
|
||||
</Col>
|
||||
<Col xs={24} lg={18}>
|
||||
<Space wrap align="center">
|
||||
<Text code copyable={{ text: messageUrl }} style={{ fontSize: 13, fontWeight: 500 }}>
|
||||
{messageUrl}
|
||||
</Text>
|
||||
{isMessageUrlLocal ? (
|
||||
<Tag color="warning">⚠️ 当前为本地地址,请在下方配置公网域名后订阅</Tag>
|
||||
) : (
|
||||
<Tag color="success">✅ 公网推送就绪</Tag>
|
||||
)}
|
||||
</Space>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
|
||||
@@ -47,6 +47,27 @@ export function buildDouyinMashidaMessageUrl(origin: string): string {
|
||||
return `${normalized}/api/v1/open/douyin-mashida/message`
|
||||
}
|
||||
|
||||
/**
|
||||
* 从已配置的 claimLinkBase 或 certLink 中提取公网 origin,未配置时回退到 fallbackOrigin。
|
||||
* 例:`https://nonsecretly-posttracheal-amado.ngrok-free.dev/h5` → `https://nonsecretly-posttracheal-amado.ngrok-free.dev`
|
||||
*/
|
||||
export function resolveDouyinMashidaPublicOrigin(
|
||||
claimLinkBase?: string,
|
||||
certLink?: string,
|
||||
fallbackOrigin = 'http://localhost',
|
||||
): string {
|
||||
const candidate = String(claimLinkBase || certLink || '').trim()
|
||||
if (candidate && /^https?:\/\//i.test(candidate)) {
|
||||
try {
|
||||
const url = new URL(candidate)
|
||||
return url.origin
|
||||
} catch {
|
||||
// 容错
|
||||
}
|
||||
}
|
||||
return fallbackOrigin
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回缺失项的中文名数组,顺序固定为:接入开关 / 商户uid / 用户秘钥 / 兑换链接。
|
||||
* 全齐时返回空数组。
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
buildDouyinMashidaMessageUrl,
|
||||
describeMissingConfigFields,
|
||||
isLocalDevBaseUrl,
|
||||
resolveDouyinMashidaPublicOrigin,
|
||||
} from '../src/utils/douyin-mashida.ts'
|
||||
|
||||
/** 固定顺序:接入开关 / 商户uid / 用户秘钥 / 兑换链接 */
|
||||
@@ -126,3 +127,19 @@ test('发消息模板提示:没有 {link} 就等于没给买家链接', () =>
|
||||
assert.equal(describeMessageTemplateWarning(''), '')
|
||||
assert.match(describeMessageTemplateWarning('您的订单已发货'), /\{link\}/)
|
||||
})
|
||||
|
||||
test('resolveDouyinMashidaPublicOrigin:从已配置的 claimLinkBase 或 certLink 提取公网 origin', () => {
|
||||
assert.equal(
|
||||
resolveDouyinMashidaPublicOrigin('https://nonsecretly-posttracheal-amado.ngrok-free.dev/h5'),
|
||||
'https://nonsecretly-posttracheal-amado.ngrok-free.dev',
|
||||
)
|
||||
assert.equal(
|
||||
resolveDouyinMashidaPublicOrigin('', 'https://my-domain.com/h5'),
|
||||
'https://my-domain.com',
|
||||
)
|
||||
assert.equal(
|
||||
resolveDouyinMashidaPublicOrigin('', '', 'http://localhost:5173'),
|
||||
'http://localhost:5173',
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user