收藏
回答

API接收消息

问题类型 API/组件名称 终端类型 微信版本 基础库版本
Bug API接收消息 工具 最新 2.0.0

这里返回结果 跟明文 一样啊 为什么提示错误呢

最后一次编辑于  2020-02-22
回答关注问题邀请回答
收藏

1 个回答

  • Javen
    Javen
    2020-02-22

    你返回的明文不对,要从 echostr = random(16B) + msg_len(4B) + msg + receiveid 中解析出明文 msg 返回 ,示例代码如下 完整源码

       decrypt(echostr: string): string {
        // 实例 AES 解密对象
        let deCipheriv = crypto.createDecipheriv(this.aesModel, this.encodingAesKey, this.iv)
        // 设置自定填充数据为 false
        deCipheriv.setAutoPadding(false)
        // 对密文解密对密文解密 并去除前 16 个随机字符串
        let decipheredBuff = Buffer.concat([deCipheriv.update(echostr, 'base64'), deCipheriv.final()])
        decipheredBuff = this.PKCS7Decoder(decipheredBuff)
        // 移除头部16个随机字节
        let len_netOrder_corpid = decipheredBuff.slice(16)
        // 4个字节的 msg_len
        let msg_len = len_netOrder_corpid.slice(0, 4).readUInt32BE(0)
        // 截取 msg_len 长度的 msg
        let result = len_netOrder_corpid.slice(4, msg_len + 4).toString()
        return result
      }
    
    2020-02-22
    有用 1
    回复 1
    • 你
      2020-02-22
      抱歉 解决了 我原本是使用的 jsp页面 out.print() 返回 导致这个错  后来我改成servlet  response.getwriter().print(0  问题就解决了
      2020-02-22
      回复
登录 后发表内容
问题标签