获取微信支付特约商户进件
加密证书用的是从服务商下载的证书apicclient_cert.pem
解密用的是获取平台证书
解密代码
javax.crypto.AEADBadTagException: Tag mismatch!
at com.sun.crypto.provider.GaloisCounterMode.decryptFinal(GaloisCounterMode.java:524)
at com.sun.crypto.provider.CipherCore.finalNoPadding(CipherCore.java:1023)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:960)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:824)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:436)
at javax.crypto.Cipher.doFinal(Cipher.java:2165)
比如用的 FastJson 库:
@Test public void decryptPayCallbackContentTest() throws GeneralSecurityException, IOException { String content = "{\"id\":\"f00e26a0-d255-5bfd-8f0d-a0275df040ad\",\"create_time\":\"2021-09-30T16:08:53+08:00\",\"resource_type\":\"encrypt-resource\",\"event_type\":\"TRANSACTION.SUCCESS\",\"summary\":\"支付成功\",\"resource\":{\"original_type\":\"transaction\",\"algorithm\":\"AEAD_AES_256_GCM\",\"ciphertext\":\"lZr3KNzyREUwOpGTp8******ncWT3t1n0eU20wdk=\",\"associated_data\":\"transaction\",\"nonce\":\"cji332epFsZO\"}}"; JSONObject parseObject = JSON.parseObject(content); JSONObject resourceObject = parseObject.getJSONObject("resource"); AesUtil aesUtil = new AesUtil(apiV3Key.getBytes(StandardCharsets.UTF_8)); // 这里很重要 String transaction = resourceObject.getString("associated_data"); String nonceStr = resourceObject.getString("nonce"); String cipherText = resourceObject.getString("ciphertext"); Assertions.assertThrows(AEADBadTagException.class, () -> { // 错误的做法 aesUtil.decryptToString(resourceObject.getBytes("associated_data"), resourceObject.getBytes("nonce"), resourceObject.getString("ciphertext")); }); Assertions.assertDoesNotThrow(() -> { // 对的做法 aesUtil.decryptToString(transaction.getBytes(StandardCharsets.UTF_8), nonceStr.getBytes(StandardCharsets.UTF_8), cipherText); }); }
支付问题移步至支付专区https://developers.weixin.qq.com/community/pay提问,我们会有对应的同学处理
好的 华华
华华 怎么解决
耐心等待下,我们会有支付那边的同学帮忙处理的(PS:是不是觉得喊一句华华就能搞定啦?)
哈哈哈,好有爱的称呼!!!
出来帮忙 不要出来 打酱油