收藏
回答

APP调起支付签名 问题

密钥
String PRIVATE_KEY =  "-----BEGIN PRIVATE KEY-----\n" +
        "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC22GDMFODt5jzI\n" +
       
        "qeZ1Lk5rBIySzBmAbL2PH5k=\n" +
        "-----END PRIVATE KEY-----";

签名方法
public static String sign(byte[] message) throws NoSuchAlgorithmException, SignatureException, InvalidKeyException, UnsupportedEncodingException {
    PrivateKey privateKey = PemUtil.loadPrivateKey(new ByteArrayInputStream(WxPayConstants.PRIVATE_KEY.getBytes("utf-8")));
    Signature sign = Signature.getInstance("SHA256withRSA");
    sign.initSign(privateKey);
    sign.update(message);
    return Base64.getEncoder().encodeToString(sign.sign());
}

调用方式
String timestamp = System.currentTimeMillis() / 1000 + "";

String nonce = RandomUtil.randomString(32);

StringBuilder builder = new StringBuilder();
// appid
builder.append(WxPayConstants.APP_ID).append("\n");
// 时间戳
builder.append(timestamp).append("\n");
// 随机字符串
builder.append(nonce).append("\n");
JsonNode jsonNode = objectMapper.readTree(bodyAsString);
String prepayId = jsonNode.get("prepay_id").asText();
// prepay_id
builder.append(prepayId).append("\n");

String sign = sign(builder.toString().getBytes(StandardCharsets.UTF_8));

这样子生成的签名在前端无法调起微信支付,这个签名哪里出现了问题


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

1 个回答

  • Memory
    Memory
    1天前

    检查一下实际调用参数类型、大小写是否正确,计算签名参数与调起支付时的是否一致

    1天前
    有用
    回复
登录 后发表内容