From 7dd0cfe0093fb42286717a5df46683411eac4d32 Mon Sep 17 00:00:00 2001 From: jinyu Date: Tue, 20 Sep 2016 18:25:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dapache=E7=9A=84HttpClinet?= =?UTF-8?q?=E8=AF=81=E4=B9=A6=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin4j/cache/RedisCacheStorager.java | 5 +++-- .../http/factory/SimpleHttpClientFactory.java | 6 +---- .../apache4/HttpComponent4_2Factory.java | 22 +++++++++++-------- .../foxinmy/weixin4j/http/weixin/error.xml | 12 ++++++++++ .../weixin4j/payment/mch/MchPayPackage.java | 1 + 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/cache/RedisCacheStorager.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/cache/RedisCacheStorager.java index e3c9f61a..b0cc01f5 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/cache/RedisCacheStorager.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/cache/RedisCacheStorager.java @@ -5,6 +5,7 @@ import java.util.Set; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; +import redis.clients.util.Pool; import com.foxinmy.weixin4j.util.Consts; import com.foxinmy.weixin4j.util.SerializationUtils; @@ -20,7 +21,7 @@ import com.foxinmy.weixin4j.util.SerializationUtils; public class RedisCacheStorager implements CacheStorager { - private JedisPool jedisPool; + private Pool jedisPool; private final static String HOST = "127.0.0.1"; private final static int PORT = 6379; @@ -54,7 +55,7 @@ public class RedisCacheStorager implements this(new JedisPool(jedisPoolConfig, host, port, timeout)); } - public RedisCacheStorager(JedisPool jedisPool) { + public RedisCacheStorager(Pool jedisPool) { this.jedisPool = jedisPool; } diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/factory/SimpleHttpClientFactory.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/factory/SimpleHttpClientFactory.java index e5c2fbac..4fe3f3a5 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/factory/SimpleHttpClientFactory.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/factory/SimpleHttpClientFactory.java @@ -15,7 +15,6 @@ import com.foxinmy.weixin4j.http.SimpleHttpClient; */ public class SimpleHttpClientFactory extends HttpClientFactory { - private volatile SimpleHttpClient httpClient; private HttpParams params; @Override @@ -25,9 +24,6 @@ public class SimpleHttpClientFactory extends HttpClientFactory { @Override public HttpClient newInstance() { - if (this.httpClient == null) { - this.httpClient = new SimpleHttpClient(params); - } - return this.httpClient; + return new SimpleHttpClient(params); } } diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/support/apache4/HttpComponent4_2Factory.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/support/apache4/HttpComponent4_2Factory.java index 7e82838c..c8edf0b1 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/support/apache4/HttpComponent4_2Factory.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/support/apache4/HttpComponent4_2Factory.java @@ -8,6 +8,8 @@ import org.apache.http.client.config.RequestConfig; import org.apache.http.config.ConnectionConfig; import org.apache.http.config.SocketConfig; import org.apache.http.conn.HttpClientConnectionManager; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.X509HostnameVerifier; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; @@ -53,12 +55,17 @@ public class HttpComponent4_2Factory extends HttpClientFactory { socketAddress.getPort()); clientBuilder.setProxy(proxy); } - if (params.getHostnameVerifier() != null) { - clientBuilder.setHostnameVerifier(new CustomHostnameVerifier(params - .getHostnameVerifier())); - } if (params.getSSLContext() != null) { - clientBuilder.setSslcontext(params.getSSLContext()); + X509HostnameVerifier hostnameVerifier; + if (params.getHostnameVerifier() != null) { + hostnameVerifier = new CustomHostnameVerifier( + params.getHostnameVerifier()); + } else { + hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; + } + clientBuilder.setHostnameVerifier(hostnameVerifier); + clientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory( + params.getSSLContext(), hostnameVerifier)); } } @@ -93,9 +100,6 @@ public class HttpComponent4_2Factory extends HttpClientFactory { @Override public HttpClient newInstance() { - if (httpClient == null) { - this.httpClient = clientBuilder.build(); - } - return new HttpComponent4_2(httpClient); + return new HttpComponent4_2(clientBuilder.build()); } } diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml index 962ca538..a520e717 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml @@ -879,6 +879,10 @@ 60025 主页型应用不支持的消息类型 + + 60026 + 已授权的应用不允许企业管理组调用接口修改菜单 + 60027 不支持第三方修改主页型应用字段 @@ -891,6 +895,10 @@ 60029 应用已授权予第三方,不允许通过接口修改可信域名 + + 60031 + 未设置管理组的登录授权域名 + 60102 UserID已存在 @@ -999,6 +1007,10 @@ 60129 用户设置了拒绝邀请 + + 60131 + 不合法的职位长度 + 61017 子商户未发起授权,不能进行授权确认 diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/MchPayPackage.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/MchPayPackage.java index d43c2051..f11306fa 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/MchPayPackage.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/MchPayPackage.java @@ -145,6 +145,7 @@ public class MchPayPackage extends PayPackage { String goodsTag, String limitPay, String subOpenId) { super(body, detial, outTradeNo, totalFee, notifyUrl, createIp, attach, timeStart, timeExpire, goodsTag); + this.tradeType = tradeType.name(); this.openId = openId; this.authCode = authCode; this.productId = productId;