101 Star 617 Fork 189

Javen / TNWX

 / 详情

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined

待办的
创建于  
2023-02-12 22:31
@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.

评论 (0)

俊瑶先森 创建了任务

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(1)
TypeScript
1
https://gitee.com/javen205/TNWX.git
git@gitee.com:javen205/TNWX.git
javen205
TNWX
TNWX

搜索帮助

53164aa7 5694891 3bd8fe86 5694891