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