native微信使用sdk wechatpay-java支付成功 退款成功 就是 支付回调验签失败?
// 从请求头中获取信息
String wechatPaySerial = request.getHeader("Wechatpay-Signature");
System.out.println("wechatPaySerial"+wechatPaySerial);
String wechatSignature = request.getHeader("Wechatpay-Serial");
System.out.println("Wechatpay-Serial"+wechatSignature);
String wechatpayNonce = request.getHeader("Wechatpay-Nonce");
String wechatTimestamp = request.getHeader("Wechatpay-Timestamp");
// String singType = request.getHeader("Wechatpay-Signature-Type");
// 拿到请求体body
StringBuilder requestBody = null;
try {
//读取请求体的信息
ServletInputStream inputStream = request.getInputStream();
// StringBuffer stringBuffer = new StringBuffer();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
requestBody = new StringBuilder();
String line;
// BufferedReader reader;
// reader = request.getReader();
while (null != (line = bufferedReader.readLine())) {
requestBody.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("body"+requestBody);
// 构造 RequestParam
// 构造 RequestParam
RequestParam requestParam = new RequestParam.Builder()
.serialNumber(wechatPaySerial)
.nonce(wechatpayNonce)
.signature(wechatSignature)
.timestamp(wechatTimestamp)
.body(requestBody.toString())
.build();
System.out.println("requestParam"+requestParam);
// 如果已经初始化了 RSAAutoCertificateConfig,可直接使用
// 没有的话,则构造一个
// NotificationConfig config = new RSAAutoCertificateConfig.Builder()
// .merchantId(merchantId)
// .privateKeyFromPath(privateKeyPath)
// .merchantSerialNumber(merchantSerialNumber)
// .apiV3Key(apiV3Key)
// .build();
// 初始化 NotificationParser
NotificationParser parser = new NotificationParser((NotificationConfig) getConfig());
try {
// 以支付通知回调为例,验签、解密并转换成 Transaction
System.out.println("开始回调!");
Transaction transaction = parser.parse(requestParam, Transaction.class);
System.out.println("transaction"+transaction);
} catch (ValidationException e) {
// 签名验证失败,返回 401 UNAUTHORIZED 状态码
logger.error("sign verification failed", e);
}