Skip to content

Commit bdf7f79

Browse files
committed
微信支付优化部分代码,方便扩展
1 parent 7daeff2 commit bdf7f79

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,20 @@ public void setUseSandboxEnv(boolean useSandboxEnv) {
163163
}
164164

165165
public SSLContext initSSLContext() throws WxPayException {
166-
if (StringUtils.isBlank(mchId)) {
166+
if (StringUtils.isBlank(this.getMchId())) {
167167
throw new WxPayException("请确保商户号mchId已设置");
168168
}
169169

170-
if (StringUtils.isBlank(this.keyPath)) {
170+
if (StringUtils.isBlank(this.getKeyPath())) {
171171
throw new WxPayException("请确保证书文件地址keyPath已配置");
172172
}
173173

174174
InputStream inputStream;
175175
final String prefix = "classpath:";
176-
String fileHasProblemMsg = "证书文件【" + this.keyPath + "】有问题,请核实!";
177-
String fileNotFoundMsg = "证书文件【" + this.keyPath + "】不存在,请核实!";
178-
if (this.keyPath.startsWith(prefix)) {
179-
String path = StringUtils.removeFirst(this.keyPath, prefix);
176+
String fileHasProblemMsg = "证书文件【" + this.getKeyPath() + "】有问题,请核实!";
177+
String fileNotFoundMsg = "证书文件【" + this.getKeyPath() + "】不存在,请核实!";
178+
if (this.getKeyPath().startsWith(prefix)) {
179+
String path = StringUtils.removeFirst(this.getKeyPath(), prefix);
180180
if (!path.startsWith("/")) {
181181
path = "/" + path;
182182
}
@@ -186,7 +186,7 @@ public SSLContext initSSLContext() throws WxPayException {
186186
}
187187
} else {
188188
try {
189-
File file = new File(this.keyPath);
189+
File file = new File(this.getKeyPath());
190190
if (!file.exists()) {
191191
throw new WxPayException(fileNotFoundMsg);
192192
}
@@ -199,7 +199,7 @@ public SSLContext initSSLContext() throws WxPayException {
199199

200200
try {
201201
KeyStore keystore = KeyStore.getInstance("PKCS12");
202-
char[] partnerId2charArray = mchId.toCharArray();
202+
char[] partnerId2charArray = this.getMchId().toCharArray();
203203
keystore.load(inputStream, partnerId2charArray);
204204
this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build();
205205
return this.sslContext;

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ protected String post(String url, String requestStr, boolean useKey) throws WxPa
5353
.setSocketTimeout(this.getConfig().getHttpTimeout())
5454
.build());
5555

56-
if (StringUtils.isNotBlank(this.config.getHttpProxyHost())
57-
&& this.config.getHttpProxyPort() > 0) {
56+
if (StringUtils.isNotBlank(this.getConfig().getHttpProxyHost())
57+
&& this.getConfig().getHttpProxyPort() > 0) {
5858
// 使用代理服务器 需要用户认证的代理服务器
5959
CredentialsProvider provider = new BasicCredentialsProvider();
6060
provider.setCredentials(
61-
new AuthScope(this.config.getHttpProxyHost(), this.config.getHttpProxyPort()),
62-
new UsernamePasswordCredentials(this.config.getHttpProxyUsername(), this.config.getHttpProxyPassword()));
61+
new AuthScope(this.getConfig().getHttpProxyHost(), this.getConfig().getHttpProxyPort()),
62+
new UsernamePasswordCredentials(this.getConfig().getHttpProxyUsername(), this.getConfig().getHttpProxyPassword()));
6363
httpClientBuilder.setDefaultCredentialsProvider(provider);
6464
}
6565

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ protected String post(String url, String requestStr, boolean useKey) throws WxPa
2626
try {
2727
HttpRequest request = HttpRequest
2828
.post(url)
29-
.timeout(this.config.getHttpTimeout())
30-
.connectionTimeout(this.config.getHttpConnectionTimeout())
29+
.timeout(this.getConfig().getHttpTimeout())
30+
.connectionTimeout(this.getConfig().getHttpConnectionTimeout())
3131
.bodyText(requestStr);
3232

3333
if (useKey) {
@@ -39,9 +39,9 @@ protected String post(String url, String requestStr, boolean useKey) throws WxPa
3939
request.withConnectionProvider(provider);
4040
}
4141

42-
if (StringUtils.isNotBlank(this.config.getHttpProxyHost()) && this.config.getHttpProxyPort() > 0) {
43-
ProxyInfo httpProxy = new ProxyInfo(ProxyType.HTTP, this.config.getHttpProxyHost(), this.config.getHttpProxyPort(),
44-
this.config.getHttpProxyUsername(), this.config.getHttpProxyPassword());
42+
if (StringUtils.isNotBlank(this.getConfig().getHttpProxyHost()) && this.getConfig().getHttpProxyPort() > 0) {
43+
ProxyInfo httpProxy = new ProxyInfo(ProxyType.HTTP, this.getConfig().getHttpProxyHost(), this.getConfig().getHttpProxyPort(),
44+
this.getConfig().getHttpProxyUsername(), this.getConfig().getHttpProxyPassword());
4545
HttpConnectionProvider provider = request.connectionProvider();
4646
if (null == provider) {
4747
provider = new SocketHttpConnectionProvider();

0 commit comments

Comments
 (0)