FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

:art: 【微信支付】服务商模式-兼容公钥模式下请求头序列号 by SynchPj · Pull Request #3498 · binarywang/WxJava · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,7 @@ public CloseableHttpClient initApiV3HttpClient() throws WxPayException {
//构造Http Proxy正向代理
WxPayHttpProxy wxPayHttpProxy = getWxPayHttpProxy();

Verifier certificatesVerifier;
if (publicKey == null) {
certificatesVerifier =
new AutoUpdateCertificatesVerifier(
new WxPayCredentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
this.getApiV3Key().getBytes(StandardCharsets.UTF_8), this.getCertAutoUpdateTime(),
this.getPayBaseUrl(), wxPayHttpProxy);
} else {
certificatesVerifier = new PublicCertificateVerifier(publicKey, publicKeyId);
}
Verifier certificatesVerifier = getVerifier(merchantPrivateKey, wxPayHttpProxy, publicKey);

WxPayV3HttpClientBuilder wxPayV3HttpClientBuilder = WxPayV3HttpClientBuilder.create()
.withMerchant(mchId, certSerialNo, merchantPrivateKey)
Expand All @@ -355,6 +346,19 @@ public CloseableHttpClient initApiV3HttpClient() throws WxPayException {
}
}

private Verifier getVerifier(PrivateKey merchantPrivateKey, WxPayHttpProxy wxPayHttpProxy, PublicKey publicKey) {
Verifier 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;
}
return certificatesVerifier;
}

/**
* 初始化一个WxPayHttpProxy对象
*
Expand Down Expand Up @@ -382,7 +386,7 @@ private InputStream loadConfigInputStream(String configString, String configPath
if (configContent != null) {
return new ByteArrayInputStream(configContent);
}

if (StringUtils.isNotEmpty(configString)) {
configContent = Base64.getDecoder().decode(configString);
return new ByteArrayInputStream(configContent);
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public String postV3(String url, String requestStr) throws WxPayException {
HttpPost httpPost = this.createHttpPost(url, requestStr);
httpPost.addHeader(ACCEPT, APPLICATION_JSON);
httpPost.addHeader(CONTENT_TYPE, APPLICATION_JSON);
String serialNumber = getWechatpaySerial(getConfig());
httpPost.addHeader("Wechatpay-Serial", serialNumber);
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
//v3已经改为通过状态码判断200 204 成功
int statusCode = response.getStatusLine().getStatusCode();
Expand Down Expand Up @@ -387,10 +389,9 @@ private WxPayException convertException(JsonObject jsonObject) {
* @return
*/
private String getWechatpaySerial(WxPayConfig wxPayConfig) {
String serialNumber = wxPayConfig.getVerifier().getValidCertificate().getSerialNumber().toString(16).toUpperCase();
if (StringUtils.isNotBlank(wxPayConfig.getPublicKeyId())) {
serialNumber = wxPayConfig.getPublicKeyId();
return wxPayConfig.getPublicKeyId();
}
return serialNumber;
return wxPayConfig.getVerifier().getValidCertificate().getSerialNumber().toString(16).toUpperCase();
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,24 @@ public class PublicCertificateVerifier implements Verifier{

private final PublicKey publicKey;

private Verifier certificateVerifier;

private final X509PublicCertificate publicCertificate;

public PublicCertificateVerifier(PublicKey publicKey, String publicId) {
this.publicKey = publicKey;
this.publicCertificate = new X509PublicCertificate(publicKey, publicId);
}

public void setOtherVerifier(Verifier verifier) {
this.certificateVerifier = verifier;
}

@Override
public boolean verify(String serialNumber, byte[] message, String signature) {
if (!serialNumber.contains("PUB_KEY_ID")) {
return this.certificateVerifier.verify(serialNumber, message, signature);
}
try {
Signature sign = Signature.getInstance("SHA256withRSA");
sign.initVerify(publicKey);
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public interface Verifier {


X509Certificate getValidCertificate();

default void setOtherVerifier(Verifier verifier) {};
}

Back | FazBrowse Home | New Git URL