Skip to content

Commit

Permalink
🎨 #3242 【微信支付】修改自动更新证书接口地址,使用WxPayConfig设置的payBaseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
HaalandCR authored Mar 4, 2024
1 parent b87afb6 commit 573f0f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public CloseableHttpClient initApiV3HttpClient() throws WxPayException {

AutoUpdateCertificatesVerifier certificatesVerifier = new AutoUpdateCertificatesVerifier(
new WxPayCredentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
this.getApiV3Key().getBytes(StandardCharsets.UTF_8), this.getCertAutoUpdateTime(), wxPayHttpProxy);
this.getApiV3Key().getBytes(StandardCharsets.UTF_8), this.getCertAutoUpdateTime(), this.getPayBaseUrl(), wxPayHttpProxy);

WxPayV3HttpClientBuilder wxPayV3HttpClientBuilder = WxPayV3HttpClientBuilder.create()
.withMerchant(mchId, certSerialNo, merchantPrivateKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class AutoUpdateCertificatesVerifier implements Verifier {
/**
* 证书下载地址
*/
private static final String CERT_DOWNLOAD_PATH = "https://api.mch.weixin.qq.com/v3/certificates";
private static final String CERT_DOWNLOAD_PATH = "/v3/certificates";

/**
* 上次更新时间
Expand All @@ -64,6 +64,8 @@ public class AutoUpdateCertificatesVerifier implements Verifier {

private final byte[] apiV3Key;

private String payBaseUrl ;

private final ReentrantLock lock = new ReentrantLock();

/**
Expand Down Expand Up @@ -93,18 +95,19 @@ public enum TimeInterval {
private final int minutes;
}

public AutoUpdateCertificatesVerifier(Credentials credentials, byte[] apiV3Key) {
this(credentials, apiV3Key, TimeInterval.OneHour.getMinutes());
public AutoUpdateCertificatesVerifier(Credentials credentials, byte[] apiV3Key, String payBaseUrl) {
this(credentials, apiV3Key, TimeInterval.OneHour.getMinutes(), payBaseUrl);
}

public AutoUpdateCertificatesVerifier(Credentials credentials, byte[] apiV3Key, int minutesInterval) {
this(credentials,apiV3Key,minutesInterval,null);
public AutoUpdateCertificatesVerifier(Credentials credentials, byte[] apiV3Key, int minutesInterval, String payBaseUrl) {
this(credentials, apiV3Key, minutesInterval, payBaseUrl, null);
}

public AutoUpdateCertificatesVerifier(Credentials credentials, byte[] apiV3Key, int minutesInterval,WxPayHttpProxy wxPayHttpProxy) {
public AutoUpdateCertificatesVerifier(Credentials credentials, byte[] apiV3Key, int minutesInterval, String payBaseUrl, WxPayHttpProxy wxPayHttpProxy) {
this.credentials = credentials;
this.apiV3Key = apiV3Key;
this.minutesInterval = minutesInterval;
this.payBaseUrl = payBaseUrl;
this.wxPayHttpProxy = wxPayHttpProxy;
//构造时更新证书
try {
Expand Down Expand Up @@ -153,7 +156,7 @@ private void autoUpdateCert() throws IOException, GeneralSecurityException {

CloseableHttpClient httpClient = wxPayV3HttpClientBuilder.build();

HttpGet httpGet = new HttpGet(CERT_DOWNLOAD_PATH);
HttpGet httpGet = new HttpGet(this.payBaseUrl + CERT_DOWNLOAD_PATH);
httpGet.addHeader("Accept", "application/json");

CloseableHttpResponse response = httpClient.execute(httpGet);
Expand Down

0 comments on commit 573f0f5

Please sign in to comment.