You've already forked FrameTour-BE
支付
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
package com.ycwl.basic.utils;
|
||||
|
||||
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import com.wechat.pay.java.core.util.PemUtil;
|
||||
import org.springframework.util.Base64Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.*;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @Author: songmingsong
|
||||
* @CreateTime: 2024-12-05
|
||||
* @Description: 微信支付
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class WXPayUtil {
|
||||
|
||||
private static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
private static final Random RANDOM = new SecureRandom();
|
||||
|
||||
|
||||
public static String getSign(String signatureStr,String privateKey) throws InvalidKeyException, NoSuchAlgorithmException, SignatureException, IOException, URISyntaxException {
|
||||
//replace 根据实际情况,不一定都需要
|
||||
String replace = privateKey.replace("\\n", "\n");
|
||||
PrivateKey merchantPrivateKey = PemUtil.loadPrivateKeyFromString(replace);
|
||||
Signature sign = Signature.getInstance("SHA256withRSA");
|
||||
sign.initSign(merchantPrivateKey);
|
||||
sign.update(signatureStr.getBytes(StandardCharsets.UTF_8));
|
||||
return Base64Utils.encodeToString(sign.sign());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取随机字符串 Nonce Str
|
||||
*
|
||||
* @return String 随机字符串
|
||||
*/
|
||||
public static String generateNonceStr() {
|
||||
char[] nonceChars = new char[32];
|
||||
for (int index = 0; index < nonceChars.length; ++index) {
|
||||
nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
|
||||
}
|
||||
return new String(nonceChars);
|
||||
}
|
||||
|
||||
public static Map<String, Object> xmlToMap(String xmlData) {
|
||||
return XmlUtil.xmlToMap(xmlData);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user