瀏覽代碼

提出部分代码为方法,清晰化代码结构

BinaryWang 8 年之前
父節點
當前提交
a154e3065a
共有 1 個文件被更改,包括 14 次插入10 次删除
  1. 14 10
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java

+ 14 - 10
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java

@@ -67,10 +67,6 @@ public class WxMpServiceImpl implements WxMpService {
 
   private HttpHost httpProxy;
 
-  public HttpHost getHttpProxy() {
-    return this.httpProxy;
-  }
-
   private int retrySleepMillis = 1000;
 
   private int maxRetryTimes = 5;
@@ -421,6 +417,10 @@ public class WxMpServiceImpl implements WxMpService {
       throw new RuntimeException(e);
     }
   }
+  
+  public HttpHost getHttpProxy() {
+    return this.httpProxy;
+  }
 
   public CloseableHttpClient getHttpclient() {
     return this.httpClient;
@@ -429,19 +429,23 @@ public class WxMpServiceImpl implements WxMpService {
   @Override
   public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) {
     this.wxMpConfigStorage = wxConfigProvider;
+    this.initHttpClient();
+  }
 
+  private void initHttpClient() {
     ApacheHttpClientBuilder apacheHttpClientBuilder = this.wxMpConfigStorage.getApacheHttpClientBuilder();
     if (null == apacheHttpClientBuilder) {
       apacheHttpClientBuilder = DefaultApacheHttpHttpClientBuilder.get();
     }
-    apacheHttpClientBuilder.httpProxyHost(this.wxMpConfigStorage.getHttp_proxy_host())
-      .httpProxyPort(this.wxMpConfigStorage.getHttp_proxy_port())
-      .httpProxyUsername(this.wxMpConfigStorage.getHttp_proxy_username())
-      .httpProxyPassword(this.wxMpConfigStorage.getHttp_proxy_password());
+    
+    apacheHttpClientBuilder.httpProxyHost(this.wxMpConfigStorage.getHttpProxyHost())
+      .httpProxyPort(this.wxMpConfigStorage.getHttpProxyPort())
+      .httpProxyUsername(this.wxMpConfigStorage.getHttpProxyUsername())
+      .httpProxyPassword(this.wxMpConfigStorage.getHttpProxyPassword());
 
-    if (wxConfigProvider.getSSLContext() != null){
+    if (this.wxMpConfigStorage.getSSLContext() != null){
       SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
-          wxConfigProvider.getSSLContext(),
+          this.wxMpConfigStorage.getSSLContext(),
           new String[] { "TLSv1" },
           null,
           SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);