🎨 #3757 【微信支付】修复当只设置 privateCertString 或 PrivateCertContent 时 certSerialNo 没有被正确生成的问题
This commit is contained in:
@@ -341,7 +341,7 @@ public class WxPayConfig {
|
|||||||
certificate = (X509Certificate) objects[1];
|
certificate = (X509Certificate) objects[1];
|
||||||
this.certSerialNo = certificate.getSerialNumber().toString(16).toUpperCase();
|
this.certSerialNo = certificate.getSerialNumber().toString(16).toUpperCase();
|
||||||
}
|
}
|
||||||
if (certificate == null && StringUtils.isBlank(this.getCertSerialNo()) && StringUtils.isNotBlank(this.getPrivateCertPath())) {
|
if (certificate == null && StringUtils.isBlank(this.getCertSerialNo()) && (StringUtils.isNotBlank(this.getPrivateCertPath()) || StringUtils.isNotBlank(this.getPrivateCertString())) || this.getPrivateCertContent() != null) {
|
||||||
try (InputStream certInputStream = this.loadConfigInputStream(this.getPrivateCertString(), this.getPrivateCertPath(),
|
try (InputStream certInputStream = this.loadConfigInputStream(this.getPrivateCertString(), this.getPrivateCertPath(),
|
||||||
this.privateCertContent, "privateCertPath")) {
|
this.privateCertContent, "privateCertPath")) {
|
||||||
certificate = PemUtils.loadCertificate(certInputStream);
|
certificate = PemUtils.loadCertificate(certInputStream);
|
||||||
@@ -349,7 +349,7 @@ public class WxPayConfig {
|
|||||||
this.certSerialNo = certificate.getSerialNumber().toString(16).toUpperCase();
|
this.certSerialNo = certificate.getSerialNumber().toString(16).toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getPublicKeyString() != null || this.getPublicKeyPath() != null || this.publicKeyContent != null) {
|
if (StringUtils.isNotBlank(this.getPublicKeyString()) || StringUtils.isNotBlank(this.getPublicKeyPath()) || this.publicKeyContent != null) {
|
||||||
if (StringUtils.isBlank(this.getPublicKeyId())) {
|
if (StringUtils.isBlank(this.getPublicKeyId())) {
|
||||||
throw new WxPayException("请确保和publicKeyId配套使用");
|
throw new WxPayException("请确保和publicKeyId配套使用");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import org.testng.annotations.Test;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -976,4 +977,44 @@ public class BaseWxPayServiceImplTest {
|
|||||||
WxPayUnifiedOrderV3Result.JsapiResult result = payService.createPartnerOrderV3(TradeTypeEnum.JSAPI, request);
|
WxPayUnifiedOrderV3Result.JsapiResult result = payService.createPartnerOrderV3(TradeTypeEnum.JSAPI, request);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_certSerialNoExtractedFromPrivateCertContentOrPrivateCertString() throws Exception {
|
||||||
|
WxPayConfig wxPayConfig = new WxPayConfig();
|
||||||
|
//服务商的参数
|
||||||
|
wxPayConfig.setMchId("xxx");
|
||||||
|
wxPayConfig.setAppId("xxx");
|
||||||
|
wxPayConfig.setApiV3Key("xxx");
|
||||||
|
wxPayConfig.setPrivateKeyContent("xxx".getBytes(StandardCharsets.UTF_8));
|
||||||
|
wxPayConfig.setPrivateCertContent("xxx".getBytes(StandardCharsets.UTF_8)
|
||||||
|
);
|
||||||
|
wxPayConfig.setPublicKeyId("xxx");
|
||||||
|
wxPayConfig.setPublicKeyContent("xxx".getBytes(StandardCharsets.UTF_8));
|
||||||
|
//创建支付服务
|
||||||
|
WxPayService wxPayService = new WxPayServiceImpl();
|
||||||
|
wxPayService.setConfig(wxPayConfig);
|
||||||
|
|
||||||
|
String outTradeNo = RandomUtils.getRandomStr();
|
||||||
|
String notifyUrl = "https://api.qq.com/";
|
||||||
|
System.out.println("outTradeNo = " + outTradeNo);
|
||||||
|
WxPayUnifiedOrderV3Request request = new WxPayUnifiedOrderV3Request();
|
||||||
|
request.setOutTradeNo(outTradeNo);
|
||||||
|
request.setNotifyUrl(notifyUrl);
|
||||||
|
request.setDescription("test");
|
||||||
|
|
||||||
|
WxPayUnifiedOrderV3Request.Payer payer = new WxPayUnifiedOrderV3Request.Payer();
|
||||||
|
payer.setOpenid("xxx");
|
||||||
|
request.setPayer(payer);
|
||||||
|
|
||||||
|
//构建金额信息
|
||||||
|
WxPayUnifiedOrderV3Request.Amount amount = new WxPayUnifiedOrderV3Request.Amount();
|
||||||
|
//设置币种信息
|
||||||
|
amount.setCurrency(WxPayConstants.CurrencyType.CNY);
|
||||||
|
//设置金额
|
||||||
|
amount.setTotal(BaseWxPayRequest.yuan2Fen(BigDecimal.ONE));
|
||||||
|
request.setAmount(amount);
|
||||||
|
|
||||||
|
wxPayService.createOrderV3(TradeTypeEnum.JSAPI, request);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user