can get the message sent by the user to the official account, but failed to send the xml data of the reply through res.end (), that is, the user cannot receive the message replied in the background. The official account shows a failure. If you uncomment a line of res.setHeader in your code, there will be an error of Can"t set headers after they are sent.
?
req.on("end", function(){
util.parseXMLAsync(postData)
.then(result => {
console.log(result)
var now = new Date().getTime()
if(result.MsgType === "event"){
if(result.Event === "subscribe"){
result.Content = "~"
}
}
// res.setHeader("Content-Type", "text/xml")
var response = `<xml>
<ToUserName>< ![CDATA[${result.FromUserName}] ]></ToUserName>
<FromUserName>< ![CDATA[${result.ToUserName}] ]></FromUserName>
<CreateTime>${now}</CreateTime>
<MsgType>< ![CDATA[text] ]></MsgType>
<Content>< ![CDATA[${result.Content}] ]></Content>
</xml>`
res.end(response)
})
})
result
the result of converting the received xml to json