fix(claim): 统一所有买家领取链接为 H5 订单号格式
This commit is contained in:
@@ -835,7 +835,7 @@ export default function AdminTaskDetailPage() {
|
||||
type="secondary"
|
||||
style={{ fontSize: 12, display: 'block', marginBottom: 6 }}
|
||||
>
|
||||
历史/备用 Token 链接:
|
||||
任务领取链接(统一 H5 订单号):
|
||||
</Typography.Text>
|
||||
<Space wrap align="center">
|
||||
{claimUrl ? (
|
||||
@@ -861,7 +861,7 @@ export default function AdminTaskDetailPage() {
|
||||
disabled={!claimUrl}
|
||||
onClick={copyClaimUrl}
|
||||
>
|
||||
复制 Token 链接
|
||||
复制领取链接
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
@@ -87,22 +87,52 @@ export function describeMissingConfigFields(config: MissingConfigCheck): string[
|
||||
/**
|
||||
* 面板预览用的示例订单号(与真实 16 位平台订单号形态一致)。
|
||||
*/
|
||||
const CLAIM_LINK_PREVIEW_TOKEN = '2628301923197355'
|
||||
const CLAIM_LINK_PREVIEW_ORDER_NO = '2628301923197355'
|
||||
|
||||
/**
|
||||
* 拼一条领取链接预览:`claimLinkBase` 去尾斜杠 + '/' + token。
|
||||
* 规则与后端拼装一致(后端用配置里的 `claimLinkBase`)。
|
||||
* 基址为空返回空串(后端会回退到通用兑换链接)。
|
||||
* 拼一条领取链接预览:`<claimLinkBase>/<订单号>`。
|
||||
* 规则与后端一致,历史 `/#/claim`、`/claim` 基址也会归一化为 `/h5/订单号`。
|
||||
* 基址为空返回空串。
|
||||
*/
|
||||
export function buildDouyinMashidaClaimLinkPreview(
|
||||
claimLinkBase: string,
|
||||
token = CLAIM_LINK_PREVIEW_TOKEN,
|
||||
orderNo = CLAIM_LINK_PREVIEW_ORDER_NO,
|
||||
): string {
|
||||
const base = String(claimLinkBase ?? '')
|
||||
.trim()
|
||||
.replace(/\/+$/, '')
|
||||
if (!base) return ''
|
||||
return `${base}/${String(token ?? '').trim()}`
|
||||
const base = normalizeH5ClaimBase(claimLinkBase)
|
||||
const normalizedOrderNo = String(orderNo ?? '').trim()
|
||||
if (!base || !normalizedOrderNo) return ''
|
||||
return `${base}/${encodeURIComponent(normalizedOrderNo)}`
|
||||
}
|
||||
|
||||
/** 将历史 `/#/claim`、`/claim` 基址归一化为同站点 `/h5`,与后端生成口径一致。 */
|
||||
function normalizeH5ClaimBase(claimLinkBase: string): string {
|
||||
const raw = String(claimLinkBase ?? '').trim()
|
||||
if (!raw) return ''
|
||||
|
||||
let url: URL
|
||||
try {
|
||||
url = new URL(raw)
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
|
||||
const pathname = url.pathname.replace(/\/+$/, '')
|
||||
const h5Match = pathname.match(/\/h5(?:\/|$)/i)
|
||||
const claimMatch = pathname.match(/\/claim(?:\/|$)/i)
|
||||
|
||||
if (h5Match?.index !== undefined) {
|
||||
url.pathname = `${pathname.slice(0, h5Match.index)}/h5`
|
||||
} else if (claimMatch?.index !== undefined) {
|
||||
url.pathname = `${pathname.slice(0, claimMatch.index)}/h5`
|
||||
} else if (pathname && pathname !== '/') {
|
||||
url.pathname = `${pathname}/h5`
|
||||
} else {
|
||||
url.pathname = '/h5'
|
||||
}
|
||||
|
||||
url.search = ''
|
||||
url.hash = ''
|
||||
return url.toString().replace(/\/+$/, '')
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user