Node developer Wechat official account message replying to the xml returned by ctx.body cannot be received on Wechat.

node develops Wechat official account. Wechat cannot receive xml data returned by ctx.body

var sha1 = require ("sha1");
var Wechat = require (". / wechat")
var getRawBody = require ("raw-body")
var util = require (".. / libs/util")
var answer = require (". / answer")

module.exports = function (opts) {

var wechat = new Wechat(opts)
return async function(ctx,next){
    var token = opts.token;
    var signature = ctx.query.signature
    var nonce = ctx.query.nonce
    var timestamp = ctx.query.timestamp
    var echostr = ctx.query.ecostr
    var str = [token,timestamp,nonce].sort().join("")
    var sha = sha1(str)
    console.log("PPPP+"+ctx.method)
    if(ctx.method === "GET"){
        if(sha ===signature){
            ctx.body = ctx.query.echostr
        }else {
            ctx.body = "wrong"
        }
    }else if(ctx.method === "POST"){
        if(sha ===signature){
            ctx.body = ctx.query.echostr
        }else {
            ctx.body = "wrong"
            return false
        }
        var data = await getRawBody(ctx.req,{
            length : ctx.length,
            limit : "1mb",
            encoding : ctx.charset
        })
        var content = await util.parseXmlAsync(data)
        console.log("contentPPPP+"+content+"-------"+content.xml)
        if(content.xml.MsgType === "text"){
            var now = new Date().getTime()
            var output=answer.text(content.xml)
             ctx.body=output;
            console.log(output)
        }


    }
}

} xml

Apr.03,2022

check whether toUserName and fromUserName are written in reverse

in the xml format you introduced.
Menu