小程序
小游戏
企业微信
微信支付
扫描小程序码分享
"original_type": "transaction","algorithm": "AEAD_AES_256_GCM", "ciphertext": "", "associated_data": "", "nonce": ""
resource里面将数据加密后回传给商户开发者,然后商户端的开发者解析数据进行业务处理,问题是你们如何加密的,我无法模拟数据的加密,官方只提供了解密的案例,没有加密的案例。无法在线上调试。
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
退款回调微信使用的是AEAD_AES_256_GCM加密算法。
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
//支付数据加密模拟 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); }
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
退款回调微信使用的是AEAD_AES_256_GCM加密算法。
//支付数据加密模拟 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); }