官网地址:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_1.shtml
public class WxPayUtil {
private String privateKey = ""; //privateKey:私钥字符串
private String mchId = ""; //商户号
private String mchSerialNo = ""; //mchSerialNo:商户证书序列号
private String apiV3Key = ""; //apiV3Key:V3密钥
private String appid = ""; //应用ID
private String notifyUrl = "https://weixin.qq.com/"; //通知URL必须为直接可访问的URL,不允许携带查询串,要求必须为https地址。
public static String getUUID() {
System.out.println(UUID.randomUUID());
String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
return uuid;
}
public CloseableHttpClient setup() throws IOException {
// 加载商户私钥(privateKey:私钥字符串)
// PrivateKey merchantPrivateKey = getPrivateKey("D:\\tools\\wb.txt");
PrivateKey merchantPrivateKey = PemUtil
.loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes(StandardCharsets.UTF_8)));
// 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3密钥)
AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey)), apiV3Key.