代码拉取完成,页面将自动刷新
@Post('/msg/callback')
@ApiOperation({ summary: '公众号消息/事件回调处理' })
async handleMpCallback(@Req() req, @Res() res) {
console.log(req.query)
let appId: string = req.query.appId
if (appId) {
ApiConfigKit.setCurrentAppId(appId)
}
// 获取签名相关的参数用于消息解密(测试号以及明文模式无此参数)
const { signature, timestamp, nonce } = req.query;
let buffer: Uint8Array[] = [];
req.on('data', (data: any) => {
buffer.push(data);
});
req.on('end', () => {
let msgXml = Buffer.concat(buffer).toString('utf-8');
console.log(msgXml)
WeChat.handleMsg(
new MsgController(),
msgXml,
signature,
timestamp,
nonce,
).then((data) => {
console.log('data', data)
res.send(data)
}).catch(error => console.log("error", error))
})
}
<xml><ToUserName><![CDATA[gh_029c12ae1cba]]></ToUserName>
<FromUserName><![CDATA[orgKLwWyy9DqBT7ipkkzID50H8PU]]></FromUserName>
<CreateTime>1676212138</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[1]]></Content>
<MsgId>23997586448432458</MsgId>
</xml>
(node:14807) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
at new NodeError (internal/errors.js:322:7)
at Decipheriv.update (internal/crypto/cipher.js:157:11)
at CryptoKit.decryptMsg (/Users/hongjunyao/Desktop/common_backend/node_modules/@tnwx/commons/src/CryptoKit.ts:79:52)
at /Users/hongjunyao/Desktop/common_backend/node_modules/@tnwx/wxmp/src/WeChat.ts:110:30
at Generator.next (<anonymous>)
at /Users/hongjunyao/Desktop/common_backend/node_modules/@tnwx/wxmp/dist/WeChat.js:8:71
at new Promise (<anonymous>)
at __awaiter (/Users/hongjunyao/Desktop/common_backend/node_modules/@tnwx/wxmp/dist/WeChat.js:4:12)
at /Users/hongjunyao/Desktop/common_backend/node_modules/@tnwx/wxmp/dist/WeChat.js:76:24
at Parser.<anonymous> (/Users/hongjunyao/Desktop/common_backend/node_modules/xml2js/lib/parser.js:304:18)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14807) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:14807) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.