java微信支付v3 0.4.9版本 验证签名代码
时间: 2024-05-25 12:17:09 浏览: 94
微信移动支付,java后台签名代码
//获取签名和时间戳
String sign = headers.getHeaderString("Wechatpay-Signature");
String timestamp = headers.getHeaderString("Wechatpay-Timestamp");
//获取请求体
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(requestContext.getEntityStream().readAllBytes());
String body = IOUtils.toString(byteArrayInputStream, StandardCharsets.UTF_8);
//验签
String publicKey = "公钥";
boolean result = WechatPayUtil.verifySign(body, sign, timestamp, publicKey);
if (!result) {
throw new RuntimeException("签名验证失败");
}
//将请求体再次写入流中
requestContext.setEntityStream(new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)));
阅读全文