-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a98e5df
commit 00ab107
Showing
6 changed files
with
230 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
94 changes: 94 additions & 0 deletions
94
core/src/main/java/com/wechat/pay/java/core/notification/RSACombinedNotificationConfig.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.wechat.pay.java.core.notification; | ||
|
||
import static com.wechat.pay.java.core.notification.Constant.AES_CIPHER_ALGORITHM; | ||
import static com.wechat.pay.java.core.notification.Constant.RSA_SIGN_TYPE; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import com.wechat.pay.java.core.AbstractRSAConfigBuilder; | ||
import com.wechat.pay.java.core.certificate.CertificateProvider; | ||
import com.wechat.pay.java.core.certificate.RSAAutoCertificateProvider; | ||
import com.wechat.pay.java.core.cipher.AeadAesCipher; | ||
import com.wechat.pay.java.core.cipher.AeadCipher; | ||
import com.wechat.pay.java.core.http.HttpClient; | ||
import com.wechat.pay.java.core.util.PemUtil; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.PublicKey; | ||
|
||
/** 通知回调配置类 该类仅在商户由平台证书切换为平台公钥的灰度阶段使用,灰度完成后请切换为RSAPublicKeyNotificationConfig */ | ||
public final class RSACombinedNotificationConfig extends AbstractNotificationConfig { | ||
|
||
private RSACombinedNotificationConfig( | ||
CertificateProvider certificateProvider, | ||
PublicKey publicKey, | ||
String publicKeyId, | ||
AeadCipher aeadAesCipher) { | ||
super( | ||
RSA_SIGN_TYPE, | ||
AES_CIPHER_ALGORITHM, | ||
certificateProvider, | ||
publicKey, | ||
publicKeyId, | ||
aeadAesCipher); | ||
} | ||
|
||
public static class Builder extends AbstractRSAConfigBuilder<Builder> { | ||
protected HttpClient httpClient; | ||
protected byte[] apiV3Key; | ||
|
||
private PublicKey publicKey; | ||
private String publicKeyId; | ||
|
||
public Builder apiV3Key(String apiV3Key) { | ||
this.apiV3Key = apiV3Key.getBytes(StandardCharsets.UTF_8); | ||
return this; | ||
} | ||
|
||
public Builder httpClient(HttpClient httpClient) { | ||
this.httpClient = httpClient; | ||
return this; | ||
} | ||
|
||
public Builder publicKey(String publicKey) { | ||
this.publicKey = PemUtil.loadPublicKeyFromString(publicKey); | ||
return this; | ||
} | ||
|
||
public Builder publicKey(PublicKey publicKey) { | ||
this.publicKey = publicKey; | ||
return this; | ||
} | ||
|
||
public Builder publicFromPath(String publicKeyPath) { | ||
this.publicKey = PemUtil.loadPublicKeyFromPath(publicKeyPath); | ||
return this; | ||
} | ||
|
||
public Builder publicKeyId(String publicKeyId) { | ||
this.publicKeyId = publicKeyId; | ||
return this; | ||
} | ||
|
||
@Override | ||
protected Builder self() { | ||
return this; | ||
} | ||
|
||
public RSACombinedNotificationConfig build() { | ||
|
||
RSAAutoCertificateProvider.Builder builder = | ||
new RSAAutoCertificateProvider.Builder() | ||
.apiV3Key(requireNonNull(apiV3Key)) | ||
.privateKey(requireNonNull(privateKey)) | ||
.merchantId(requireNonNull(merchantId)) | ||
.merchantSerialNumber(requireNonNull(merchantSerialNumber)); | ||
if (httpClient != null) { | ||
builder.httpClient(httpClient); | ||
} | ||
return new RSACombinedNotificationConfig( | ||
builder.build(), | ||
requireNonNull(publicKey), | ||
requireNonNull(publicKeyId), | ||
new AeadAesCipher(requireNonNull(apiV3Key))); | ||
} | ||
} | ||
} |
This file contains 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
60 changes: 60 additions & 0 deletions
60
core/src/main/java/com/wechat/pay/java/core/notification/RSAPublicKeyNotificationConfig.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.wechat.pay.java.core.notification; | ||
|
||
import static com.wechat.pay.java.core.notification.Constant.AES_CIPHER_ALGORITHM; | ||
import static com.wechat.pay.java.core.notification.Constant.RSA_SIGN_TYPE; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import com.wechat.pay.java.core.cipher.AeadAesCipher; | ||
import com.wechat.pay.java.core.cipher.AeadCipher; | ||
import com.wechat.pay.java.core.util.PemUtil; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.PublicKey; | ||
|
||
/** 签名类型为RSA的通知配置参数 */ | ||
public final class RSAPublicKeyNotificationConfig extends AbstractNotificationConfig { | ||
|
||
private RSAPublicKeyNotificationConfig( | ||
PublicKey publicKey, String publicKeyId, AeadCipher aeadCipher) { | ||
super(RSA_SIGN_TYPE, AES_CIPHER_ALGORITHM, publicKey, publicKeyId, aeadCipher); | ||
} | ||
|
||
public static class Builder { | ||
private byte[] apiV3Key; | ||
|
||
private PublicKey publicKey; | ||
private String publicKeyId; | ||
|
||
public Builder publicKey(String publicKey) { | ||
this.publicKey = PemUtil.loadPublicKeyFromString(publicKey); | ||
return this; | ||
} | ||
|
||
public Builder publicKey(PublicKey publicKey) { | ||
this.publicKey = publicKey; | ||
return this; | ||
} | ||
|
||
public Builder publicFromPath(String publicKeyPath) { | ||
this.publicKey = PemUtil.loadPublicKeyFromPath(publicKeyPath); | ||
return this; | ||
} | ||
|
||
public Builder apiV3Key(String apiV3Key) { | ||
this.apiV3Key = apiV3Key.getBytes(StandardCharsets.UTF_8); | ||
return this; | ||
} | ||
|
||
public Builder publicKeyId(String publicKeyId) { | ||
this.publicKeyId = publicKeyId; | ||
return this; | ||
} | ||
|
||
public RSAPublicKeyNotificationConfig build() { | ||
requireNonNull(publicKey); | ||
requireNonNull(publicKeyId); | ||
requireNonNull(apiV3Key); | ||
return new RSAPublicKeyNotificationConfig( | ||
publicKey, requireNonNull(publicKeyId), new AeadAesCipher(requireNonNull(apiV3Key))); | ||
} | ||
} | ||
} |