1
1
package com .wechat .pay .java .core ;
2
2
3
+ import static com .wechat .pay .java .core .notification .Constant .AES_CIPHER_ALGORITHM ;
4
+ import static com .wechat .pay .java .core .notification .Constant .RSA_SIGN_TYPE ;
3
5
import static java .util .Objects .requireNonNull ;
4
6
5
7
import com .wechat .pay .java .core .certificate .CertificateProvider ;
6
8
import com .wechat .pay .java .core .certificate .RSAAutoCertificateProvider ;
9
+ import com .wechat .pay .java .core .cipher .AeadAesCipher ;
10
+ import com .wechat .pay .java .core .cipher .AeadCipher ;
11
+ import com .wechat .pay .java .core .cipher .RSAVerifier ;
12
+ import com .wechat .pay .java .core .cipher .Verifier ;
7
13
import com .wechat .pay .java .core .http .HttpClient ;
14
+ import com .wechat .pay .java .core .notification .NotificationConfig ;
8
15
import java .nio .charset .StandardCharsets ;
9
- import java .security .PrivateKey ;
10
16
11
17
/** 具有自动下载平台证书能力的RSA配置类 */
12
- public final class RSAAutoCertificateConfig extends AbstractRSAConfig {
13
-
14
- private RSAAutoCertificateConfig (
15
- String merchantId ,
16
- PrivateKey privateKey ,
17
- String merchantSerialNumber ,
18
- CertificateProvider certificateProvider ) {
19
- super (merchantId , privateKey , merchantSerialNumber , certificateProvider );
18
+ public final class RSAAutoCertificateConfig extends AbstractRSAConfig
19
+ implements NotificationConfig {
20
+
21
+ private final CertificateProvider certificateProvider ;
22
+ private final AeadCipher aeadCipher ;
23
+
24
+ private RSAAutoCertificateConfig (Builder builder ) {
25
+ super (
26
+ builder .merchantId ,
27
+ builder .privateKey ,
28
+ builder .merchantSerialNumber ,
29
+ builder .certificateProvider );
30
+ this .certificateProvider = builder .certificateProvider ;
31
+ this .aeadCipher = new AeadAesCipher (builder .apiV3Key );
32
+ }
33
+
34
+ /**
35
+ * 获取签名类型
36
+ *
37
+ * @return 签名类型
38
+ */
39
+ @ Override
40
+ public String getSignType () {
41
+ return RSA_SIGN_TYPE ;
42
+ }
43
+
44
+ /**
45
+ * 获取认证加解密器类型
46
+ *
47
+ * @return 认证加解密器类型
48
+ */
49
+ @ Override
50
+ public String getCipherType () {
51
+ return AES_CIPHER_ALGORITHM ;
52
+ }
53
+
54
+ /**
55
+ * 创建验签器
56
+ *
57
+ * @return 验签器
58
+ */
59
+ @ Override
60
+ public Verifier createVerifier () {
61
+ return new RSAVerifier (certificateProvider );
62
+ }
63
+
64
+ /**
65
+ * 创建认证加解密器
66
+ *
67
+ * @return 认证加解密器
68
+ */
69
+ @ Override
70
+ public AeadCipher createAeadCipher () {
71
+ return aeadCipher ;
20
72
}
21
73
22
74
public static class Builder extends AbstractRSAConfigBuilder <Builder > {
23
75
protected HttpClient httpClient ;
24
76
protected byte [] apiV3Key ;
77
+ protected CertificateProvider certificateProvider ;
25
78
26
79
public Builder apiV3Key (String apiV3key ) {
27
80
this .apiV3Key = apiV3key .getBytes (StandardCharsets .UTF_8 );
@@ -48,8 +101,10 @@ public RSAAutoCertificateConfig build() {
48
101
if (httpClient != null ) {
49
102
providerBuilder .httpClient (httpClient );
50
103
}
51
- return new RSAAutoCertificateConfig (
52
- merchantId , privateKey , merchantSerialNumber , providerBuilder .build ());
104
+
105
+ certificateProvider = providerBuilder .build ();
106
+
107
+ return new RSAAutoCertificateConfig (this );
53
108
}
54
109
}
55
110
}
0 commit comments