收藏
回答

【求助】微信小程序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

回答关注问题邀请回答
收藏

1 个回答

  • 用爱发电
    用爱发电
    2022-05-26

    签名工具只校验签名的方式是否正确,不校验参数的正确性。无非就是计算签名参数与调起参数不一致或者签名拼接出错导致的,先用工具生成签名,前端写固定参数去调起看看是否能成功

    2022-05-26
    有用
    回复
登录 后发表内容