微信V3的接口,支付回调验签使用NotificationParser验签解析Transaction,接口并未需要传公钥信息,但是调用后接口返回
Verify the signature and get the WechatPay certificate or publicKey corresponding to serialNumber[PUB_KEY_ID_0115625853912024112500337900000468] is empty.是什么原因。
获取头部信息代码如下:
ServletInputStream inputStream = notifyData.getInputStream();
StringBuffer stringBuffer = new StringBuffer();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String s;
//读取回调请求体
while ((s = bufferedReader.readLine()) != null) {
stringBuffer.append(s);
}
String bodyStr= stringBuffer.toString();
String timestamp = notifyData.getHeader("Wechatpay-Timestamp");
String nonce = notifyData.getHeader("Wechatpay-Nonce");//验签的随机字符串
String signType = notifyData.getHeader("Wechatpay-Signature-Type");
String serial = notifyData.getHeader("Wechatpay-Serial");//验签的微信支付平台证书序列号/微信支付公钥ID
String signature = notifyData.getHeader("Wechatpay-Signature");//验签的签名值
验签解析代码如下:
NotificationConfig config = new RSAAutoCertificateConfig.Builder()
.merchantId(mchId)
.privateKeyFromPath(privateKeyFromPath)
.merchantSerialNumber(merchantSerialNumber)
.apiV3Key(apiV3Key)
.build();
NotificationParser parser = new NotificationParser(config);
RequestParam requestParam = new RequestParam.Builder()
.serialNumber(serial)
.nonce(nonce)
.signature(signature)
.timestamp(timestamp)
.signType(singType)
.body(bodyStr)
.build();
Transaction parse = parser.parse(requestParam, Transaction.class);
你收到的通知是公钥模式,平台公钥模式要用RSAPublicKeyNotificationConfig来初始化