Skip to content

Commit ad58730

Browse files
committed
#307 微信支付模块中增加http proxy设置的支持
1 parent 66c786d commit ad58730

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected String post(String url, String requestStr, boolean useKey) throws WxPa
5454
.build());
5555

5656
if (StringUtils.isNotBlank(this.config.getHttpProxyHost())
57-
&& StringUtils.isNotBlank(this.config.getHttpProxyUsername())) {
57+
&& this.config.getHttpProxyPort() > 0) {
5858
// 使用代理服务器 需要用户认证的代理服务器
5959
CredentialsProvider provider = new BasicCredentialsProvider();
6060
provider.setCredentials(

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.github.binarywang.wxpay.service.impl;
22

33
import com.github.binarywang.wxpay.exception.WxPayException;
4+
import jodd.http.HttpConnectionProvider;
45
import jodd.http.HttpRequest;
56
import jodd.http.HttpResponse;
7+
import jodd.http.ProxyInfo;
8+
import jodd.http.ProxyInfo.ProxyType;
69
import jodd.http.net.SSLSocketHttpConnectionProvider;
10+
import jodd.http.net.SocketHttpConnectionProvider;
711
import org.apache.commons.lang3.StringUtils;
812

913
import javax.net.ssl.SSLContext;
@@ -31,7 +35,19 @@ protected String post(String url, String requestStr, boolean useKey) throws WxPa
3135
if (null == sslContext) {
3236
sslContext = this.getConfig().initSSLContext();
3337
}
34-
request.withConnectionProvider(new SSLSocketHttpConnectionProvider(sslContext));
38+
final SSLSocketHttpConnectionProvider provider = new SSLSocketHttpConnectionProvider(sslContext);
39+
request.withConnectionProvider(provider);
40+
}
41+
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());
45+
HttpConnectionProvider provider = request.connectionProvider();
46+
if (null == provider) {
47+
provider = new SocketHttpConnectionProvider();
48+
}
49+
provider.useProxy(httpProxy);
50+
request.withConnectionProvider(provider);
3551
}
3652

3753
String responseString = this.getResponseString(request.send());

0 commit comments

Comments
 (0)