小程序使用V3版本的微信支付调用成功,收到服务器的应答,通过微信SDK 0.2.1版本获取到微信平台证书并且与应答中的证书编号比较是一致的,接下来按文档说明进行验签,一直验签失败,实在找不出原因了,以下是我的代码
AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
new WechatPay2Credentials(this.wxPayManager.getMchId(),
new PrivateKeySigner(
this.wxPayManager.getSerialNo(),
this.wxPayManager.getPrivateKey())),
this.wxPayManager.getKey().getBytes("utf-8"));
String Timestamp = request.getHeader("Wechatpay-Timestamp");
logger.info("Wechatpay-Timestamp=" + Timestamp);
// 应答随机串
String Nonce = request.getHeader("Wechatpay-Nonce");
logger.info("Wechatpay-Nonce=" + Nonce);
// 应答签名
String SignatureText = request
.getHeader("Wechatpay-Signature");
logger.info("Wechatpay-Signature=" + SignatureText);
//buffer为接收到的JSON格式应答内容
String text = Timestamp + "\n" + Nonce + "\n"
+ buffer.toString() + "\n";
logger.info("text=" + text);
Signature sign = Signature.getInstance("SHA256withRSA");
sign.initVerify(verifier.getValidCertificate()
.getPublicKey());
sign.update(text.getBytes());
boolean verify = sign.verify(Base64.getDecoder().decode(SignatureText.getBytes()));
报签名错误可以根据这个知识库内容排查:https://developers.weixin.qq.com/community/develop/doc/0000a4be9a8d5081d94b4e4c051c09
如果按这几个步骤没有解决您的问题,可以前往V3文档:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/index.shtml 点击右下角“技术咨询”实时寻求技术帮助。
解决了吗