Skip to content

Commit 71fb295

Browse files
添加注释 & 文件格式化
1 parent dc9c846 commit 71fb295

17 files changed

+230
-193
lines changed

.editorconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs
2+
# https://editorconfig.org
13
root = true
24

35
[*]
@@ -25,4 +27,4 @@ continuation_indent_size = 8
2527
[{*.markdown,*.md}]
2628
indent_size = 4
2729
tab_width = 4
28-
continuation_indent_size = 8
30+
continuation_indent_size = 8

build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,3 @@ publishing {
9191
signing {
9292
sign publishing.publications.maven
9393
}
94-
95-
96-
97-
98-

settings.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
rootProject.name = 'wechatpay-apache-httpclient'
2-
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
package com.wechat.pay.contrib.apache.httpclient;
2-
3-
import java.io.IOException;
4-
import org.apache.http.client.methods.HttpRequestWrapper;
5-
6-
public interface Credentials {
7-
8-
String getSchema();
9-
10-
String getToken(HttpRequestWrapper request) throws IOException;
11-
12-
}
1+
package com.wechat.pay.contrib.apache.httpclient;
2+
3+
import java.io.IOException;
4+
import org.apache.http.client.methods.HttpRequestWrapper;
5+
6+
/**
7+
* @author xy-peng
8+
*/
9+
public interface Credentials {
10+
11+
String getSchema();
12+
13+
String getToken(HttpRequestWrapper request) throws IOException;
14+
15+
}

src/main/java/com/wechat/pay/contrib/apache/httpclient/Validator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import java.io.IOException;
44
import org.apache.http.client.methods.CloseableHttpResponse;
55

6+
/**
7+
* @author xy-peng
8+
*/
69
public interface Validator {
710

811
boolean validate(CloseableHttpResponse response) throws IOException;
912

10-
}
13+
}

src/main/java/com/wechat/pay/contrib/apache/httpclient/WechatPayHttpClientBuilder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import org.apache.http.impl.client.HttpClientBuilder;
1212
import org.apache.http.impl.execchain.ClientExecChain;
1313

14+
/**
15+
* @author xy-peng
16+
*/
1417
public class WechatPayHttpClientBuilder extends HttpClientBuilder {
1518

1619
private static final String OS = System.getProperty("os.name") + "/" + System.getProperty("os.version");
@@ -78,4 +81,4 @@ protected ClientExecChain decorateProtocolExec(final ClientExecChain requestExec
7881
return new SignatureExec(this.credentials, this.validator, requestExecutor);
7982
}
8083

81-
}
84+
}

src/main/java/com/wechat/pay/contrib/apache/httpclient/WechatPayUploadHttpPost.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import org.apache.http.entity.mime.HttpMultipartMode;
1212
import org.apache.http.entity.mime.MultipartEntityBuilder;
1313

14+
/**
15+
* @author xy-peng
16+
*/
1417
public class WechatPayUploadHttpPost extends HttpPost {
1518

1619
private final String meta;

src/main/java/com/wechat/pay/contrib/apache/httpclient/auth/AutoUpdateCertificatesVerifier.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
/**
3434
* 在原有CertificatesVerifier基础上,增加自动更新证书功能
35+
*
36+
* @author xy-peng
3537
*/
3638
public class AutoUpdateCertificatesVerifier implements Verifier {
3739

@@ -155,4 +157,4 @@ protected List<X509Certificate> deserializeToCerts(byte[] apiV3Key, String body)
155157
return newCertList;
156158
}
157159

158-
}
160+
}

src/main/java/com/wechat/pay/contrib/apache/httpclient/auth/CertificatesVerifier.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import java.util.List;
1414
import java.util.NoSuchElementException;
1515

16+
/**
17+
* @author xy-peng
18+
*/
1619
public class CertificatesVerifier implements Verifier {
1720

1821
protected final HashMap<BigInteger, X509Certificate> certificates = new HashMap<>();
@@ -58,4 +61,4 @@ public X509Certificate getValidCertificate() {
5861
throw new NoSuchElementException("没有有效的微信支付平台证书");
5962
}
6063

61-
}
64+
}
Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
1-
package com.wechat.pay.contrib.apache.httpclient.auth;
2-
3-
import java.security.InvalidKeyException;
4-
import java.security.NoSuchAlgorithmException;
5-
import java.security.PrivateKey;
6-
import java.security.Signature;
7-
import java.security.SignatureException;
8-
import java.util.Base64;
9-
10-
public class PrivateKeySigner implements Signer {
11-
12-
protected final String certificateSerialNumber;
13-
protected final PrivateKey privateKey;
14-
15-
public PrivateKeySigner(String serialNumber, PrivateKey privateKey) {
16-
this.certificateSerialNumber = serialNumber;
17-
this.privateKey = privateKey;
18-
}
19-
20-
@Override
21-
public SignatureResult sign(byte[] message) {
22-
try {
23-
Signature sign = Signature.getInstance("SHA256withRSA");
24-
sign.initSign(privateKey);
25-
sign.update(message);
26-
return new SignatureResult(Base64.getEncoder().encodeToString(sign.sign()), certificateSerialNumber);
27-
28-
} catch (NoSuchAlgorithmException e) {
29-
throw new RuntimeException("当前Java环境不支持SHA256withRSA", e);
30-
} catch (SignatureException e) {
31-
throw new RuntimeException("签名计算失败", e);
32-
} catch (InvalidKeyException e) {
33-
throw new RuntimeException("无效的私钥", e);
34-
}
35-
}
36-
37-
}
1+
package com.wechat.pay.contrib.apache.httpclient.auth;
2+
3+
import java.security.InvalidKeyException;
4+
import java.security.NoSuchAlgorithmException;
5+
import java.security.PrivateKey;
6+
import java.security.Signature;
7+
import java.security.SignatureException;
8+
import java.util.Base64;
9+
10+
/**
11+
* @author xy-peng
12+
*/
13+
public class PrivateKeySigner implements Signer {
14+
15+
protected final String certificateSerialNumber;
16+
protected final PrivateKey privateKey;
17+
18+
public PrivateKeySigner(String serialNumber, PrivateKey privateKey) {
19+
this.certificateSerialNumber = serialNumber;
20+
this.privateKey = privateKey;
21+
}
22+
23+
@Override
24+
public SignatureResult sign(byte[] message) {
25+
try {
26+
Signature sign = Signature.getInstance("SHA256withRSA");
27+
sign.initSign(privateKey);
28+
sign.update(message);
29+
return new SignatureResult(Base64.getEncoder().encodeToString(sign.sign()), certificateSerialNumber);
30+
31+
} catch (NoSuchAlgorithmException e) {
32+
throw new RuntimeException("当前Java环境不支持SHA256withRSA", e);
33+
} catch (SignatureException e) {
34+
throw new RuntimeException("签名计算失败", e);
35+
} catch (InvalidKeyException e) {
36+
throw new RuntimeException("无效的私钥", e);
37+
}
38+
}
39+
40+
}

0 commit comments

Comments
 (0)