//用此方法生成的密钥去唤起小程序会报错 签名错误 我想验证一下签名生成的对错 替换成文档中的密钥 会直接报错 。。 不知道是文档中提供的密钥不对还是此签名生成方式不对
public static String getSign(String signatureStr, String privateKey) throws Exception {
// String replace = privateKey.replace("\\n", "\n");
PrivateKey merchantPrivateKey = PemUtil.loadPrivateKeyFromPath(privateKey);
Signature sign = Signature.getInstance("SHA256withRSA");
sign.initSign(merchantPrivateKey);
sign.update(signatureStr.getBytes(StandardCharsets.UTF_8));
return Base64Utils.encodeToString(sign.sign());
}
public static void main(String[] args) {
String signatureStr = Stream.of("wx2421b1c4370ec43b", "1554208460", "593BEC0C930BF1AFEB40B4A08C8FB242", "prepay_id=" + "wx201410272009395522657a690389285100")
.collect(Collectors.joining("\n", "", "\n"));
String sign = null;
try {
sign = getSign(signatureStr, "D:\\data\\apiclient_key.pem");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(sign);
}
https://pay.weixin.qq.com/doc/v3/merchant/4012365341 如果密钥文件换成参考文档中的密钥文件会报错