fix(微信订阅): 用微信真实关键词修正歌曲排期模板(thing1/phrase2/time3/character_string4),并修掉字段认领顺序导致的校准失效

This commit is contained in:
2026-10-24 11:56:50 +08:00
parent dc2565da34
commit f5a43b37cc
7 changed files with 192 additions and 56 deletions
+15
View File
@@ -350,6 +350,7 @@ export async function resolveTemplate(
reason: `拿不到微信模板列表(${error || '未知原因'}),沿用配置里的字段名`,
unresolvedVariables: [],
invalidConfiguredCodes: [],
unclaimedCodes: [],
remoteError: error,
remoteTitle: null,
remoteContent: null,
@@ -818,6 +819,9 @@ export async function sendWechatSubscribe(
: '本次字段名是【沿用配置】的:'
detail =
`微信回 47003:模板字段名或字段值不合规。${hint}` +
(resolution?.unclaimedCodes?.length
? `还有关键词没被任何字段填上(${resolution.unclaimedCodes.join('、')}),微信会报「value is empty」。`
: '') +
'用 /api/admin/wechat/diagnose 可以看到微信侧的真实关键词名。' +
(resolution?.remoteKeywords?.length
? ` 微信侧关键词:${resolution.remoteKeywords
@@ -973,6 +977,8 @@ export type TemplateStatus = {
fieldReason: string
/** 配置里有、但微信模板里根本没有的关键词名(有值就一定会 47003) */
invalidConfiguredCodes: string[]
/** 微信模板里有、但没有任何字段去填的关键词(微信会回 `data.xxx.value is empty`) */
unclaimedCodes: string[]
/** 微信侧真实的关键词表(拿不到时为 null) */
remoteKeywords: Array<{ code: string; type: string; label: string }> | null
/** 微信侧的模板原文(能看到真实的关键词与顺序) */
@@ -1109,6 +1115,7 @@ export async function inspectWechatSubscribe(
fieldSource: resolution?.source === 'wechat-api' ? 'wechat-api' : 'config',
fieldReason: resolution?.reason || '没有模板 ID,无法校准',
invalidConfiguredCodes: resolution?.invalidConfiguredCodes || [],
unclaimedCodes: resolution?.unclaimedCodes || [],
remoteKeywords: resolution?.remoteKeywords?.length
? resolution.remoteKeywords.map((k) => ({
code: k.code,
@@ -1166,6 +1173,14 @@ export async function inspectWechatSubscribe(
)
}
templateStatuses.forEach((t) => {
// 「少填一个关键词」是 47003 `data.xxx.value is empty` 的直接原因,比字段名错更常见,先说
if (t.unclaimedCodes.length) {
actions.push(
`模板「${t.title}」里有关键词没被任何字段填上:${t.unclaimedCodes.join('、')} —— ` +
`微信会回 47003「data.${t.unclaimedCodes[0]}.value is empty」。` +
`对照 remoteContent 把这几个关键词补进 fields 映射(少填一个就整条发不出去)`
)
}
// 字段名是 47003 的头号嫌疑,体检里把它放在前面说清楚
if (t.remoteError) {
actions.push(