收藏
回答

支付分回调解密为啥没有各个语言的demo,怎么解密

  1.  用商户平台上设置的APIv3密钥(微信商户平台(pay.weixin.qq.com)-账户设置-API安全-设置APIv3密钥),记为key

  2. ● 针对resource.algorithm中描述的算法(目前为AEAD_AES_256_GCM),取得对应的参数nonce和associated_data。

  3. ● 使用key、nonce和associated_data,对数据密文resource.ciphertext进行解密,得到XML形式的资源对象

注: AEAD_AES_256_GCM算法的接口细节,请参考rfc5116。微信支付使用的密钥key长度为32个字节,随机串nonce长度12个字节,associated_data长度小于16个字节并可能为空。

描述的太笼统了。

回答关注问题邀请回答
收藏

3 个回答

  • 🚂💨
    🚂💨
    2021-08-12

    https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_2.shtml

    2021-08-12
    有用
    回复
  • :D
    :D
    2020-05-08

    API V3 文档链接 https://wechatpay-api.gitbook.io/wechatpay-api-v3/qian-ming-zhi-nan-1/zheng-shu-he-hui-tiao-bao-wen-jie-mi

    文档里有 Java/PHP/.Net/Python 的示例,这里补充下 Node.js 的示例

    // 对 API V3 加密数据进行解密
    const apiV3Key = '*******'; // 设置的 API V3 密钥
    
    const decryptByApiV3 = ({
      associate, // 加密参数 - 类型
      nonce, // 加密参数 - 随机数
      ciphertext, // 加密密文
    } = {}) => {
      ciphertext = decodeURIComponent(ciphertext);
      ciphertext = Buffer.from(ciphertext, 'base64');
    
    
      const authTag = ciphertext.slice(ciphertext.length - 16);
      const data = ciphertext.slice(0, ciphertext.length - 16);
    
    
      const decipher = crypto.createDecipheriv('aes-256-gcm', apiV3Key, nonce);
      decipher.setAuthTag(authTag);
      decipher.setAAD(Buffer.from(associate));
    
    
      let decryptedText = decipher.update(data, null, 'utf8');
      decryptedText += decipher.final();
      return decryptedText;
    };
    


    2020-05-08
    有用
    回复 5
    • JV
      JV
      2020-10-20
      nodejs还是会有报错:Unsupported state or unable to authenticate data
      2020-10-20
      2
      回复
    • ali
      ali
      2021-04-25
      建议加上golang的demo
      2021-04-25
      1
      回复
    • 李元
      李元
      2021-06-19回复JV
      有解决吗
      2021-06-19
      回复
    • 李元
      李元
      2021-06-19
      decodeURIComponent 是关键
      2021-06-19
      回复
    • Dannel
      Dannel
      2021-08-10回复ali
      有 go的 dome吗
      2021-08-10
      回复
  • 我是只会说666的咸鱼
    我是只会说666的咸鱼
    2019-11-04

    解密demo 在v3的文档里面,坑,也不说明在哪。

    2019-11-04
    有用
    回复 2
    • 众
      2020-03-22
      你好,我找了半天没找到,能否告知具体位置吗
      2020-03-22
      回复
    • 依恋
      依恋
      2020-04-04回复
      你好~你找到了吗。。。。。。
      2020-04-04
      回复
登录 后发表内容