收藏
回答

V3支付、退款回调的数据微信那边是如何加密的?

"original_type": "transaction","algorithm": "AEAD_AES_256_GCM", "ciphertext": "", "associated_data": "", "nonce": ""

resource里面将数据加密后回传给商户开发者,然后商户端的开发者解析数据进行业务处理,问题是你们如何加密的,我无法模拟数据的加密,官方只提供了解密的案例,没有加密的案例。无法在线上调试。

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

2 个回答

  • 大头
    大头
    2024-09-09

    退款回调微信使用的是AEAD_AES_256_GCM加密算法。

    2024-09-09
    有用
    回复
  • 随心漂泊
    随心漂泊
    2021-12-23
    //支付数据加密模拟
    public static String payNotify() throws NoSuchPaddingException, NoSuchAlgorithmException,
            InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
        //密文数据
        String test = DataDemo.V3_PAY_NOTIFY_JSON;
        //随机串
        String nonce = "xxxxxx";
        //附加数据
        String fj = "";
        Cipher cipher = Cipher.getInstance(WxV3Constant.AES_GCM);
        byte[] aesKey = WxV3Constant.KEY_V3.getBytes();
        SecretKeySpec key = new SecretKeySpec(aesKey, "AES");
        GCMParameterSpec spec = new GCMParameterSpec(128, nonce.getBytes(StandardCharsets.UTF_8));
        cipher.init(Cipher.ENCRYPT_MODE, key, spec);
        cipher.updateAAD(fj.getBytes(StandardCharsets.UTF_8));
        byte[] encrypted = cipher.doFinal(test.getBytes());
        return Base64Util.encode(encrypted);
    }
    
    //退款数据加密模拟
    public static String refundNotify() throws NoSuchPaddingException, NoSuchAlgorithmException,
            InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
        //密文数据
        String test = DataDemo.V3_REFUND_JSON;
        //随机串
        String nonce = "xxxxx";
        //附加数据
        String fj = "";
        Cipher cipher = Cipher.getInstance(WxV3Constant.AES_GCM);
        byte[] aesKey = WxV3Constant.KEY_V3.getBytes();
        SecretKeySpec key = new SecretKeySpec(aesKey, "AES");
        GCMParameterSpec spec = new GCMParameterSpec(128, nonce.getBytes(StandardCharsets.UTF_8));
        cipher.init(Cipher.ENCRYPT_MODE, key, spec);
        cipher.updateAAD(fj.getBytes(StandardCharsets.UTF_8));
        byte[] encrypted = cipher.doFinal(test.getBytes());
        return Base64Util.encode(encrypted);
    
    }
    
    public static void main(String[] args) throws NoSuchPaddingException, InvalidKeyException,
            NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException,
            InvalidAlgorithmParameterException {
        String s = payNotify();
        System.out.println(s);
        String s1 = refundNotify();
        System.out.println(s1);
    
    }
    


    2021-12-23
    有用
    回复
登录 后发表内容