getChatData时有可能返回非json字符串:“svrip 116.128.138.160 has been offline. more in at https://developer.work.weixin.qq.com/community/announcement/detail?content_id=16311614294857467685” 所以在对getChatData返回的值,应该做json格式的校验再使用
会话存档jvm crash我们使用java sdk去拉取会话存档,最开始正常运行,昨天突然jvm crash terminate called after throwing an instance of 'j2pb_error' what(): Load failed: '[' or '{' expected near '<' [图片]
2023-08-15楼主分享一下解决办法,目前还是遇到了同样的问题 我是照官方的 demo 做的
微信 WXBizMsgCrypt解密失败,AesException:解密后得到的buffer非法?WXBizMsgCrypt.java 解密过程,如下: /** * 对密文进行解密. * * @param text 需要解密的密文 * @return 解密得到的明文 * @throws AesException aes解密失败 */ String decrypt(String text) throws AesException { byte[] original; try { // 设置解密模式为AES的CBC模式 Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); SecretKeySpec key_spec = new SecretKeySpec(aesKey, "AES"); IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16)); cipher.init(Cipher.DECRYPT_MODE, key_spec, iv); // 使用BASE64对密文进行解码 byte[] encrypted = Base64.decodeBase64(text); // 解密 original = cipher.doFinal(encrypted); } catch (Exception e) { e.printStackTrace(); throw new AesException(AesException.DecryptAESError); } String xmlContent, from_appid; try { // 去除补位字符 byte[] bytes = PKCS7Encoder.decode(original); // 分离16位随机字符串,网络字节序和AppId byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20); int xmlLength = recoverNetworkBytesOrder(networkOrder); xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), CHARSET); from_appid = new String(Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length), CHARSET); } catch (Exception e) { e.printStackTrace(); throw new AesException(AesException.IllegalBuffer); } // appid不相同的情况 if (!from_appid.equals(appId)) { throw new AesException(AesException.ValidateAppidError); } return xmlContent; } 上面代码中,标红处解密出错,如下: [图片] [图片]需要解密的内容如下: <xml> <AppId><![CDATA[wx715ef430c8070462]]></AppId> <Encrypt><![CDATA[5NWqy2SBB3fPlQRkrHUDe2SnrQGpeCvI04jXc7WmGJQeuCoTlssyopMuCnX2tsrmfw+oEJUugOLV6RFT65dfyJ7PS3uGpH+WzFq+gJuSQYu40cQllKNHuV7tI+hnp7HfQrZ5a9aJUGNDgz4EJuimtkIVo+DaPgA/CfxRd1eDBtnvqcYzJ10f7lXImPa2RuSDvyxBiT3d6JzH3BSz8oMSw7ah8WEIp0B38X1WlTGk7UdP2RMcSO2GgCjP4kN593EQBR0g8lJPb04Xo4bDrdDEChGhhMxzi1Y7ywZxwvrm0oWyVdX6DTfAoh6X4+tQic/BoWjlrMaYC2GHwUJ83E1FQr6eEAsPezMfkGYln/GVlkuiMilozDueyT8KQkF/rCmx6T9SZLix7/eq/VJsDbwVcg3stgwLfhCUHnS+LUXNZ4tdlbr4xt/N/u8CzFOr+SlVeOCZ8xa7L7JeIH9rvO/93g==]]></Encrypt> </xml>
2021-09-26