微信支付退款通知参数解密遇到的坑-附java编码
问题1:java.security.InvalidKeyException: Illegal key size or default parameters jre自带的加密jar包支持128位,如果需要支持256位加密、解密需要去orace下载jar包,替换jdk安装路径下 C:Program FilesJavajdk1.8.0_25jrelibsecurity 的local_policy.jar和US_export_policy.jar
request.setCharacterEncoding("UTF-8");
DataInputStream in;
String wxNotifyStr = "";
try {
in = new DataInputStream(request.getInputStream());
byte[] dataOrigin = new byte[request.getContentLength()];
//将消息实体的内容读入字节数组dataOrigin中
in.readFully(dataOrigin);
// 从字节数组中得到表示实体的字符串
wxNotifyStr = new String(dataOrigin);
// 关闭数据流
if (null != in) {
in.close();
}
} catch (Exception e) {
logger.error("解析数据流error={}", e);
e.printStackTrace();
}
2.将wxNotifyStr转换成实体,获取到回调返回的req_info 3.解密
private static byte[] getContentBytes(String content, String charset) {
if (charset == null || "".equals(charset)) {
return content.getBytes();
}
try {
return content.getBytes(charset);
} catch (UnsupportedEncodingException e) {
throw new ResultException("MD5签名过程中出现错误" + charset);
}
}
