From ad5873047801c39effdc12ef2579aaf0427e9817 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Wed, 23 Aug 2017 21:35:23 +0800 Subject: [PATCH] =?UTF-8?q?#307=20=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E4=B8=AD=E5=A2=9E=E5=8A=A0http=20proxy?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/WxPayServiceApacheHttpImpl.java | 2 +- .../service/impl/WxPayServiceJoddHttpImpl.java | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java index 09c414f4..14ef7c12 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java @@ -54,7 +54,7 @@ public class WxPayServiceApacheHttpImpl extends WxPayServiceAbstractImpl { .build()); if (StringUtils.isNotBlank(this.config.getHttpProxyHost()) - && StringUtils.isNotBlank(this.config.getHttpProxyUsername())) { + && this.config.getHttpProxyPort() > 0) { // 使用代理服务器 需要用户认证的代理服务器 CredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials( diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java index 29008e26..7e7d31d9 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java @@ -1,9 +1,13 @@ package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.exception.WxPayException; +import jodd.http.HttpConnectionProvider; import jodd.http.HttpRequest; import jodd.http.HttpResponse; +import jodd.http.ProxyInfo; +import jodd.http.ProxyInfo.ProxyType; import jodd.http.net.SSLSocketHttpConnectionProvider; +import jodd.http.net.SocketHttpConnectionProvider; import org.apache.commons.lang3.StringUtils; import javax.net.ssl.SSLContext; @@ -31,7 +35,19 @@ public class WxPayServiceJoddHttpImpl extends WxPayServiceAbstractImpl { if (null == sslContext) { sslContext = this.getConfig().initSSLContext(); } - request.withConnectionProvider(new SSLSocketHttpConnectionProvider(sslContext)); + final SSLSocketHttpConnectionProvider provider = new SSLSocketHttpConnectionProvider(sslContext); + request.withConnectionProvider(provider); + } + + if (StringUtils.isNotBlank(this.config.getHttpProxyHost()) && this.config.getHttpProxyPort() > 0) { + ProxyInfo httpProxy = new ProxyInfo(ProxyType.HTTP, this.config.getHttpProxyHost(), this.config.getHttpProxyPort(), + this.config.getHttpProxyUsername(), this.config.getHttpProxyPassword()); + HttpConnectionProvider provider = request.connectionProvider(); + if (null == provider) { + provider = new SocketHttpConnectionProvider(); + } + provider.useProxy(httpProxy); + request.withConnectionProvider(provider); } String responseString = this.getResponseString(request.send());