diff --git a/app/controller/wechatOpen.js b/app/controller/wechatOpen.js index 4b049e8..cd8772e 100644 --- a/app/controller/wechatOpen.js +++ b/app/controller/wechatOpen.js @@ -30,6 +30,12 @@ function detectAccountType(appid) { return '未知账号'; } +/** + * autoReply 返回该值表示「显式不回复,响应体回空串」: + * 官方检测步骤3要求 5 秒内返回空串表明暂时不回复(不能回 success)。 + */ +const EMPTY_REPLY = '__EMPTY_REPLY__'; + /** * 微信开放平台第三方平台回调 Controller。 * 接收微信服务器推送的授权事件(组件票据/授权成功/授权更新/取消授权), @@ -441,8 +447,14 @@ class WechatOpenController extends Controller { break; case 'text': { - // 记录文本消息并自动回复(有被动回复时返回加密 XML) + // 记录文本消息并自动回复(被动回复返回加密 XML;客服消息场景返回空串) const reply = await this.autoReply(appid, data, nonce); + if (reply === EMPTY_REPLY) { + // 官方检测步骤3/4:5 秒内返回空串表明暂时不回复,客服消息在后台异步发送 + ctx.logger.warn(`[wechatOpen.events] 返回空串响应(客服消息后台发送中) appid=${appid} type=${detectAccountType(appid)}`); + ctx.body = ''; + return; + } if (reply) { ctx.logger.warn(`[wechatOpen.events] 被动回复已返回 appid=${appid} type=${detectAccountType(appid)} openid=${data.FromUserName} length=${reply.length}`); ctx.type = 'application/xml'; @@ -605,7 +617,7 @@ class WechatOpenController extends Controller { replyContent = `收到您的消息:${content}\n我会尽快回复您!`; } - if (noReply) return ''; + if (noReply) return EMPTY_REPLY; // 组装明文回复 XML(ToUserName=用户 openid,FromUserName=公众号原始 ID) const plainXml = ''