Skip to content

Commit 802f9e8

Browse files
committed
#370 WxMpServiceOkHttpImpl改用httpProxy
1 parent a2cf1f6 commit 802f9e8

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,15 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
6767
@Override
6868
public void initHttp() {
6969
this.log.debug("WxCpServiceOkHttpImpl initHttp");
70-
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
7170
//设置代理
71+
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
72+
httpProxy = OkHttpProxyInfo.httpProxy(configStorage.getHttpProxyHost(),
73+
configStorage.getHttpProxyPort(),
74+
configStorage.getHttpProxyUsername(),
75+
configStorage.getHttpProxyPassword());
76+
}
77+
78+
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
7279
if (httpProxy != null) {
7380
clientBuilder.proxy(getRequestHttpProxy().getProxy());
7481

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public abstract class WxMpServiceAbstractImpl<H, P> implements WxMpService, Requ
2828

2929
protected final Logger log = LoggerFactory.getLogger(this.getClass());
3030
protected WxSessionManager sessionManager = new StandardSessionManager();
31-
private WxMpConfigStorage wxMpConfigStorage;
31+
protected WxMpConfigStorage wxMpConfigStorage;
3232
private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this);
3333
private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this);
3434
private WxMpMenuService menuService = new WxMpMenuServiceImpl(this);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import me.chanjar.weixin.common.exception.WxErrorException;
66
import me.chanjar.weixin.common.util.http.HttpType;
77
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
8-
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
98
import me.chanjar.weixin.mp.api.WxMpService;
109
import okhttp3.*;
1110

@@ -64,13 +63,16 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
6463
@Override
6564
public void initHttp() {
6665
this.log.debug("WxMpServiceOkHttpImpl initHttp");
67-
WxMpConfigStorage configStorage = this.getWxMpConfigStorage();
6866

69-
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
70-
httpProxy = OkHttpProxyInfo.httpProxy(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort(), configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword());
67+
//设置代理
68+
if (wxMpConfigStorage.getHttpProxyHost() != null && wxMpConfigStorage.getHttpProxyPort() > 0) {
69+
httpProxy = OkHttpProxyInfo.httpProxy(wxMpConfigStorage.getHttpProxyHost(),
70+
wxMpConfigStorage.getHttpProxyPort(),
71+
wxMpConfigStorage.getHttpProxyUsername(),
72+
wxMpConfigStorage.getHttpProxyPassword());
7173
}
74+
7275
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
73-
//设置代理
7476
if (httpProxy != null) {
7577
clientBuilder.proxy(getRequestHttpProxy().getProxy());
7678

0 commit comments

Comments
 (0)