Browse Source

#370 WxMpServiceOkHttpImpl改用httpProxy

master
Binary Wang 7 years ago
parent
commit
802f9e8a28
3 changed files with 16 additions and 7 deletions
  1. +8
    -1
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java
  2. +1
    -1
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java
  3. +7
    -5
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java

+ 8
- 1
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java View File

@@ -67,8 +67,15 @@ public class WxCpServiceOkHttpImpl extends WxCpServiceAbstractImpl<OkHttpClient,
@Override @Override
public void initHttp() { public void initHttp() {
this.log.debug("WxCpServiceOkHttpImpl initHttp"); this.log.debug("WxCpServiceOkHttpImpl initHttp");
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
//设置代理 //设置代理
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
httpProxy = OkHttpProxyInfo.httpProxy(configStorage.getHttpProxyHost(),
configStorage.getHttpProxyPort(),
configStorage.getHttpProxyUsername(),
configStorage.getHttpProxyPassword());
}

OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
if (httpProxy != null) { if (httpProxy != null) {
clientBuilder.proxy(getRequestHttpProxy().getProxy()); clientBuilder.proxy(getRequestHttpProxy().getProxy());




+ 1
- 1
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java View File

@@ -28,7 +28,7 @@ public abstract class WxMpServiceAbstractImpl<H, P> implements WxMpService, Requ


protected final Logger log = LoggerFactory.getLogger(this.getClass()); protected final Logger log = LoggerFactory.getLogger(this.getClass());
protected WxSessionManager sessionManager = new StandardSessionManager(); protected WxSessionManager sessionManager = new StandardSessionManager();
private WxMpConfigStorage wxMpConfigStorage;
protected WxMpConfigStorage wxMpConfigStorage;
private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this);
private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this); private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this);
private WxMpMenuService menuService = new WxMpMenuServiceImpl(this); private WxMpMenuService menuService = new WxMpMenuServiceImpl(this);


+ 7
- 5
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java View File

@@ -5,7 +5,6 @@ import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.common.util.http.HttpType;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import okhttp3.*; import okhttp3.*;


@@ -64,13 +63,16 @@ public class WxMpServiceOkHttpImpl extends WxMpServiceAbstractImpl<OkHttpClient,
@Override @Override
public void initHttp() { public void initHttp() {
this.log.debug("WxMpServiceOkHttpImpl initHttp"); this.log.debug("WxMpServiceOkHttpImpl initHttp");
WxMpConfigStorage configStorage = this.getWxMpConfigStorage();


if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
httpProxy = OkHttpProxyInfo.httpProxy(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort(), configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword());
//设置代理
if (wxMpConfigStorage.getHttpProxyHost() != null && wxMpConfigStorage.getHttpProxyPort() > 0) {
httpProxy = OkHttpProxyInfo.httpProxy(wxMpConfigStorage.getHttpProxyHost(),
wxMpConfigStorage.getHttpProxyPort(),
wxMpConfigStorage.getHttpProxyUsername(),
wxMpConfigStorage.getHttpProxyPassword());
} }

OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
//设置代理
if (httpProxy != null) { if (httpProxy != null) {
clientBuilder.proxy(getRequestHttpProxy().getProxy()); clientBuilder.proxy(getRequestHttpProxy().getProxy());




Loading…
Cancel
Save