mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-08-29 09:04:14 +00:00
fix: 修复微信支付v3 api 构建失败报“无可用的平台证书...”问题。
This commit is contained in:
@@ -15,6 +15,7 @@ import org.apache.commons.lang3.RegExUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
import org.dromara.daxpay.channel.wechat.code.WechatPayCode;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.*;
|
||||
@@ -42,6 +43,12 @@ public class WxPayConfig {
|
||||
private static final String PROBLEM_MSG = "证书文件【%s】有问题,请核实!";
|
||||
private static final String NOT_FOUND_MSG = "证书文件【%s】不存在,请核实!";
|
||||
|
||||
/**
|
||||
* 接口版本, 使用v2还是v3接口
|
||||
* @see WechatPayCode#API_V2
|
||||
*/
|
||||
private String apiVersion;
|
||||
|
||||
/**
|
||||
* 微信支付接口请求地址域名部分.
|
||||
*/
|
||||
@@ -277,7 +284,6 @@ public class WxPayConfig {
|
||||
* 初始化api v3请求头 自动签名验签
|
||||
* 方法参照 <a href="https://github.com/wechatpay-apiv3/wechatpay-apache-httpclient">微信支付官方api项目</a>
|
||||
*
|
||||
* @return org.apache.http.impl.client.CloseableHttpClient
|
||||
* @author doger.wang
|
||||
**/
|
||||
public CloseableHttpClient initApiV3HttpClient() throws WxPayException {
|
||||
@@ -353,16 +359,19 @@ public class WxPayConfig {
|
||||
boolean pathC = this.getPrivateCertContent() != null && this.getPrivateKeyContent() != null;
|
||||
boolean pathS = this.getPrivateCertString() != null && this.getPrivateKeyString() != null;
|
||||
|
||||
if (pathB || pathC || pathS) {
|
||||
certificatesVerifier = new AutoUpdateCertificatesVerifier(
|
||||
new WxPayCredentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
|
||||
this.getApiV3Key().getBytes(StandardCharsets.UTF_8), this.getCertAutoUpdateTime(),
|
||||
this.getPayBaseUrl(), wxPayHttpProxy);
|
||||
}
|
||||
if (publicKey != null) {
|
||||
Verifier publicCertificatesVerifier = new PublicCertificateVerifier(publicKey, publicKeyId);
|
||||
publicCertificatesVerifier.setOtherVerifier(certificatesVerifier);
|
||||
certificatesVerifier = publicCertificatesVerifier;
|
||||
if(WechatPayCode.API_V2.equals(this.getApiVersion())){
|
||||
if (pathB || pathC || pathS) {
|
||||
certificatesVerifier = new AutoUpdateCertificatesVerifier(
|
||||
new WxPayCredentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
|
||||
this.getApiV3Key().getBytes(StandardCharsets.UTF_8), this.getCertAutoUpdateTime(),
|
||||
this.getPayBaseUrl(), wxPayHttpProxy);
|
||||
}
|
||||
}else{
|
||||
if (publicKey != null) {
|
||||
Verifier publicCertificatesVerifier = new PublicCertificateVerifier(publicKey, publicKeyId);
|
||||
publicCertificatesVerifier.setOtherVerifier(certificatesVerifier);
|
||||
certificatesVerifier = publicCertificatesVerifier;
|
||||
}
|
||||
}
|
||||
return certificatesVerifier;
|
||||
}
|
||||
@@ -493,4 +502,4 @@ public class WxPayConfig {
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -168,6 +168,7 @@ public class WechatPayConfigService {
|
||||
payConfig.setSubAppId(wechatPayConfig.getSubAppId());
|
||||
payConfig.setMchKey(wechatPayConfig.getApiKeyV2());
|
||||
payConfig.setApiV3Key(wechatPayConfig.getApiKeyV3());
|
||||
payConfig.setApiVersion(wechatPayConfig.getApiVersion());
|
||||
// 注意不要使用base64的方式进行配置, 因为wxjava 是直接读取文本并不会进行解码, 会导致证书异常
|
||||
if (StrUtil.isNotBlank(wechatPayConfig.getPublicKey())){
|
||||
payConfig.setPublicKeyContent(Base64.decode(wechatPayConfig.getPublicKey()));
|
||||
|
Reference in New Issue
Block a user