【求助】微信小程序V3 支付失败,验签通过,唤起支付失败问题
后端技术:java 【第一步】准备的 字符串构造器; String buildMessage(String appid, String timestamp,String nonceStr,String prepay_id) {
return appid + "\n"
+ timestamp + "\n"
+ nonceStr + "\n"
+ prepay_id + "\n";
}
String appid 小程序的APPID String timeStamp = String.valueOf(System.currentTimeMillis()/1000); String nonceStr 随机字符串 String prepay_id 预下单ID,拼接时已经 转换 "prepay_id=wx**********" *****下单时遵循官方文档 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml 【第二步】准备的签名方法; public String sign(byte[] message) {
Signature signature = null;
try {
signature = Signature.getInstance("SHA256withRSA");
signature.initSign(merchantPrivateKey);
signature.update(message);
return Base64.getEncoder().encodeToString(signature.sign());
} catch (Exception e) {
e.printStackTrace();
}
throw new RuntimeException("微信小程序签名失败");
}
加密后 [图片] 返回给前端的JSON { "amount": 1, "appId": "wx****************0", "nonceStr": "miniPRE22052604869632", "payNo": "PRE22052604869632", "paySign": "EjiAXnhqQkTkcMcEWtrXnRL9QGQ/YnCsxYEQe6e/hDNSZti29KwsKnMGcsJnqcU/n42GmzwqSI8MCVGktn5V71GHh6utKLjae/eoiB5aF7saFTUSqb06OoyT5gn2tfEfpcIf9qcYapLU1ntdTu9mnMkCVd97zlXGeulhO94R5MCm2z1NWrgFcniMLd0Z6i7LOFJRiXky/ZpW55hxsaAwEWjhDZLC2N2w3IZmHwyCaKc965Kzfn/qQGp8hZg1fASPwU6oN5ljfOPhsJsha9lV/2wlThRUYl+dVII/c86Z8yOo+3ShRDPDM0tz2fHdfawd+8*ehM9ii31d7N9K1l6GtQ==", "prepayId": "wx*******************", "signType": "RSA", "timeStamp": "1653569886" } [图片] 然后就入坑了 [图片] *** 唤起时准许的官方文档 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_4.shtml [图片]