- 微信小程序 V3 拉起微信支付 报支付签名认证失败
在调用https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi接口后微信返回一个 [图片] 然后根据prepay_id 去给前端返回一些 拉起支付的时候 需要加密 [图片] 加密Sign 也返回的 但是拉起支付的时候 返回 支付签名认证失败
2021-01-18 - 微信小程序支付v3接口生成二次签名paysign,一直提示支付验证失败?
public static String getTokenTwo (String appId, String packag) throws IOException, SignatureException, NoSuchAlgorithmException, InvalidKeyException { String nonceStr = getRandomString(32); long timestamp = System.currentTimeMillis() / 1000; String message = buildMessageTwo( appId,timestamp,nonceStr,packag); String signature = sign(message.getBytes("utf-8")); return signature; } private static String buildMessageTwo(String appId, long timestamp, String nonceStr, String packag) { return appId + "\n" + timestamp + "\n" + nonceStr + "\n" + packag + "\n"; } private static String sign(byte[] message) throws NoSuchAlgorithmException, SignatureException, IOException, InvalidKeyException { Signature sign = Signature.getInstance("SHA256withRSA"); //SHA256withRSA PrivateKey privateKey = getPrivateKey("密钥文件地址"); sign.initSign(privateKey); sign.update(message); return Base64.getEncoder().encodeToString(sign.sign()); }
2020-12-28