From 59f92a3b41b63bf8c8efe5b5656b284b884c2b87 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Thu, 1 Sep 2016 10:26:16 +0800 Subject: [PATCH 01/49] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/common/util/crypto/SHA1.java | 9 +- .../common/util/crypto/WxCryptUtil.java | 57 ++++++------ .../weixin/common/util/fs/FileUtils.java | 36 +++----- .../http/DefaultApacheHttpClientBuilder.java | 8 +- .../util/http/JoddGetRequestExecutor.java | 9 +- .../util/http/JoddPostRequestExecutor.java | 9 +- .../http/MediaDownloadRequestExecutor.java | 25 +++--- .../weixin/common/session/SessionTest.java | 4 +- .../mp/api/impl/WxMpCardServiceImpl.java | 17 ++-- .../weixin/mp/api/impl/WxMpServiceImpl.java | 88 ++++++++++++------- 10 files changed, 132 insertions(+), 130 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java index 4f7503c6..683f2ecf 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java @@ -1,10 +1,9 @@ package me.chanjar.weixin.common.util.crypto; -import org.apache.commons.codec.digest.DigestUtils; - -import java.security.NoSuchAlgorithmException; import java.util.Arrays; +import org.apache.commons.codec.digest.DigestUtils; + /** * Created by Daniel Qian on 14/10/19. */ @@ -13,7 +12,7 @@ public class SHA1 { /** * 串接arr参数,生成sha1 digest */ - public static String gen(String... arr) throws NoSuchAlgorithmException { + public static String gen(String... arr) { Arrays.sort(arr); StringBuilder sb = new StringBuilder(); for (String a : arr) { @@ -25,7 +24,7 @@ public class SHA1 { /** * 用&串接arr参数,生成sha1 digest */ - public static String genWithAmple(String... arr) throws NoSuchAlgorithmException { + public static String genWithAmple(String... arr) { Arrays.sort(arr); StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.length; i++) { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java index 4cc31039..eb5df7af 100755 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java @@ -17,11 +17,16 @@ */ package me.chanjar.weixin.common.util.crypto; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.digest.DigestUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.InputSource; +import java.io.StringReader; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.SortedMap; +import java.util.TreeMap; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; @@ -29,10 +34,12 @@ import javax.crypto.spec.SecretKeySpec; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import java.io.StringReader; -import java.nio.charset.Charset; -import java.security.NoSuchAlgorithmException; -import java.util.*; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.digest.DigestUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.InputSource; public class WxCryptUtil { @@ -130,13 +137,9 @@ public class WxCryptUtil { String timeStamp = Long.toString(System.currentTimeMillis() / 1000l); String nonce = genRandomStr(); - try { - String signature = SHA1.gen(this.token, timeStamp, nonce, encryptedXml); - String result = generateXml(encryptedXml, signature, timeStamp, nonce); - return result; - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } + String signature = SHA1.gen(this.token, timeStamp, nonce, encryptedXml); + String result = generateXml(encryptedXml, signature, timeStamp, nonce); + return result; } /** @@ -205,14 +208,10 @@ public class WxCryptUtil { // 提取密文 String cipherText = extractEncryptPart(encryptedXml); - try { - // 验证安全签名 - String signature = SHA1.gen(this.token, timeStamp, nonce, cipherText); - if (!signature.equals(msgSignature)) { - throw new RuntimeException("加密消息签名校验失败"); - } - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); + // 验证安全签名 + String signature = SHA1.gen(this.token, timeStamp, nonce, cipherText); + if (!signature.equals(msgSignature)) { + throw new RuntimeException("加密消息签名校验失败"); } // 解密 @@ -277,7 +276,7 @@ public class WxCryptUtil { * * @param number */ - private byte[] number2BytesInNetworkOrder(int number) { + private static byte[] number2BytesInNetworkOrder(int number) { byte[] orderBytes = new byte[4]; orderBytes[3] = (byte) (number & 0xFF); orderBytes[2] = (byte) (number >> 8 & 0xFF); @@ -291,7 +290,7 @@ public class WxCryptUtil { * * @param bytesInNetworkOrder */ - private int bytesNetworkOrder2Number(byte[] bytesInNetworkOrder) { + private static int bytesNetworkOrder2Number(byte[] bytesInNetworkOrder) { int sourceNumber = 0; for (int i = 0; i < 4; i++) { sourceNumber <<= 8; @@ -303,7 +302,7 @@ public class WxCryptUtil { /** * 随机生成16位字符串 */ - private String genRandomStr() { + private static String genRandomStr() { String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; Random random = new Random(); StringBuffer sb = new StringBuffer(); @@ -323,8 +322,8 @@ public class WxCryptUtil { * @param nonce 随机字符串 * @return 生成的xml字符串 */ - private String generateXml(String encrypt, String signature, String timestamp, - String nonce) { + private static String generateXml(String encrypt, String signature, + String timestamp, String nonce) { String format = "\n" + "\n" + "\n" + "%3$s\n" + "\n" diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java index 706ced39..9ff25ebc 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java @@ -17,37 +17,25 @@ public class FileUtils { * @param tmpDirFile 临时文件夹目录 */ public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile) throws IOException { - FileOutputStream fos = null; - try { - File tmpFile; - if (tmpDirFile == null) { - tmpFile = File.createTempFile(name, '.' + ext); - } else { - tmpFile = File.createTempFile(name, '.' + ext, tmpDirFile); - } - tmpFile.deleteOnExit(); - fos = new FileOutputStream(tmpFile); + File tmpFile; + if (tmpDirFile == null) { + tmpFile = File.createTempFile(name, '.' + ext); + } else { + tmpFile = File.createTempFile(name, '.' + ext, tmpDirFile); + } + + tmpFile.deleteOnExit(); + + try (FileOutputStream fos = new FileOutputStream(tmpFile)) { int read = 0; byte[] bytes = new byte[1024 * 100]; while ((read = inputStream.read(bytes)) != -1) { fos.write(bytes, 0, read); } + fos.flush(); return tmpFile; - } finally { - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException e) { - } - } - if (fos != null) { - try { - fos.close(); - } catch (IOException e) { - } - } - } + } } /** diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java index 4acc7662..f01d0d9e 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java @@ -1,6 +1,8 @@ package me.chanjar.weixin.common.util.http; -import me.chanjar.weixin.common.util.StringUtils; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + import org.apache.http.annotation.NotThreadSafe; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; @@ -21,8 +23,7 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.protocol.HttpContext; -import java.io.IOException; -import java.util.concurrent.TimeUnit; +import me.chanjar.weixin.common.util.StringUtils; /** * httpclient 连接管理器 @@ -107,6 +108,7 @@ public class DefaultApacheHttpClientBuilder implements ApacheHttpClientBuilder { .register("https", this.sslConnectionSocketFactory) .build(); + @SuppressWarnings("resource") PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry); connectionManager.setMaxTotal(this.maxTotalConn); connectionManager.setDefaultMaxPerRoute(this.maxConnPerHost); diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddGetRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddGetRequestExecutor.java index a2ff7a56..34f20779 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddGetRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddGetRequestExecutor.java @@ -1,15 +1,14 @@ package me.chanjar.weixin.common.util.http; +import org.apache.http.HttpHost; +import org.apache.http.impl.client.CloseableHttpClient; + import jodd.http.HttpRequest; import jodd.http.HttpResponse; import jodd.http.ProxyInfo; import jodd.http.net.SocketHttpConnectionProvider; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; -import org.apache.http.HttpHost; -import org.apache.http.impl.client.CloseableHttpClient; - -import java.io.IOException; /** * 简单的GET请求执行器,请求的参数是String, 返回的结果也是String @@ -20,7 +19,7 @@ public class JoddGetRequestExecutor implements RequestExecutor { @Override public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, - String queryParam) throws WxErrorException, IOException { + String queryParam) throws WxErrorException { if (queryParam != null) { if (uri.indexOf('?') == -1) { uri += '?'; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddPostRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddPostRequestExecutor.java index 771fb46e..757db665 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddPostRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddPostRequestExecutor.java @@ -1,15 +1,14 @@ package me.chanjar.weixin.common.util.http; +import org.apache.http.HttpHost; +import org.apache.http.impl.client.CloseableHttpClient; + import jodd.http.HttpRequest; import jodd.http.HttpResponse; import jodd.http.ProxyInfo; import jodd.http.net.SocketHttpConnectionProvider; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; -import org.apache.http.HttpHost; -import org.apache.http.impl.client.CloseableHttpClient; - -import java.io.IOException; /** * 简单的POST请求执行器,请求的参数是String, 返回的结果也是String @@ -20,7 +19,7 @@ public class JoddPostRequestExecutor implements RequestExecutor @Override public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, - String postEntity) throws WxErrorException, IOException { + String postEntity) throws WxErrorException { SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider(); if (httpProxy != null) { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java index 9a2bfb33..87981142 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java @@ -1,9 +1,11 @@ package me.chanjar.weixin.common.util.http; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.StringUtils; -import me.chanjar.weixin.common.util.fs.FileUtils; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.apache.http.Header; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; @@ -12,11 +14,10 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.entity.ContentType; import org.apache.http.impl.client.CloseableHttpClient; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.StringUtils; +import me.chanjar.weixin.common.util.fs.FileUtils; /** * 下载媒体文件请求执行器,请求的参数是String, 返回的结果是File @@ -52,7 +53,9 @@ public class MediaDownloadRequestExecutor implements RequestExecutor 0) { @@ -62,8 +65,6 @@ public class MediaDownloadRequestExecutor implements RequestExecutor Date: Fri, 2 Sep 2016 19:20:53 +0800 Subject: [PATCH 05/49] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E4=B8=A4=E4=B8=AAgroup?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/impl/WxMpGroupServiceImplTest.java | 11 +++++++++++ .../weixin/mp/api/impl/WxMpUserServiceImplTest.java | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java index d107a4b7..d0ba6029 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java @@ -47,4 +47,15 @@ public class WxMpGroupServiceImplTest { this.wxService.getGroupService().groupUpdate(this.group); } + public void testGroupQueryUserGroup() throws WxErrorException { + ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); + long groupid = this.wxService.getGroupService().userGetGroup(configStorage.getOpenId()); + Assert.assertTrue(groupid != -1l); + } + + public void testGroupMoveUser() throws WxErrorException { + ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); + this.wxService.getGroupService().userUpdateGroup(configStorage.getOpenId(), this.wxService.getGroupService().groupGet().get(3).getId()); + } + } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java index 07503516..bc598285 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java @@ -45,15 +45,4 @@ public class WxMpUserServiceImplTest { System.out.println(wxMpUserList); } - public void testGroupQueryUserGroup() throws WxErrorException { - ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); - long groupid = this.wxService.getGroupService().userGetGroup(configStorage.getOpenId()); - Assert.assertTrue(groupid != -1l); - } - - public void testGroupMoveUser() throws WxErrorException { - ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); - this.wxService.getGroupService().userUpdateGroup(configStorage.getOpenId(), this.wxService.getGroupService().groupGet().get(3).getId()); - } - } From ce58afc5da97b596973acb8f8ab2c7dae8076ca9 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Fri, 2 Sep 2016 19:21:27 +0800 Subject: [PATCH 06/49] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/WxMpService.java | 8 +++ .../weixin/mp/api/WxMpUserTagService.java | 26 +++++++ .../weixin/mp/api/impl/WxMpServiceImpl.java | 68 +++++++------------ .../mp/api/impl/WxMpUserTagServiceImpl.java | 38 +++++++++++ .../chanjar/weixin/mp/bean/tag/WxUserTag.java | 65 ++++++++++++++++++ .../api/impl/WxMpUserTagServiceImplTest.java | 29 ++++++++ 6 files changed, 189 insertions(+), 45 deletions(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 7acd2342..18df437f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -314,8 +314,16 @@ public interface WxMpService { * * @return WxMpGroupService */ + WxMpGroupService getGroupService(); + /** + * 返回用户标签相关接口的方法实现类,以方便调用个其各种接口 + * + * @return WxMpUserTagService + */ + WxMpUserTagService getUserTagService(); + /** * 返回二维码相关接口的方法实现类,以方便调用个其各种接口 * diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java new file mode 100644 index 00000000..c909f9ce --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java @@ -0,0 +1,26 @@ +package me.chanjar.weixin.mp.api; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.bean.tag.WxUserTag; + +/** + * 用户标签管理相关接口 + * Created by Binary Wang on 2016/9/2. + * @author binarywang(https://github.com/binarywang) + * + */ +public interface WxMpUserTagService { + + /** + *
+   *   创建标签
+   *   一个公众号,最多可以创建100个标签。
+   * 详情请见:用户标签管理
+   * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/create?access_token=ACCESS_TOKEN
+   * 
+ * + * @param name 分组名字(30个字符以内) + */ + WxUserTag tagCreate(String name) throws WxErrorException; + +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java index c69f2672..cbbd1264 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java @@ -1,23 +1,9 @@ package me.chanjar.weixin.mp.api.impl; -import java.io.IOException; - -import org.apache.http.HttpHost; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.ssl.DefaultHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.BasicResponseHandler; -import org.apache.http.impl.client.CloseableHttpClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; - import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.result.WxError; @@ -26,37 +12,22 @@ import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.util.RandomUtils; import me.chanjar.weixin.common.util.crypto.SHA1; -import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; -import me.chanjar.weixin.common.util.http.DefaultApacheHttpClientBuilder; -import me.chanjar.weixin.common.util.http.RequestExecutor; -import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; -import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; -import me.chanjar.weixin.common.util.http.URIUtil; -import me.chanjar.weixin.mp.api.WxMpCardService; -import me.chanjar.weixin.mp.api.WxMpConfigStorage; -import me.chanjar.weixin.mp.api.WxMpDataCubeService; -import me.chanjar.weixin.mp.api.WxMpGroupService; -import me.chanjar.weixin.mp.api.WxMpKefuService; -import me.chanjar.weixin.mp.api.WxMpMaterialService; -import me.chanjar.weixin.mp.api.WxMpMenuService; -import me.chanjar.weixin.mp.api.WxMpPayService; -import me.chanjar.weixin.mp.api.WxMpQrcodeService; -import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxMpUserService; -import me.chanjar.weixin.mp.bean.WxMpCustomMessage; -import me.chanjar.weixin.mp.bean.WxMpIndustry; -import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage; -import me.chanjar.weixin.mp.bean.WxMpMassNews; -import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; -import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage; -import me.chanjar.weixin.mp.bean.WxMpMassVideo; -import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; -import me.chanjar.weixin.mp.bean.WxMpTemplateMessage; -import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; -import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; -import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; -import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; -import me.chanjar.weixin.mp.bean.result.WxMpUser; +import me.chanjar.weixin.common.util.http.*; +import me.chanjar.weixin.mp.api.*; +import me.chanjar.weixin.mp.bean.*; +import me.chanjar.weixin.mp.bean.result.*; +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.BasicResponseHandler; +import org.apache.http.impl.client.CloseableHttpClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; public class WxMpServiceImpl implements WxMpService { @@ -86,6 +57,8 @@ public class WxMpServiceImpl implements WxMpService { private WxMpGroupService groupService = new WxMpGroupServiceImpl(this); + private WxMpUserTagService tagService = new WxMpUserTagServiceImpl(this); + private WxMpQrcodeService qrCodeService = new WxMpQrcodeServiceImpl(this); private WxMpCardService cardService = new WxMpCardServiceImpl(this); @@ -534,6 +507,11 @@ public class WxMpServiceImpl implements WxMpService { return this.groupService; } + @Override + public WxMpUserTagService getUserTagService() { + return this.tagService; + } + @Override public WxMpQrcodeService getQrcodeService() { return this.qrCodeService; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java new file mode 100644 index 00000000..1566f602 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java @@ -0,0 +1,38 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.gson.JsonObject; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.WxMpUserTagService; +import me.chanjar.weixin.mp.bean.tag.WxUserTag; + +/** + * + * @author binarywang(https://github.com/binarywang) + * Created by Binary Wang on 2016/9/2. + */ +public class WxMpUserTagServiceImpl implements WxMpUserTagService { + private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/tags"; + + private WxMpService wxMpService; + + public WxMpUserTagServiceImpl(WxMpService wxMpService) { + this.wxMpService = wxMpService; + } + + @Override + public WxUserTag tagCreate(String name) throws WxErrorException { + String url = API_URL_PREFIX + "/create"; + JsonObject json = new JsonObject(); + JsonObject groupJson = new JsonObject(); + groupJson.addProperty("name", name); + json.add("tag", groupJson); + + String responseContent = this.wxMpService.execute( + new SimplePostRequestExecutor(), + url, + json.toString()); + return WxUserTag.fromJson(responseContent); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java new file mode 100644 index 00000000..79d28f20 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java @@ -0,0 +1,65 @@ +package me.chanjar.weixin.mp.bean.tag; + +import com.google.gson.JsonParser; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 用户标签对象 + * @author binarywang(https://github.com/binarywang) + * Created by Binary Wang on 2016/9/2. + */ +public class WxUserTag { + /** + * id 标签id,由微信分配 + */ + private Integer id; + + /** + * name 标签名,UTF8编码 + */ + private String name; + + /** + * count 此标签下粉丝数 + */ + private Integer count; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getCount() { + return count; + } + + public void setCount(Integer count) { + this.count = count; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public static WxUserTag fromJson(String json) { + return WxMpGsonBuilder.create().fromJson(new JsonParser().parse(json).getAsJsonObject().get("tag"), WxUserTag.class); + } + + public String toJson() { + return WxMpGsonBuilder.create().toJson(this); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); + } +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java new file mode 100644 index 00000000..af8125bf --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java @@ -0,0 +1,29 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.inject.Inject; +import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.bean.tag.WxUserTag; +import org.testng.Assert; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +/** + * + * @author binarywang(https://github.com/binarywang) + * Created by Binary Wang on 2016/9/2. + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMpUserTagServiceImplTest { + @Inject + protected WxMpServiceImpl wxService; + + @Test + public void testTagCreate() throws Exception { + String tagName = "测试标签"; + WxUserTag res = this.wxService.getUserTagService().tagCreate(tagName); + System.out.println(res); + Assert.assertEquals(tagName, res.getName()); + } + +} \ No newline at end of file From fa51539e1ea5a03db3387aa99fadc64e64ba7a0e Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Fri, 2 Sep 2016 19:30:47 +0800 Subject: [PATCH 07/49] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java index 1566f602..2fce5443 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java @@ -6,6 +6,8 @@ import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpUserTagService; import me.chanjar.weixin.mp.bean.tag.WxUserTag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @@ -13,6 +15,7 @@ import me.chanjar.weixin.mp.bean.tag.WxUserTag; * Created by Binary Wang on 2016/9/2. */ public class WxMpUserTagServiceImpl implements WxMpUserTagService { + protected final Logger log = LoggerFactory.getLogger(WxMpDataCubeServiceImpl.class); private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/tags"; private WxMpService wxMpService; @@ -33,6 +36,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { new SimplePostRequestExecutor(), url, json.toString()); + this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, name, responseContent); return WxUserTag.fromJson(responseContent); } } From 99bb1a9a9651631f0fb41826008695226d0fcbab Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Tue, 6 Sep 2016 18:41:16 +0800 Subject: [PATCH 08/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8fbe9ac4..8b402e7f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Weixin Java Tools 微信公众号/企业号开发Java SDK -## [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=078f7a153d243853e24cf2b542e7a6ccbf2a592bc138080f84d11297f736ec46) [![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badge/) ![Maven Central](https://img.shields.io/maven-central/v/com.github.binarywang/weixin-java-parent.svg) [![Build Status](https://travis-ci.org/binarywang/weixin-java-tools.svg?branch=develop)](https://travis-ci.org/binarywang/weixin-java-tools) +## [![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badge/) ![Maven Central](https://img.shields.io/maven-central/v/com.github.binarywang/weixin-java-parent.svg) [![Build Status](https://travis-ci.org/binarywang/weixin-java-tools.svg?branch=develop)](https://travis-ci.org/binarywang/weixin-java-tools) ### 声明:本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。 @@ -11,9 +11,9 @@ ### 详细开发文档请看 [wiki](https://github.com/chanjarster/weixin-java-tools/wiki)。 =========== ## 开发交流工具: -* QQ群:343954419 [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=078f7a153d243853e24cf2b542e7a6ccbf2a592bc138080f84d11297f736ec46) -* 注意:为保证入群成员质量,请申请入群时认真输入Github帐号ID,即你的github主页地址https://github.com/XXXX 中最后的部分XXXX的内容,谢谢~ * 微信群: 因二维码有时间限制,如有想加入微信群的,请入QQ群后咨询获取最新入群二维码。 +* QQ群:343954419 [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=078f7a153d243853e24cf2b542e7a6ccbf2a592bc138080f84d11297f736ec46) +* ***注意:为保证入群成员质量,请申请入群前,先Star本项目,然后在申请入群时,输入您的Github帐号ID,以便管理员核对,ID即你的github主页地址https://github.com/XXXX 中最后的部分XXXX的内容,谢谢~*** =========== From a86c8ebfbb296d01f097f54c1b87e959922ec192 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 6 Sep 2016 18:42:34 +0800 Subject: [PATCH 09/49] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8fbe9ac4..8b402e7f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Weixin Java Tools 微信公众号/企业号开发Java SDK -## [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=078f7a153d243853e24cf2b542e7a6ccbf2a592bc138080f84d11297f736ec46) [![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badge/) ![Maven Central](https://img.shields.io/maven-central/v/com.github.binarywang/weixin-java-parent.svg) [![Build Status](https://travis-ci.org/binarywang/weixin-java-tools.svg?branch=develop)](https://travis-ci.org/binarywang/weixin-java-tools) +## [![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badge/) ![Maven Central](https://img.shields.io/maven-central/v/com.github.binarywang/weixin-java-parent.svg) [![Build Status](https://travis-ci.org/binarywang/weixin-java-tools.svg?branch=develop)](https://travis-ci.org/binarywang/weixin-java-tools) ### 声明:本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。 @@ -11,9 +11,9 @@ ### 详细开发文档请看 [wiki](https://github.com/chanjarster/weixin-java-tools/wiki)。 =========== ## 开发交流工具: -* QQ群:343954419 [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=078f7a153d243853e24cf2b542e7a6ccbf2a592bc138080f84d11297f736ec46) -* 注意:为保证入群成员质量,请申请入群时认真输入Github帐号ID,即你的github主页地址https://github.com/XXXX 中最后的部分XXXX的内容,谢谢~ * 微信群: 因二维码有时间限制,如有想加入微信群的,请入QQ群后咨询获取最新入群二维码。 +* QQ群:343954419 [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=078f7a153d243853e24cf2b542e7a6ccbf2a592bc138080f84d11297f736ec46) +* ***注意:为保证入群成员质量,请申请入群前,先Star本项目,然后在申请入群时,输入您的Github帐号ID,以便管理员核对,ID即你的github主页地址https://github.com/XXXX 中最后的部分XXXX的内容,谢谢~*** =========== From 6588e2537daa5539e79583a438cc6e9a34fdd36b Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Tue, 6 Sep 2016 18:52:28 +0800 Subject: [PATCH 10/49] add one pic --- res/github_id.png | Bin 0 -> 4006 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 res/github_id.png diff --git a/res/github_id.png b/res/github_id.png new file mode 100644 index 0000000000000000000000000000000000000000..dc2aefcf92f1f622aefae965ec9753ec8f03ebfc GIT binary patch literal 4006 zcmaKvcQ~6}*uZ12s#MXUh?c0@1TUpVgV-%t@9c6}Jsj4CInBZ!%i zIzL4^P^f~&&rDAnP(5^Ijk=(B)-u)t0P0fNP98B(*DT&J8$STxeAk~r^U3S&699nY zran~5BG_T`HN}gI#2a@oJa6uI>~JKPIBMW=ukqbWC1d!-WmFoFnZ8q0C>=>z0E{OJW-{iB@mCE74meAL)$L)^~G6ly63w8_Z z{0r5cok(Ec#a?z=06iO&4nz;)0|*1~0A`waMonf-2tXTvq5;wZ*`t6_a6k+I%9ckV z)ksv^HsetcZc@KdGk_Ma zt@&9YaGtdlSCQm!a@|BGVruR1h@4~p4&f<7q$RRI*)F#l*tdotEF-duoM&&E47WyJ zT_h<77Fv4XI4m2->8Kh~6TcU__MX@?sXtApxDC3p;hio4r5;*eb{g683^}RVZ<)h> zKw9`=eO879jt*Cl{a)`GNg2J@m8n`7*;G&0Vm)QSFUOSo7Z5$y18&?^iszBF%?%i9 zB_WkC1R;`8|6wC}cf?N@<1WFAbW;c(aR%2DZ$i{Xa+Ve!l5r{d8RdV&!Z)EMqSCo%@(}ccr7zg zZ|1B}aHb^=dnMV!N^;Au|1sDs;4fNKmV!Va z_P*Zc5J&GWYYuGv0(jgCl#|MJ(&@Th#b0bMBzF8SYnyw7J zHeVPG2bSn%hv{&%PiS(~xbKC9`x@S4FOjamCR>m=h@goBfoaV8*CIW6o{bk(vxF0! zS1wti6P>NC{1a4vS+t@Oc30Pp71tUiDKr_~XxU~`T#!FpNb zssMeDf|63HrJOk=_UVX(opf}_?@B)C@f=L!i`~gBscNC`eb}S#z}EVMO55o%%>5#b z$iSGfQ}3y*wPY$<0*py($9)njrJgrk8>OhI=-Qc@k`l6XqvT;&*BU+(_E(TAKdQA z?r@oypY*R=ChzXD1~X*!4)$hC*%3~Es+V^ESpF>Fc-Zm!w2aB+GoGsz(~c}W{tjyW zFh7flI1I(izd&F@@3Qw;d7^FxZR01heL~hNM)vlGuK6#LJ(>@U&~>@$QgnM2C2`QP zt$#%K#ThQFfvyX>Oy;sUOr!ZqKGwjKMeM{y9j6Y#a@sPHc&%AAZ0>}R9d!2e=>~5VIqo$Zdt4gb_vzR&9}8?S6;QZ_C`o_9W+o5*v5)$EyUbJ6Bq` zA)*6J5pZE5YqV?ddN9iCCC|2smVo*-|N5Z#eSuAMLek8^XIER9uM~i2C)dFW_f+8l5v^Lj=g?KmB0N zONQ3l4|e{M46uH@^6$+D$kpOYZ5oC(O(tgB%i{Sh&vJSt=T*&>SBtSCM8$)zhj{(w z05X;IVmuE>t&Xz3eg(EkmN(n?2NR2r+rxRwQeQQ@xEU&MY7q65J)h0WeCBeg^rgkq z#^@+Cz0^|2RXCw5)xEQM&b(93LKh0c(ck~xCVP?=)8u-Bms~r!ulHg2L->mHbis`? z<(i!&B;fr=q&xs5Vx8=63fyHUy@mE){y!@E|5Nk_U4L;9_xJY`S32oY&u!QYvyH$m zzP|Mv_1q%)XAMMvh3d6y*C4X845oXP+U?QBO#H_>AckACI`m9HjPYu z2r%^7B^&pcYMi3ejI!LBK<-lqPjCxu&Y5Iv;lTvm=8Lt&eX&ah829Kkt)C2ehVL-` zRLqtSPbQ_ESU>khmK%}eRorKiJyFB zMP=9zDd5d!_1677-l+c@d27qFQN-^yeO}T$ZuopHTgVHArz2-e8O8}<{oZ3ML4X#} zO#1siy{L*q|Er9N`Kx>mXXp z65437*&;9DBzy7oC9kQQ-P zXV7z~d)8qIy<$J(5)U0kPoC>X95gQ>10W7xN{DXc%QaCmR(^^J_9&J0w@0=j<-PvM zHO|B2d4z~9*{$yyi=n5K)0^=0uZzcm2%SX}Nxn;u@CJdY*CkPB$LvFhc+v9LKq6FbJ}##3k#u?KEzM4+rgB+9@^8&VmED7 zaBT*f3-#1S;Lnjrl<{mu2)1IYs`On)=Tlq+T5?B}uf}OA*Gge)@WA=LWG%OG&tX(| zGwPX`L{q;Vrt;#9frDf4q9G(;NIaF(uBGf%wYmb28Ou&<03>oPGbtH?$TEQxKCJG) z*&3do=TD&DZ~3uX5!QyXxl8y5j3tVxnw!5KR*h9Y(@_{IkK`vkL}-{BzD2xLrv_52 zBwx@dhqg5)HkPruW%ipLm}$r=aD|@yt$uBPELj3hfjiq`d0F|p_#dEb@*p0>KnowDwlY!JY zI#}MK9c1gH01lAU8|mCajrFFmv~%S#zc{~~f@0W2Z#^p@e|hEnCnc$hrwPDQ`0u%a zV-R2T`vpS`lTcWiVDKDGj~l!5+KAXz+40uDaOMS*eyE+_dw!HKEcO@IW`HYJ)yMg? zdk26`VP4Qru*9^F>{q|!tP(^C$BR)7W)e1bD{D$Qs8K-+ZpO*jqPsz`HS_vV48vqI zEvIqDn<)_NkvIZgBVdX2xgsc7y43HnH)$hdD-4P^#lNTf>#gU{X%c%L2R>_`=it_Z zC+I+gjUOjj#JFxM$x%Y(y|r@!95I*_PFM(g@YJa{VW^dmBzL@s$qk6}PqWd0eDY&h0$(FWQD7CnHDjm9r!Dd@>mAYjV=ZP4pA8D7_~~3&Cg+EwcC|UtktRQ`XuYaJfLZ{3x*KSZUpXP z5c%r;A*8q-y2mm4pP%tEy~S)me9n1@OWu2zhL_v&gXxBq+rm}3mmlhdJo zYDN9bRDWw?WUm@`;sBhMAlo6>MSpBm40k+_H9EoG1@wpk^+M34Glxy2QWI0Jn}6~s zn!0J3o{s*`W;XPva|lzLi#9X0VF1lq;O2XgufElvj&kq7sBde4zK#jBTKi%2{{XAO By2}6n literal 0 HcmV?d00001 From 0f42e64e7074cbaaf1a0676f6f4925e58833b3a8 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Tue, 6 Sep 2016 18:57:55 +0800 Subject: [PATCH 11/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b402e7f..1a49fb67 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ ## 开发交流工具: * 微信群: 因二维码有时间限制,如有想加入微信群的,请入QQ群后咨询获取最新入群二维码。 * QQ群:343954419 [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=078f7a153d243853e24cf2b542e7a6ccbf2a592bc138080f84d11297f736ec46) -* ***注意:为保证入群成员质量,请申请入群前,先Star本项目,然后在申请入群时,输入您的Github帐号ID,以便管理员核对,ID即你的github主页地址https://github.com/XXXX 中最后的部分XXXX的内容,谢谢~*** +* ***注意:为保证入群成员质量,请申请入群前,先Star本项目,然后在申请入群时,输入您的Github帐号ID,以便管理员核对,ID即你的github主页地址https://github.com/XXXX 中最后的部分XXXX的内容,或者在github网页右上角点击头像查看,如下图Signed in as下方黄色标识内容即是:*** +![github_id](https://raw.githubusercontent.com/wechat-group/weixin-java-tools/develop/res/github_id.png) =========== From f157963a87af87c5e765df623748363c5976374e Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 6 Sep 2016 18:58:31 +0800 Subject: [PATCH 12/49] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b402e7f..1a49fb67 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ ## 开发交流工具: * 微信群: 因二维码有时间限制,如有想加入微信群的,请入QQ群后咨询获取最新入群二维码。 * QQ群:343954419 [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=078f7a153d243853e24cf2b542e7a6ccbf2a592bc138080f84d11297f736ec46) -* ***注意:为保证入群成员质量,请申请入群前,先Star本项目,然后在申请入群时,输入您的Github帐号ID,以便管理员核对,ID即你的github主页地址https://github.com/XXXX 中最后的部分XXXX的内容,谢谢~*** +* ***注意:为保证入群成员质量,请申请入群前,先Star本项目,然后在申请入群时,输入您的Github帐号ID,以便管理员核对,ID即你的github主页地址https://github.com/XXXX 中最后的部分XXXX的内容,或者在github网页右上角点击头像查看,如下图Signed in as下方黄色标识内容即是:*** +![github_id](https://raw.githubusercontent.com/wechat-group/weixin-java-tools/develop/res/github_id.png) =========== From 329433f4a65251a50691e426868aaeededfa0c2f Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Tue, 6 Sep 2016 18:58:55 +0800 Subject: [PATCH 13/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a49fb67..c6a776c9 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ * 微信群: 因二维码有时间限制,如有想加入微信群的,请入QQ群后咨询获取最新入群二维码。 * QQ群:343954419 [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=078f7a153d243853e24cf2b542e7a6ccbf2a592bc138080f84d11297f736ec46) * ***注意:为保证入群成员质量,请申请入群前,先Star本项目,然后在申请入群时,输入您的Github帐号ID,以便管理员核对,ID即你的github主页地址https://github.com/XXXX 中最后的部分XXXX的内容,或者在github网页右上角点击头像查看,如下图Signed in as下方黄色标识内容即是:*** -![github_id](https://raw.githubusercontent.com/wechat-group/weixin-java-tools/develop/res/github_id.png) +* ![github_id](https://raw.githubusercontent.com/wechat-group/weixin-java-tools/develop/res/github_id.png) =========== From 04ca89a4c7c3fb16295b73d23351ab0b2eb398ef Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 6 Sep 2016 18:59:12 +0800 Subject: [PATCH 14/49] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a49fb67..c6a776c9 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ * 微信群: 因二维码有时间限制,如有想加入微信群的,请入QQ群后咨询获取最新入群二维码。 * QQ群:343954419 [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=078f7a153d243853e24cf2b542e7a6ccbf2a592bc138080f84d11297f736ec46) * ***注意:为保证入群成员质量,请申请入群前,先Star本项目,然后在申请入群时,输入您的Github帐号ID,以便管理员核对,ID即你的github主页地址https://github.com/XXXX 中最后的部分XXXX的内容,或者在github网页右上角点击头像查看,如下图Signed in as下方黄色标识内容即是:*** -![github_id](https://raw.githubusercontent.com/wechat-group/weixin-java-tools/develop/res/github_id.png) +* ![github_id](https://raw.githubusercontent.com/wechat-group/weixin-java-tools/develop/res/github_id.png) =========== From e9c504bd402754c18aa34980cdcdb115bf3aa4da Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Tue, 6 Sep 2016 19:00:37 +0800 Subject: [PATCH 15/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6a776c9..c8d64558 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ### 声明:本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。 ### 最新更新:2.1.0版发布!!! on 2016-08-31 -#### 自2.0.0版本以来,接口调整比较大,主要是公众号的调整,企业号无过多调整,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。所以如果习惯于1.X.X版本的同学不想做过多更改的话,请慎重考虑升级到2.X.X版本。 +#### *** 注意 自2.0.0版本以来,接口调整比较大,主要是公众号的调整,企业号无过多调整,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。所以如果习惯于1.X.X版本的同学不想做过多更改的话,请慎重考虑升级到2.X.X版本。*** --- ### 详细开发文档请看 [wiki](https://github.com/chanjarster/weixin-java-tools/wiki)。 From f2b840cf3a192f3a0f91784d7fa4197438c53117 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Tue, 6 Sep 2016 19:01:41 +0800 Subject: [PATCH 16/49] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c8d64558..d7b1ca7d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ### 声明:本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。 ### 最新更新:2.1.0版发布!!! on 2016-08-31 -#### *** 注意 自2.0.0版本以来,接口调整比较大,主要是公众号的调整,企业号无过多调整,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。所以如果习惯于1.X.X版本的同学不想做过多更改的话,请慎重考虑升级到2.X.X版本。*** +* *** 注意 自2.0.0版本以来,接口调整比较大,主要是公众号的调整,企业号无过多调整,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。所以如果习惯于1.X.X版本的同学不想做过多更改的话,请慎重考虑升级到2.X.X版本。*** --- ### 详细开发文档请看 [wiki](https://github.com/chanjarster/weixin-java-tools/wiki)。 From 5c3bf7a933f25b28d4b580fd52436206d9dc6ea3 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 6 Sep 2016 19:07:27 +0800 Subject: [PATCH 17/49] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d7b1ca7d..a546f16d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ ### 声明:本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。 ### 最新更新:2.1.0版发布!!! on 2016-08-31 -* *** 注意 自2.0.0版本以来,接口调整比较大,主要是公众号的调整,企业号无过多调整,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。所以如果习惯于1.X.X版本的同学不想做过多更改的话,请慎重考虑升级到2.X.X版本。*** + +#### ***自2.0.0版本以来,接口调整比较大,主要是公众号的调整,企业号无过多调整,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。所以如果习惯于1.X.X版本的同学不想做过多更改的话,请慎重考虑升级到2.X.X版本.*** --- ### 详细开发文档请看 [wiki](https://github.com/chanjarster/weixin-java-tools/wiki)。 From 4732f2112118ea1fb60412f5b66af74db0ec0963 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 6 Sep 2016 19:08:00 +0800 Subject: [PATCH 18/49] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c6a776c9..a546f16d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ ### 声明:本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。 ### 最新更新:2.1.0版发布!!! on 2016-08-31 -#### 自2.0.0版本以来,接口调整比较大,主要是公众号的调整,企业号无过多调整,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。所以如果习惯于1.X.X版本的同学不想做过多更改的话,请慎重考虑升级到2.X.X版本。 + +#### ***自2.0.0版本以来,接口调整比较大,主要是公众号的调整,企业号无过多调整,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。所以如果习惯于1.X.X版本的同学不想做过多更改的话,请慎重考虑升级到2.X.X版本.*** --- ### 详细开发文档请看 [wiki](https://github.com/chanjarster/weixin-java-tools/wiki)。 From f5273ba732f815b792e8b360d0d23f06907ad396 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Wed, 7 Sep 2016 20:04:55 +0800 Subject: [PATCH 19/49] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3=20?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=9E=84=E9=80=A0=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=BD=91=E7=AB=99=E5=BA=94=E7=94=A8=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E7=99=BB=E5=BD=95=E7=9A=84url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/common/api/WxConsts.java | 6 + .../me/chanjar/weixin/mp/api/WxMpService.java | 14 ++ .../weixin/mp/api/impl/WxMpServiceImpl.java | 17 ++ .../chanjar/weixin/mp/api/ApiTestModule.java | 9 + .../weixin/mp/api/WxMpMiscAPITest.java | 2 +- .../mp/api/impl/WxMpServiceImplTest.java | 162 ++++++++++++++++++ .../src/test/resources/test-config.sample.xml | 1 + 7 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java index e45643b7..ce2a16a4 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java @@ -164,6 +164,12 @@ public class WxConsts { * 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息 */ public static final String OAUTH2_SCOPE_USER_INFO = "snsapi_userinfo"; + + /** + * 网页应用登录授权作用域 snsapi_login + */ + public static final String QRCONNECT_SCOPE_SNSAPI_LOGIN = "snsapi_login"; + /////////////////////// // 永久素材类型 /////////////////////// diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 7acd2342..ab205a03 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -152,6 +152,20 @@ public interface WxMpService { */ WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException; + /** + *
+   * 构造第三方使用网站应用授权登录的url
+   * 详情请见: 网站应用微信登录开发指南
+   * URL格式为:https://open.weixin.qq.com/connect/qrconnect?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
+   * 
+ * + * @param redirectURI 用户授权完成后的重定向链接,无需urlencode, 方法内会进行encode + * @param scope 应用授权作用域,拥有多个作用域用逗号(,)分隔,网页应用目前仅填写snsapi_login即可 + * @param state 非必填,用于保持请求和回调的状态,授权请求后原样带回给第三方。该参数可用于防止csrf攻击(跨站请求伪造攻击),建议第三方带上该参数,可设置为简单的随机数加session进行校验 + * @return url + */ + String buildQrConnectUrl(String redirectURI, String scope, String state); + /** *
    * 构造oauth2授权的url连接
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java
index 43777c16..b3f52ed8 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java
@@ -282,6 +282,23 @@ public class WxMpServiceImpl implements WxMpService {
     return url.toString();
   }
 
+  @Override
+  public String buildQrConnectUrl(String redirectURI, String scope,
+      String state) {
+    StringBuilder url = new StringBuilder();
+    url.append("https://open.weixin.qq.com/connect/qrconnect?");
+    url.append("appid=").append(this.wxMpConfigStorage.getAppId());
+    url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI));
+    url.append("&response_type=code");
+    url.append("&scope=").append(scope);
+    if (state != null) {
+      url.append("&state=").append(state);
+    }
+    
+    url.append("#wechat_redirect");
+    return url.toString();
+  }
+
   private WxMpOAuth2AccessToken getOAuth2AccessToken(StringBuilder url) throws WxErrorException {
     try {
       RequestExecutor executor = new SimpleGetRequestExecutor();
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java
index 4980faca..4557c342 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java
@@ -44,6 +44,7 @@ public class ApiTestModule implements Module {
 
     private String openId;
     private String kfAccount;
+    private String qrconnectRedirectUrl;
 
     public String getOpenId() {
       return this.openId;
@@ -66,6 +67,14 @@ public class ApiTestModule implements Module {
       this.kfAccount = kfAccount;
     }
 
+    public String getQrconnectRedirectUrl() {
+      return this.qrconnectRedirectUrl;
+    }
+
+    public void setQrconnectRedirectUrl(String qrconnectRedirectUrl) {
+      this.qrconnectRedirectUrl = qrconnectRedirectUrl;
+    }
+
   }
 
 }
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java
index 3d80836f..de0725ea 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java
@@ -23,7 +23,7 @@ public class WxMpMiscAPITest {
 
   @Test
   public void testGetCallbackIP() throws WxErrorException {
-    String[] ipArray = wxService.getCallbackIP();
+    String[] ipArray = this.wxService.getCallbackIP();
     System.out.println(Arrays.toString(ipArray));
     Assert.assertNotNull(ipArray);
     Assert.assertNotEquals(ipArray.length, 0);
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java
new file mode 100644
index 00000000..5791367b
--- /dev/null
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java
@@ -0,0 +1,162 @@
+package me.chanjar.weixin.mp.api.impl;
+
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
+
+import com.google.inject.Inject;
+
+import me.chanjar.weixin.common.api.WxConsts;
+import me.chanjar.weixin.mp.api.ApiTestModule;
+import me.chanjar.weixin.mp.api.ApiTestModule.WxXmlMpInMemoryConfigStorage;
+
+import org.testng.Assert;
+
+@Test
+@Guice(modules = ApiTestModule.class)
+public class WxMpServiceImplTest {
+
+  @Inject
+  private WxMpServiceImpl wxService;
+
+  @Test
+  public void testCheckSignature() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testGetAccessToken() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testGetAccessTokenBoolean() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testGetJsapiTicket() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testGetJsapiTicketBoolean() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testCreateJsapiSignature() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testCustomMessageSend() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testMassNewsUpload() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testMassVideoUpload() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testMassGroupMessageSend() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testMassOpenIdsMessageSend() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testMassMessagePreview() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testShortUrl() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testTemplateSend() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testSetIndustry() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testGetIndustry() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testSemanticQuery() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testOauth2buildAuthorizationUrl() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testBuildQrConnectUrl() {
+    String qrConnectUrl = this.wxService
+        .buildQrConnectUrl(
+            ((WxXmlMpInMemoryConfigStorage) this.wxService
+                .getWxMpConfigStorage()).getOauth2redirectUri(),
+            WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null);
+    Assert.assertNotNull(qrConnectUrl);
+    System.out.println(qrConnectUrl);
+  }
+
+  @Test
+  public void testOauth2getAccessToken() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testOauth2refreshAccessToken() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testOauth2getUserInfo() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testOauth2validateAccessToken() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testGetCallbackIP() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testGet() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testPost() {
+    Assert.fail("Not yet implemented");
+  }
+
+  @Test
+  public void testExecute() {
+    Assert.fail("Not yet implemented");
+  }
+
+}
diff --git a/weixin-java-mp/src/test/resources/test-config.sample.xml b/weixin-java-mp/src/test/resources/test-config.sample.xml
index 1f79bea2..836b26c4 100644
--- a/weixin-java-mp/src/test/resources/test-config.sample.xml
+++ b/weixin-java-mp/src/test/resources/test-config.sample.xml
@@ -7,5 +7,6 @@
     可以不填写
     某个加你公众号的用户的openId
     网页授权获取用户信息回调地址
+    网页应用授权登陆回调地址
     完整客服账号,格式为:账号前缀@公众号微信号
 

From 168e168d655f29111f994ce0f3e70c71407f9a55 Mon Sep 17 00:00:00 2001
From: BinaryWang 
Date: Wed, 7 Sep 2016 20:25:11 +0800
Subject: [PATCH 20/49] =?UTF-8?q?jedis=E4=BD=9C=E4=B8=BA=E9=9D=9E=E5=BF=85?=
 =?UTF-8?q?=E9=9C=80=E4=BE=9D=E8=B5=96=E9=A1=B9=E6=94=B9=E4=B8=BAprovided?=
 =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=97=B6=E6=9B=B4=E6=94=B9=E7=89=88=E6=9C=AC?=
 =?UTF-8?q?=E5=8F=B7=E7=94=A8=E4=BA=8E=E5=8F=91=E5=B8=83=E4=B8=B4=E6=97=B6?=
 =?UTF-8?q?=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pom.xml                    | 3 ++-
 weixin-java-common/pom.xml | 2 +-
 weixin-java-cp/pom.xml     | 2 +-
 weixin-java-mp/pom.xml     | 4 ++--
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0b6d48b9..54782c38 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
   4.0.0
   com.github.binarywang
   weixin-java-parent
-  2.2.0-SNAPSHOT
+  2.1.1
   pom
   WeiXin Java Tools - Parent
   微信公众号、企业号上级POM
@@ -115,6 +115,7 @@
       redis.clients
       jedis
       ${jedis.version}
+      provided
     
   
 
diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml
index 4eba081a..d77b70b8 100644
--- a/weixin-java-common/pom.xml
+++ b/weixin-java-common/pom.xml
@@ -6,7 +6,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.2.0-SNAPSHOT
+    2.1.1
   
 
   weixin-java-common
diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
index 4acb1649..2aa6f0fe 100644
--- a/weixin-java-cp/pom.xml
+++ b/weixin-java-cp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.2.0-SNAPSHOT
+        2.1.1
     
 
     weixin-java-cp
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index 86254322..fedbba6e 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.2.0-SNAPSHOT
+        2.1.1
     
     weixin-java-mp
     WeiXin Java Tools - MP
@@ -47,7 +47,7 @@
             org.eclipse.jetty
             jetty-servlet
             test
-        
+        
         
             joda-time
             joda-time

From 1388060891e57d02f458aae5574fff3bf87e9f3e Mon Sep 17 00:00:00 2001
From: BinaryWang 
Date: Thu, 8 Sep 2016 15:19:05 +0800
Subject: [PATCH 21/49] fix warnings

---
 .../weixin/cp/api/WxCpServiceImpl.java        | 185 +++++++++++-------
 1 file changed, 111 insertions(+), 74 deletions(-)

diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java
index 84cb614a..741daf15 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java
@@ -1,12 +1,28 @@
 package me.chanjar.weixin.cp.api;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.http.HttpHost;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
 import com.google.gson.JsonPrimitive;
-import com.google.gson.internal.Streams;
 import com.google.gson.reflect.TypeToken;
-import com.google.gson.stream.JsonReader;
+
 import me.chanjar.weixin.common.bean.WxAccessToken;
 import me.chanjar.weixin.common.bean.WxJsapiSignature;
 import me.chanjar.weixin.common.bean.menu.WxMenu;
@@ -20,30 +36,20 @@ import me.chanjar.weixin.common.util.RandomUtils;
 import me.chanjar.weixin.common.util.StringUtils;
 import me.chanjar.weixin.common.util.crypto.SHA1;
 import me.chanjar.weixin.common.util.fs.FileUtils;
-import me.chanjar.weixin.common.util.http.*;
+import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
+import me.chanjar.weixin.common.util.http.DefaultApacheHttpClientBuilder;
+import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor;
+import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
+import me.chanjar.weixin.common.util.http.RequestExecutor;
+import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
+import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
+import me.chanjar.weixin.common.util.http.URIUtil;
 import me.chanjar.weixin.common.util.json.GsonHelper;
 import me.chanjar.weixin.cp.bean.WxCpDepart;
 import me.chanjar.weixin.cp.bean.WxCpMessage;
 import me.chanjar.weixin.cp.bean.WxCpTag;
 import me.chanjar.weixin.cp.bean.WxCpUser;
 import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
-import org.apache.http.HttpHost;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.BasicResponseHandler;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.security.NoSuchAlgorithmException;
-import java.util.List;
-import java.util.UUID;
 
 public class WxCpServiceImpl implements WxCpService {
 
@@ -72,42 +78,48 @@ public class WxCpServiceImpl implements WxCpService {
   private int retrySleepMillis = 1000;
   private int maxRetryTimes = 5;
 
+  @Override
   public boolean checkSignature(String msgSignature, String timestamp, String nonce, String data) {
     try {
-      return SHA1.gen(wxCpConfigStorage.getToken(), timestamp, nonce, data).equals(msgSignature);
+      return SHA1.gen(this.wxCpConfigStorage.getToken(), timestamp, nonce, data)
+          .equals(msgSignature);
     } catch (Exception e) {
       return false;
     }
   }
 
+  @Override
   public void userAuthenticated(String userId) throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/user/authsucc?userid=" + userId;
     get(url, null);
   }
 
+  @Override
   public String getAccessToken() throws WxErrorException {
     return getAccessToken(false);
   }
 
+  @Override
   public String getAccessToken(boolean forceRefresh) throws WxErrorException {
     if (forceRefresh) {
-      wxCpConfigStorage.expireAccessToken();
+      this.wxCpConfigStorage.expireAccessToken();
     }
-    if (wxCpConfigStorage.isAccessTokenExpired()) {
-      synchronized (globalAccessTokenRefreshLock) {
-        if (wxCpConfigStorage.isAccessTokenExpired()) {
+    if (this.wxCpConfigStorage.isAccessTokenExpired()) {
+      synchronized (this.globalAccessTokenRefreshLock) {
+        if (this.wxCpConfigStorage.isAccessTokenExpired()) {
           String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"
-                  + "&corpid=" + wxCpConfigStorage.getCorpId()
-                  + "&corpsecret=" + wxCpConfigStorage.getCorpSecret();
+              + "&corpid=" + this.wxCpConfigStorage.getCorpId() + "&corpsecret="
+              + this.wxCpConfigStorage.getCorpSecret();
           try {
             HttpGet httpGet = new HttpGet(url);
-            if (httpProxy != null) {
-              RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
+            if (this.httpProxy != null) {
+              RequestConfig config = RequestConfig.custom()
+                  .setProxy(this.httpProxy).build();
               httpGet.setConfig(config);
             }
-            CloseableHttpClient httpclient = getHttpclient();
             String resultContent = null;
-            try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
+            try (CloseableHttpClient httpclient = getHttpclient();
+                CloseableHttpResponse response = httpclient.execute(httpGet)) {
               resultContent = new BasicResponseHandler().handleResponse(response);
             } finally {
               httpGet.releaseConnection();
@@ -117,7 +129,8 @@ public class WxCpServiceImpl implements WxCpService {
               throw new WxErrorException(error);
             }
             WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
-            wxCpConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
+            this.wxCpConfigStorage.updateAccessToken(
+                accessToken.getAccessToken(), accessToken.getExpiresIn());
           } catch (ClientProtocolException e) {
             throw new RuntimeException(e);
           } catch (IOException e) {
@@ -126,33 +139,37 @@ public class WxCpServiceImpl implements WxCpService {
         }
       }
     }
-    return wxCpConfigStorage.getAccessToken();
+    return this.wxCpConfigStorage.getAccessToken();
   }
 
+  @Override
   public String getJsapiTicket() throws WxErrorException {
     return getJsapiTicket(false);
   }
 
+  @Override
   public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
     if (forceRefresh) {
-      wxCpConfigStorage.expireJsapiTicket();
+      this.wxCpConfigStorage.expireJsapiTicket();
     }
-    if (wxCpConfigStorage.isJsapiTicketExpired()) {
-      synchronized (globalJsapiTicketRefreshLock) {
-        if (wxCpConfigStorage.isJsapiTicketExpired()) {
+    if (this.wxCpConfigStorage.isJsapiTicketExpired()) {
+      synchronized (this.globalJsapiTicketRefreshLock) {
+        if (this.wxCpConfigStorage.isJsapiTicketExpired()) {
           String url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket";
           String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
-          JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
+          JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
           JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
           String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
           int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
-          wxCpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds);
+          this.wxCpConfigStorage.updateJsapiTicket(jsapiTicket,
+              expiresInSeconds);
         }
       }
     }
-    return wxCpConfigStorage.getJsapiTicket();
+    return this.wxCpConfigStorage.getJsapiTicket();
   }
 
+  @Override
   public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException {
     long timestamp = System.currentTimeMillis() / 1000;
     String noncestr = RandomUtils.getRandomStr();
@@ -175,6 +192,7 @@ public class WxCpServiceImpl implements WxCpService {
     return jsapiSignature;
   }
 
+  @Override
   public void messageSend(WxCpMessage message) throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/message/send";
     post(url, message.toJson());
@@ -182,18 +200,19 @@ public class WxCpServiceImpl implements WxCpService {
 
   @Override
   public void menuCreate(WxMenu menu) throws WxErrorException {
-    menuCreate(wxCpConfigStorage.getAgentId(), menu);
+    menuCreate(this.wxCpConfigStorage.getAgentId(), menu);
   }
 
   @Override
   public void menuCreate(String agentId, WxMenu menu) throws WxErrorException {
-    String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid=" + wxCpConfigStorage.getAgentId();
+    String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid="
+        + this.wxCpConfigStorage.getAgentId();
     post(url, menu.toJson());
   }
 
   @Override
   public void menuDelete() throws WxErrorException {
-    menuDelete(wxCpConfigStorage.getAgentId());
+    menuDelete(this.wxCpConfigStorage.getAgentId());
   }
 
   @Override
@@ -204,7 +223,7 @@ public class WxCpServiceImpl implements WxCpService {
 
   @Override
   public WxMenu menuGet() throws WxErrorException {
-    return menuGet(wxCpConfigStorage.getAgentId());
+    return menuGet(this.wxCpConfigStorage.getAgentId());
   }
 
   @Override
@@ -222,42 +241,52 @@ public class WxCpServiceImpl implements WxCpService {
     }
   }
 
+  @Override
   public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream)
           throws WxErrorException, IOException {
     return mediaUpload(mediaType, FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType));
   }
 
+  @Override
   public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?type=" + mediaType;
     return execute(new MediaUploadRequestExecutor(), url, file);
   }
 
+  @Override
   public File mediaDownload(String media_id) throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/media/get";
-    return execute(new MediaDownloadRequestExecutor(wxCpConfigStorage.getTmpDirFile()), url, "media_id=" + media_id);
+    return execute(
+        new MediaDownloadRequestExecutor(
+            this.wxCpConfigStorage.getTmpDirFile()),
+        url, "media_id=" + media_id);
   }
 
 
+  @Override
   public Integer departCreate(WxCpDepart depart) throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
     String responseContent = execute(
             new SimplePostRequestExecutor(),
             url,
             depart.toJson());
-    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
+    JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
     return GsonHelper.getAsInteger(tmpJsonElement.getAsJsonObject().get("id"));
   }
 
+  @Override
   public void departUpdate(WxCpDepart group) throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/department/update";
     post(url, group.toJson());
   }
 
+  @Override
   public void departDelete(Integer departId) throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?id=" + departId;
     get(url, null);
   }
 
+  @Override
   public List departGet() throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
     String responseContent = get(url, null);
@@ -265,7 +294,7 @@ public class WxCpServiceImpl implements WxCpService {
      * 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} }
      * 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
      */
-    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
+    JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
     return WxCpGsonBuilder.INSTANCE.create()
             .fromJson(
                     tmpJsonElement.getAsJsonObject().get("department"),
@@ -325,7 +354,7 @@ public class WxCpServiceImpl implements WxCpService {
     }
 
     String responseContent = get(url, params);
-    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
+    JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
     return WxCpGsonBuilder.INSTANCE.create()
             .fromJson(
                     tmpJsonElement.getAsJsonObject().get("userlist"),
@@ -348,7 +377,7 @@ public class WxCpServiceImpl implements WxCpService {
     }
 
     String responseContent = get(url, params);
-    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
+    JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
     return WxCpGsonBuilder.INSTANCE.create()
             .fromJson(
                     tmpJsonElement.getAsJsonObject().get("userlist"),
@@ -363,7 +392,7 @@ public class WxCpServiceImpl implements WxCpService {
     JsonObject o = new JsonObject();
     o.addProperty("tagname", tagName);
     String responseContent = post(url, o.toString());
-    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
+    JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
     return tmpJsonElement.getAsJsonObject().get("tagid").getAsString();
   }
 
@@ -386,7 +415,7 @@ public class WxCpServiceImpl implements WxCpService {
   public List tagGet() throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/list";
     String responseContent = get(url, null);
-    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
+    JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
     return WxCpGsonBuilder.INSTANCE.create()
             .fromJson(
                     tmpJsonElement.getAsJsonObject().get("taglist"),
@@ -399,7 +428,7 @@ public class WxCpServiceImpl implements WxCpService {
   public List tagGetUsers(String tagId) throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagid=" + tagId;
     String responseContent = get(url, null);
-    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
+    JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
     return WxCpGsonBuilder.INSTANCE.create()
             .fromJson(
                     tmpJsonElement.getAsJsonObject().get("userlist"),
@@ -454,7 +483,7 @@ public class WxCpServiceImpl implements WxCpService {
 	@Override
   public String oauth2buildAuthorizationUrl(String redirectUri, String state) {
     String url = "https://open.weixin.qq.com/connect/oauth2/authorize?";
-    url += "appid=" + wxCpConfigStorage.getCorpId();
+    url += "appid=" + this.wxCpConfigStorage.getCorpId();
     url += "&redirect_uri=" + URIUtil.encodeURIComponent(redirectUri);
     url += "&response_type=code";
     url += "&scope=snsapi_base";
@@ -467,7 +496,7 @@ public class WxCpServiceImpl implements WxCpService {
 
   @Override
   public String[] oauth2getUserInfo(String code) throws WxErrorException {
-    return oauth2getUserInfo(wxCpConfigStorage.getAgentId(), code);
+    return oauth2getUserInfo(this.wxCpConfigStorage.getAgentId(), code);
   }
 
   @Override
@@ -476,7 +505,7 @@ public class WxCpServiceImpl implements WxCpService {
             + "code=" + code
             + "&agendid=" + agentId;
     String responseText = get(url, null);
-    JsonElement je = Streams.parse(new JsonReader(new StringReader(responseText)));
+    JsonElement je = new JsonParser().parse(responseText);
     JsonObject jo = je.getAsJsonObject();
     return new String[]{GsonHelper.getString(jo, "UserId"), GsonHelper.getString(jo, "DeviceId")};
   }
@@ -490,7 +519,7 @@ public class WxCpServiceImpl implements WxCpService {
       jsonObject.addProperty("invite_tips", inviteTips);
     }
     String responseContent = post(url, jsonObject.toString());
-    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
+    JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
     return tmpJsonElement.getAsJsonObject().get("type").getAsInt();
   }
 
@@ -498,7 +527,7 @@ public class WxCpServiceImpl implements WxCpService {
   public String[] getCallbackIp() throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/getcallbackip";
     String responseContent = get(url, null);
-    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
+    JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
     JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
     String[] ips = new String[jsonArray.size()];
     for (int i = 0; i < jsonArray.size(); i++) {
@@ -507,10 +536,12 @@ public class WxCpServiceImpl implements WxCpService {
     return ips;
   }
 
+  @Override
   public String get(String url, String queryParam) throws WxErrorException {
     return execute(new SimpleGetRequestExecutor(), url, queryParam);
   }
 
+  @Override
   public String post(String url, String postData) throws WxErrorException {
     return execute(new SimplePostRequestExecutor(), url, postData);
   }
@@ -518,6 +549,7 @@ public class WxCpServiceImpl implements WxCpService {
   /**
    * 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求
    */
+  @Override
   public  T execute(RequestExecutor executor, String uri, E data) throws WxErrorException {
     int retryTimes = 0;
     do {
@@ -529,9 +561,10 @@ public class WxCpServiceImpl implements WxCpService {
          * -1 系统繁忙, 1000ms后重试
          */
         if (error.getErrorCode() == -1) {
-          int sleepMillis = retrySleepMillis * (1 << retryTimes);
+          int sleepMillis = this.retrySleepMillis * (1 << retryTimes);
           try {
-            log.debug("微信系统繁忙,{}ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
+            this.log.debug("微信系统繁忙,{}ms 后重试(第{}次)", sleepMillis,
+                retryTimes + 1);
             Thread.sleep(sleepMillis);
           } catch (InterruptedException e1) {
             throw new RuntimeException(e1);
@@ -540,7 +573,7 @@ public class WxCpServiceImpl implements WxCpService {
           throw e;
         }
       }
-    } while (++retryTimes < maxRetryTimes);
+    } while (++retryTimes < this.maxRetryTimes);
 
     throw new RuntimeException("微信服务端异常,超出重试次数");
   }
@@ -555,7 +588,8 @@ public class WxCpServiceImpl implements WxCpService {
     uriWithAccessToken += uri.indexOf('?') == -1 ? "?access_token=" + accessToken : "&access_token=" + accessToken;
 
     try {
-      return executor.execute(getHttpclient(), httpProxy, uriWithAccessToken, data);
+      return executor.execute(getHttpclient(), this.httpProxy,
+          uriWithAccessToken, data);
     } catch (WxErrorException e) {
       WxError error = e.getError();
       /*
@@ -565,7 +599,7 @@ public class WxCpServiceImpl implements WxCpService {
        */
       if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) {
         // 强制设置wxCpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
-        wxCpConfigStorage.expireAccessToken();
+        this.wxCpConfigStorage.expireAccessToken();
         return execute(executor, uri, data);
       }
       if (error.getErrorCode() != 0) {
@@ -580,21 +614,24 @@ public class WxCpServiceImpl implements WxCpService {
   }
 
   protected CloseableHttpClient getHttpclient() {
-    return httpClient;
+    return this.httpClient;
   }
 
+  @Override
   public void setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider) {
     this.wxCpConfigStorage = wxConfigProvider;
-    ApacheHttpClientBuilder apacheHttpClientBuilder = wxCpConfigStorage.getApacheHttpClientBuilder();
+    ApacheHttpClientBuilder apacheHttpClientBuilder = this.wxCpConfigStorage
+        .getApacheHttpClientBuilder();
     if (null == apacheHttpClientBuilder) {
       apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
     }
-    apacheHttpClientBuilder.httpProxyHost(wxCpConfigStorage.getHttp_proxy_host())
-            .httpProxyPort(wxCpConfigStorage.getHttp_proxy_port())
-            .httpProxyUsername(wxCpConfigStorage.getHttp_proxy_username())
-            .httpProxyPassword(wxCpConfigStorage.getHttp_proxy_password());
+    apacheHttpClientBuilder
+        .httpProxyHost(this.wxCpConfigStorage.getHttp_proxy_host())
+        .httpProxyPort(this.wxCpConfigStorage.getHttp_proxy_port())
+        .httpProxyUsername(this.wxCpConfigStorage.getHttp_proxy_username())
+        .httpProxyPassword(this.wxCpConfigStorage.getHttp_proxy_password());
 
-    httpClient = apacheHttpClientBuilder.build();
+    this.httpClient = apacheHttpClientBuilder.build();
   }
 
   @Override
@@ -610,18 +647,18 @@ public class WxCpServiceImpl implements WxCpService {
 
   @Override
   public WxSession getSession(String id) {
-    if (sessionManager == null) {
+    if (this.sessionManager == null) {
       return null;
     }
-    return sessionManager.getSession(id);
+    return this.sessionManager.getSession(id);
   }
 
   @Override
   public WxSession getSession(String id, boolean create) {
-    if (sessionManager == null) {
+    if (this.sessionManager == null) {
       return null;
     }
-    return sessionManager.getSession(id, create);
+    return this.sessionManager.getSession(id, create);
   }
 
 
@@ -653,7 +690,7 @@ public class WxCpServiceImpl implements WxCpService {
   }
 
   public File getTmpDirFile() {
-    return tmpDirFile;
+    return this.tmpDirFile;
   }
 
   public void setTmpDirFile(File tmpDirFile) {

From 4e67dbee51dbb786cdfc7a61f9a80a5dfbbcfe50 Mon Sep 17 00:00:00 2001
From: BinaryWang 
Date: Thu, 8 Sep 2016 15:21:17 +0800
Subject: [PATCH 22/49] fix warnings

---
 .../cp/api/WxCpInMemoryConfigStorage.java     | 61 +++++++++++--------
 1 file changed, 34 insertions(+), 27 deletions(-)

diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java
index 52d0c93b..cd4a8575 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java
@@ -1,10 +1,13 @@
 package me.chanjar.weixin.cp.api;
 
+import java.io.File;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
 import me.chanjar.weixin.common.bean.WxAccessToken;
 import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
 
-import java.io.File;
-
 /**
  * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
  *
@@ -35,6 +38,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
 
   private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
 
+  @Override
   public String getAccessToken() {
     return this.accessToken;
   }
@@ -43,18 +47,22 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
     this.accessToken = accessToken;
   }
 
+  @Override
   public boolean isAccessTokenExpired() {
     return System.currentTimeMillis() > this.expiresTime;
   }
 
+  @Override
   public void expireAccessToken() {
     this.expiresTime = 0;
   }
 
+  @Override
   public synchronized void updateAccessToken(WxAccessToken accessToken) {
     updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
   }
 
+  @Override
   public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) {
     this.accessToken = accessToken;
     this.expiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000l;
@@ -62,7 +70,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
 
   @Override
   public String getJsapiTicket() {
-    return jsapiTicket;
+    return this.jsapiTicket;
   }
 
   public void setJsapiTicket(String jsapiTicket) {
@@ -70,27 +78,31 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
   }
 
   public long getJsapiTicketExpiresTime() {
-    return jsapiTicketExpiresTime;
+    return this.jsapiTicketExpiresTime;
   }
 
   public void setJsapiTicketExpiresTime(long jsapiTicketExpiresTime) {
     this.jsapiTicketExpiresTime = jsapiTicketExpiresTime;
   }
 
+  @Override
   public boolean isJsapiTicketExpired() {
     return System.currentTimeMillis() > this.jsapiTicketExpiresTime;
   }
 
+  @Override
   public synchronized void updateJsapiTicket(String jsapiTicket, int expiresInSeconds) {
     this.jsapiTicket = jsapiTicket;
     // 预留200秒的时间
     this.jsapiTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000l;
   }
 
+  @Override
   public void expireJsapiTicket() {
     this.jsapiTicketExpiresTime = 0;
   }
 
+  @Override
   public String getCorpId() {
     return this.corpId;
   }
@@ -99,6 +111,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
     this.corpId = corpId;
   }
 
+  @Override
   public String getCorpSecret() {
     return this.corpSecret;
   }
@@ -107,6 +120,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
     this.corpSecret = corpSecret;
   }
 
+  @Override
   public String getToken() {
     return this.token;
   }
@@ -115,6 +129,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
     this.token = token;
   }
 
+  @Override
   public long getExpiresTime() {
     return this.expiresTime;
   }
@@ -123,16 +138,18 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
     this.expiresTime = expiresTime;
   }
 
+  @Override
   public String getAesKey() {
-    return aesKey;
+    return this.aesKey;
   }
 
   public void setAesKey(String aesKey) {
     this.aesKey = aesKey;
   }
 
+  @Override
   public String getAgentId() {
-    return agentId;
+    return this.agentId;
   }
 
   public void setAgentId(String agentId) {
@@ -148,32 +165,36 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
     this.oauth2redirectUri = oauth2redirectUri;
   }
 
+  @Override
   public String getHttp_proxy_host() {
-    return http_proxy_host;
+    return this.http_proxy_host;
   }
 
   public void setHttp_proxy_host(String http_proxy_host) {
     this.http_proxy_host = http_proxy_host;
   }
 
+  @Override
   public int getHttp_proxy_port() {
-    return http_proxy_port;
+    return this.http_proxy_port;
   }
 
   public void setHttp_proxy_port(int http_proxy_port) {
     this.http_proxy_port = http_proxy_port;
   }
 
+  @Override
   public String getHttp_proxy_username() {
-    return http_proxy_username;
+    return this.http_proxy_username;
   }
 
   public void setHttp_proxy_username(String http_proxy_username) {
     this.http_proxy_username = http_proxy_username;
   }
 
+  @Override
   public String getHttp_proxy_password() {
-    return http_proxy_password;
+    return this.http_proxy_password;
   }
 
   public void setHttp_proxy_password(String http_proxy_password) {
@@ -182,26 +203,12 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
 
   @Override
   public String toString() {
-    return "WxCpInMemoryConfigStorage{" +
-            "corpId='" + corpId + '\'' +
-            ", corpSecret='" + corpSecret + '\'' +
-            ", token='" + token + '\'' +
-            ", accessToken='" + accessToken + '\'' +
-            ", aesKey='" + aesKey + '\'' +
-            ", agentId='" + agentId + '\'' +
-            ", expiresTime=" + expiresTime +
-            ", http_proxy_host='" + http_proxy_host + '\'' +
-            ", http_proxy_port=" + http_proxy_port +
-            ", http_proxy_username='" + http_proxy_username + '\'' +
-            ", http_proxy_password='" + http_proxy_password + '\'' +
-            ", jsapiTicket='" + jsapiTicket + '\'' +
-            ", jsapiTicketExpiresTime='" + jsapiTicketExpiresTime + '\'' +
-            ", tmpDirFile='" + tmpDirFile + '\'' +
-            '}';
+    return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
   }
 
+  @Override
   public File getTmpDirFile() {
-    return tmpDirFile;
+    return this.tmpDirFile;
   }
 
   public void setTmpDirFile(File tmpDirFile) {

From cc59d2787159614938e403dcee3b06539364ff18 Mon Sep 17 00:00:00 2001
From: BinaryWang 
Date: Thu, 8 Sep 2016 15:32:16 +0800
Subject: [PATCH 23/49] Suppress Warnings

---
 .../weixin/common/util/http/DefaultApacheHttpClientBuilder.java  | 1 +
 1 file changed, 1 insertion(+)

diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java
index 15f0308e..f01d0d9e 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java
@@ -108,6 +108,7 @@ public class DefaultApacheHttpClientBuilder implements ApacheHttpClientBuilder {
             .register("https", this.sslConnectionSocketFactory)
             .build();
 
+    @SuppressWarnings("resource")
     PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
     connectionManager.setMaxTotal(this.maxTotalConn);
     connectionManager.setDefaultMaxPerRoute(this.maxConnPerHost);

From d42227c78e7de5e112a6f6deca75f003eea76744 Mon Sep 17 00:00:00 2001
From: BinaryWang 
Date: Thu, 8 Sep 2016 15:35:51 +0800
Subject: [PATCH 24/49] fix warnings

---
 .../chanjar/weixin/cp/api/ApiTestModule.java  | 12 +++++-----
 .../weixin/cp/api/WxCpBaseAPITest.java        |  4 ++--
 .../weixin/cp/api/WxCpDepartAPITest.java      | 16 ++++++-------
 .../weixin/cp/api/WxCpMediaAPITest.java       | 10 ++++----
 .../weixin/cp/api/WxCpMessageAPITest.java     |  6 ++---
 .../weixin/cp/api/WxCpMessageRouterTest.java  |  2 +-
 .../chanjar/weixin/cp/api/WxCpTagAPITest.java | 24 +++++++++----------
 .../weixin/cp/api/WxCpUserAPITest.java        | 10 ++++----
 .../chanjar/weixin/cp/api/WxMenuAPITest.java  |  6 ++---
 .../demo/WxCpDemoInMemoryConfigStorage.java   |  4 ++--
 .../weixin/cp/demo/WxCpEndpointServlet.java   | 10 ++++----
 .../weixin/cp/demo/WxCpOAuth2Servlet.java     |  2 +-
 12 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java
index 5235486b..179e8a08 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java
@@ -38,7 +38,7 @@ public class ApiTestModule implements Module {
     protected String tagId;
 
     public String getUserId() {
-      return userId;
+      return this.userId;
     }
 
     public void setUserId(String userId) {
@@ -46,7 +46,7 @@ public class ApiTestModule implements Module {
     }
 
     public String getDepartmentId() {
-      return departmentId;
+      return this.departmentId;
     }
 
     public void setDepartmentId(String departmentId) {
@@ -54,7 +54,7 @@ public class ApiTestModule implements Module {
     }
 
     public String getTagId() {
-      return tagId;
+      return this.tagId;
     }
 
     public void setTagId(String tagId) {
@@ -64,9 +64,9 @@ public class ApiTestModule implements Module {
     @Override
     public String toString() {
       return super.toString() + " > WxXmlCpConfigStorage{" +
-              "userId='" + userId + '\'' +
-              ", departmentId='" + departmentId + '\'' +
-              ", tagId='" + tagId + '\'' +
+              "userId='" + this.userId + '\'' +
+              ", departmentId='" + this.departmentId + '\'' +
+              ", tagId='" + this.tagId + '\'' +
               '}';
     }
   }
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java
index 9f2b60f8..d2ac69e8 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java
@@ -20,9 +20,9 @@ public class WxCpBaseAPITest {
   protected WxCpServiceImpl wxService;
 
   public void testRefreshAccessToken() throws WxErrorException {
-    WxCpConfigStorage configStorage = wxService.wxCpConfigStorage;
+    WxCpConfigStorage configStorage = this.wxService.wxCpConfigStorage;
     String before = configStorage.getAccessToken();
-    wxService.getAccessToken(false);
+    this.wxService.getAccessToken(false);
 
     String after = configStorage.getAccessToken();
 
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java
index cb8db0d5..fb52eac0 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java
@@ -28,18 +28,18 @@ public class WxCpDepartAPITest {
     depart.setName("子部门" + System.currentTimeMillis());
     depart.setParentId(1);
     depart.setOrder(1);
-    Integer departId = wxCpService.departCreate(depart);
+    Integer departId = this.wxCpService.departCreate(depart);
   }
 
   @Test(dependsOnMethods = "testDepartCreate")
   public void testDepartGet() throws WxErrorException {
     System.out.println("=================获取部门");
-    List departList = wxCpService.departGet();
+    List departList = this.wxCpService.departGet();
     Assert.assertNotNull(departList);
     Assert.assertTrue(departList.size() > 0);
     for (WxCpDepart g : departList) {
-      depart = g;
-      System.out.println(depart.getId() + ":" + depart.getName());
+      this.depart = g;
+      System.out.println(this.depart.getId() + ":" + this.depart.getName());
       Assert.assertNotNull(g.getName());
     }
   }
@@ -47,15 +47,15 @@ public class WxCpDepartAPITest {
   @Test(dependsOnMethods = {"testDepartGet", "testDepartCreate"})
   public void testDepartUpdate() throws WxErrorException {
     System.out.println("=================更新部门");
-    depart.setName("子部门改名" + System.currentTimeMillis());
-    wxCpService.departUpdate(depart);
+    this.depart.setName("子部门改名" + System.currentTimeMillis());
+    this.wxCpService.departUpdate(this.depart);
   }
 
   @Test(dependsOnMethods = "testDepartUpdate")
   public void testDepartDelete() throws WxErrorException {
     System.out.println("=================删除部门");
-    System.out.println(depart.getId() + ":" + depart.getName());
-    wxCpService.departDelete(depart.getId());
+    System.out.println(this.depart.getId() + ":" + this.depart.getName());
+    this.wxCpService.departDelete(this.depart.getId());
   }
 
 }
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java
index e880ad07..97ac9186 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java
@@ -27,21 +27,21 @@ public class WxCpMediaAPITest {
   @Inject
   protected WxCpServiceImpl wxService;
 
-  private List media_ids = new ArrayList();
+  private List media_ids = new ArrayList<>();
 
   @Test(dataProvider = "uploadMedia")
   public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
     InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName);
-    WxMediaUploadResult res = wxService.mediaUpload(mediaType, fileType, inputStream);
+    WxMediaUploadResult res = this.wxService.mediaUpload(mediaType, fileType, inputStream);
     Assert.assertNotNull(res.getType());
     Assert.assertNotNull(res.getCreatedAt());
     Assert.assertTrue(res.getMediaId() != null || res.getThumbMediaId() != null);
 
     if (res.getMediaId() != null) {
-      media_ids.add(res.getMediaId());
+      this.media_ids.add(res.getMediaId());
     }
     if (res.getThumbMediaId() != null) {
-      media_ids.add(res.getThumbMediaId());
+      this.media_ids.add(res.getThumbMediaId());
     }
   }
 
@@ -57,7 +57,7 @@ public class WxCpMediaAPITest {
 
   @Test(dependsOnMethods = {"testUploadMedia"}, dataProvider = "downloadMedia")
   public void testDownloadMedia(String media_id) throws WxErrorException {
-    wxService.mediaDownload(media_id);
+    this.wxService.mediaDownload(media_id);
   }
 
   @DataProvider
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java
index 9810435e..8bfe07e6 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java
@@ -20,13 +20,13 @@ public class WxCpMessageAPITest {
   protected WxCpServiceImpl wxService;
 
   public void testSendCustomMessage() throws WxErrorException {
-    ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlCpInMemoryConfigStorage) wxService.wxCpConfigStorage;
+    ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlCpInMemoryConfigStorage) this.wxService.wxCpConfigStorage;
     WxCpMessage message1 = new WxCpMessage();
     message1.setAgentId(configStorage.getAgentId());
     message1.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
     message1.setToUser(configStorage.getUserId());
     message1.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World");
-    wxService.messageSend(message1);
+    this.wxService.messageSend(message1);
 
     WxCpMessage message2 = WxCpMessage
             .TEXT()
@@ -34,7 +34,7 @@ public class WxCpMessageAPITest {
             .toUser(configStorage.getUserId())
             .content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World")
             .build();
-    wxService.messageSend(message2);
+    this.wxService.messageSend(message2);
 
   }
 
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java
index a5e40968..4b0fc56a 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java
@@ -286,7 +286,7 @@ public class WxCpMessageRouterTest {
     @Override
     public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map context, WxCpService wxCpService,
                                     WxSessionManager sessionManager) {
-      sb.append(this.echoStr).append(',');
+      this.sb.append(this.echoStr).append(',');
       return null;
     }
 
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpTagAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpTagAPITest.java
index 130b0722..aa26e962 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpTagAPITest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpTagAPITest.java
@@ -23,44 +23,44 @@ public class WxCpTagAPITest {
   protected String tagId;
 
   public void testTagCreate() throws Exception {
-    tagId = wxService.tagCreate("测试标签4");
-    System.out.println(tagId);
+    this.tagId = this.wxService.tagCreate("测试标签4");
+    System.out.println(this.tagId);
   }
 
   @Test(dependsOnMethods = "testTagCreate")
   public void testTagUpdate() throws Exception {
-    wxService.tagUpdate(tagId, "测试标签-改名");
+    this.wxService.tagUpdate(this.tagId, "测试标签-改名");
   }
 
   @Test(dependsOnMethods = "testTagUpdate")
   public void testTagGet() throws Exception {
-    List tags = wxService.tagGet();
+    List tags = this.wxService.tagGet();
     Assert.assertNotEquals(tags.size(), 0);
   }
 
   @Test(dependsOnMethods = "testTagGet")
   public void testTagAddUsers() throws Exception {
-    List userIds = new ArrayList();
-    userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage) configStorage).getUserId());
-    wxService.tagAddUsers(tagId, userIds, null);
+    List userIds = new ArrayList<>();
+    userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage) this.configStorage).getUserId());
+    this.wxService.tagAddUsers(this.tagId, userIds, null);
   }
 
   @Test(dependsOnMethods = "testTagAddUsers")
   public void testTagGetUsers() throws Exception {
-    List users = wxService.tagGetUsers(tagId);
+    List users = this.wxService.tagGetUsers(this.tagId);
     Assert.assertNotEquals(users.size(), 0);
   }
 
   @Test(dependsOnMethods = "testTagGetUsers")
   public void testTagRemoveUsers() throws Exception {
-    List userIds = new ArrayList();
-    userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage) configStorage).getUserId());
-    wxService.tagRemoveUsers(tagId, userIds);
+    List userIds = new ArrayList<>();
+    userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage) this.configStorage).getUserId());
+    this.wxService.tagRemoveUsers(this.tagId, userIds);
   }
 
   @Test(dependsOnMethods = "testTagRemoveUsers")
   public void testTagDelete() throws Exception {
-    wxService.tagDelete(tagId);
+    this.wxService.tagDelete(this.tagId);
   }
 
 }
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpUserAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpUserAPITest.java
index 8c5d2064..4d5a7a91 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpUserAPITest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpUserAPITest.java
@@ -35,7 +35,7 @@ public class WxCpUserAPITest {
     user.setPosition("woman");
     user.setTel("3300393");
     user.addExtAttr("爱好", "table");
-    wxCpService.userCreate(user);
+    this.wxCpService.userCreate(user);
   }
 
   @Test(dependsOnMethods = "testUserCreate")
@@ -44,23 +44,23 @@ public class WxCpUserAPITest {
     user.setUserId("some.woman");
     user.setName("Some Woman");
     user.addExtAttr("爱好", "table2");
-    wxCpService.userUpdate(user);
+    this.wxCpService.userUpdate(user);
   }
 
   @Test(dependsOnMethods = "testUserUpdate")
   public void testUserGet() throws WxErrorException {
-    WxCpUser user = wxCpService.userGet("some.woman");
+    WxCpUser user = this.wxCpService.userGet("some.woman");
     Assert.assertNotNull(user);
   }
 
   @Test(dependsOnMethods = "testUserGet")
   public void testDepartGetUsers() throws WxErrorException {
-    List users = wxCpService.departGetUsers(1, true, 0);
+    List users = this.wxCpService.departGetUsers(1, true, 0);
     Assert.assertNotEquals(users.size(), 0);
   }
 
   @Test(dependsOnMethods = "testDepartGetUsers")
   public void testUserDelete() throws WxErrorException {
-    wxCpService.userDelete("some.woman");
+    this.wxCpService.userDelete("some.woman");
   }
 }
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxMenuAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxMenuAPITest.java
index 8fe136b9..c837e51e 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxMenuAPITest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxMenuAPITest.java
@@ -24,17 +24,17 @@ public class WxMenuAPITest {
 
   @Test(dataProvider = "menu")
   public void testCreateMenu(WxMenu wxMenu) throws WxErrorException {
-    wxService.menuCreate(wxMenu);
+    this.wxService.menuCreate(wxMenu);
   }
 
   @Test(dependsOnMethods = {"testCreateMenu"})
   public void testGetMenu() throws WxErrorException {
-    Assert.assertNotNull(wxService.menuGet());
+    Assert.assertNotNull(this.wxService.menuGet());
   }
 
   @Test(dependsOnMethods = {"testGetMenu"})
   public void testDeleteMenu() throws WxErrorException {
-    wxService.menuDelete();
+    this.wxService.menuDelete();
   }
 
   @DataProvider(name = "menu")
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoInMemoryConfigStorage.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoInMemoryConfigStorage.java
index f883e311..9a97b6cd 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoInMemoryConfigStorage.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoInMemoryConfigStorage.java
@@ -21,8 +21,8 @@ class WxCpDemoInMemoryConfigStorage extends WxCpInMemoryConfigStorage {
 
   @Override
   public String toString() {
-    return "SimpleWxConfigProvider [appidOrCorpid=" + corpId + ", corpSecret=" + corpSecret + ", accessToken=" + accessToken
-            + ", expiresTime=" + expiresTime + ", token=" + token + ", aesKey=" + aesKey + "]";
+    return "SimpleWxConfigProvider [appidOrCorpid=" + this.corpId + ", corpSecret=" + this.corpSecret + ", accessToken=" + this.accessToken
+            + ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]";
   }
 
 }
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java
index 67738d2b..56683150 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java
@@ -43,12 +43,12 @@ public class WxCpEndpointServlet extends HttpServlet {
     String echostr = request.getParameter("echostr");
 
     if (StringUtils.isNotBlank(echostr)) {
-      if (!wxCpService.checkSignature(msgSignature, timestamp, nonce, echostr)) {
+      if (!this.wxCpService.checkSignature(msgSignature, timestamp, nonce, echostr)) {
         // 消息签名不正确,说明不是公众平台发过来的消息
         response.getWriter().println("非法请求");
         return;
       }
-      WxCpCryptUtil cryptUtil = new WxCpCryptUtil(wxCpConfigStorage);
+      WxCpCryptUtil cryptUtil = new WxCpCryptUtil(this.wxCpConfigStorage);
       String plainText = cryptUtil.decrypt(echostr);
       // 说明是一个仅仅用来验证的请求,回显echostr
       response.getWriter().println(plainText);
@@ -56,10 +56,10 @@ public class WxCpEndpointServlet extends HttpServlet {
     }
 
     WxCpXmlMessage inMessage = WxCpXmlMessage
-            .fromEncryptedXml(request.getInputStream(), wxCpConfigStorage, timestamp, nonce, msgSignature);
-    WxCpXmlOutMessage outMessage = wxCpMessageRouter.route(inMessage);
+            .fromEncryptedXml(request.getInputStream(), this.wxCpConfigStorage, timestamp, nonce, msgSignature);
+    WxCpXmlOutMessage outMessage = this.wxCpMessageRouter.route(inMessage);
     if (outMessage != null) {
-      response.getWriter().write(outMessage.toEncryptedXml(wxCpConfigStorage));
+      response.getWriter().write(outMessage.toEncryptedXml(this.wxCpConfigStorage));
     }
 
     return;
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java
index 80dc565d..01893e99 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java
@@ -30,7 +30,7 @@ public class WxCpOAuth2Servlet extends HttpServlet {
       response.getWriter().println("

code

"); response.getWriter().println(code); - String[] res = wxCpService.oauth2getUserInfo(code); + String[] res = this.wxCpService.oauth2getUserInfo(code); response.getWriter().println("

result

"); response.getWriter().println(Arrays.toString(res)); } catch (WxErrorException e) { From 69df599afe8828fc6719ac147caba9456daacfba Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Thu, 8 Sep 2016 15:46:22 +0800 Subject: [PATCH 25/49] fix warnings --- .../chanjar/weixin/cp/api/ApiTestModule.java | 25 ++-- .../weixin/cp/api/WxCpBusyRetryTest.java | 17 +-- .../weixin/cp/api/WxCpDepartAPITest.java | 21 ++-- .../weixin/cp/api/WxCpMediaAPITest.java | 42 ++++--- .../weixin/cp/demo/WxCpDemoServer.java | 113 +++++++++--------- .../weixin/cp/demo/WxCpEndpointServlet.java | 16 +-- .../weixin/cp/demo/WxCpOAuth2Servlet.java | 13 +- 7 files changed, 133 insertions(+), 114 deletions(-) diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java index 179e8a08..2a694ff3 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java @@ -1,12 +1,14 @@ package me.chanjar.weixin.cp.api; +import java.io.IOException; +import java.io.InputStream; + import com.google.inject.Binder; import com.google.inject.Module; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; -import me.chanjar.weixin.common.util.xml.XStreamInitializer; -import java.io.InputStream; +import me.chanjar.weixin.common.util.xml.XStreamInitializer; public class ApiTestModule implements Module { @@ -19,13 +21,18 @@ public class ApiTestModule implements Module { @Override public void configure(Binder binder) { - InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml"); - WxXmlCpInMemoryConfigStorage config = fromXml(WxXmlCpInMemoryConfigStorage.class, is1); - WxCpServiceImpl wxService = new WxCpServiceImpl(); - wxService.setWxCpConfigStorage(config); - - binder.bind(WxCpServiceImpl.class).toInstance(wxService); - binder.bind(WxCpConfigStorage.class).toInstance(config); + try (InputStream is1 = ClassLoader + .getSystemResourceAsStream("test-config.xml")) { + WxXmlCpInMemoryConfigStorage config = fromXml( + WxXmlCpInMemoryConfigStorage.class, is1); + WxCpServiceImpl wxService = new WxCpServiceImpl(); + wxService.setWxCpConfigStorage(config); + + binder.bind(WxCpServiceImpl.class).toInstance(wxService); + binder.bind(WxCpConfigStorage.class).toInstance(config); + } catch (IOException e) { + e.printStackTrace(); + } } @XStreamAlias("xml") diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java index 989a69e6..b3f96b1b 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java @@ -1,16 +1,17 @@ package me.chanjar.weixin.cp.api; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.http.RequestExecutor; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.http.RequestExecutor; + @Test public class WxCpBusyRetryTest { @@ -19,7 +20,9 @@ public class WxCpBusyRetryTest { WxCpService service = new WxCpServiceImpl() { @Override - protected T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { + protected synchronized T executeInternal( + RequestExecutor executor, String uri, E data) + throws WxErrorException { WxError error = new WxError(); error.setErrorCode(-1); throw new WxErrorException(error); diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java index fb52eac0..c0cc3251 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java @@ -1,13 +1,15 @@ package me.chanjar.weixin.cp.api; -import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.cp.bean.WxCpDepart; +import java.util.List; + import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import java.util.List; +import com.google.inject.Inject; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.cp.bean.WxCpDepart; /** * 测试部门接口 @@ -24,11 +26,12 @@ public class WxCpDepartAPITest { protected WxCpDepart depart; public void testDepartCreate() throws WxErrorException { - WxCpDepart depart = new WxCpDepart(); - depart.setName("子部门" + System.currentTimeMillis()); - depart.setParentId(1); - depart.setOrder(1); - Integer departId = this.wxCpService.departCreate(depart); + WxCpDepart cpDepart = new WxCpDepart(); + cpDepart.setName("子部门" + System.currentTimeMillis()); + cpDepart.setParentId(1); + cpDepart.setOrder(1); + Integer departId = this.wxCpService.departCreate(cpDepart); + System.out.println(departId); } @Test(dependsOnMethods = "testDepartCreate") diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java index 97ac9186..fe379226 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java @@ -1,18 +1,20 @@ package me.chanjar.weixin.cp.api; -import com.google.inject.Inject; -import me.chanjar.weixin.common.api.WxConsts; -import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.common.exception.WxErrorException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; +import com.google.inject.Inject; + +import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; +import me.chanjar.weixin.common.exception.WxErrorException; /** * 测试多媒体文件上传下载 @@ -31,17 +33,21 @@ public class WxCpMediaAPITest { @Test(dataProvider = "uploadMedia") public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { - InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName); - WxMediaUploadResult res = this.wxService.mediaUpload(mediaType, fileType, inputStream); - Assert.assertNotNull(res.getType()); - Assert.assertNotNull(res.getCreatedAt()); - Assert.assertTrue(res.getMediaId() != null || res.getThumbMediaId() != null); + try (InputStream inputStream = ClassLoader + .getSystemResourceAsStream(fileName);) { + WxMediaUploadResult res = this.wxService.mediaUpload(mediaType, fileType, + inputStream); + Assert.assertNotNull(res.getType()); + Assert.assertNotNull(res.getCreatedAt()); + Assert.assertTrue( + res.getMediaId() != null || res.getThumbMediaId() != null); - if (res.getMediaId() != null) { - this.media_ids.add(res.getMediaId()); - } - if (res.getThumbMediaId() != null) { - this.media_ids.add(res.getThumbMediaId()); + if (res.getMediaId() != null) { + this.media_ids.add(res.getMediaId()); + } + if (res.getThumbMediaId() != null) { + this.media_ids.add(res.getThumbMediaId()); + } } } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java index 10af3c57..dc667d88 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java @@ -1,16 +1,22 @@ package me.chanjar.weixin.cp.demo; -import me.chanjar.weixin.common.session.WxSessionManager; -import me.chanjar.weixin.cp.api.*; -import me.chanjar.weixin.cp.bean.WxCpXmlMessage; -import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; -import me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; -import java.io.InputStream; -import java.util.Map; +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.cp.api.WxCpConfigStorage; +import me.chanjar.weixin.cp.api.WxCpMessageHandler; +import me.chanjar.weixin.cp.api.WxCpMessageRouter; +import me.chanjar.weixin.cp.api.WxCpService; +import me.chanjar.weixin.cp.api.WxCpServiceImpl; +import me.chanjar.weixin.cp.bean.WxCpXmlMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage; public class WxCpDemoServer { @@ -36,55 +42,48 @@ public class WxCpDemoServer { server.join(); } - private static void initWeixin() { - InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml"); - WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(is1); - - wxCpConfigStorage = config; - wxCpService = new WxCpServiceImpl(); - wxCpService.setWxCpConfigStorage(config); - - WxCpMessageHandler handler = new WxCpMessageHandler() { - @Override - public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map context, - WxCpService wxCpService, WxSessionManager sessionManager) { - WxCpXmlOutTextMessage m = WxCpXmlOutMessage - .TEXT() - .content("测试加密消息") - .fromUser(wxMessage.getToUserName()) - .toUser(wxMessage.getFromUserName()) - .build(); - return m; - } - }; - - WxCpMessageHandler oauth2handler = new WxCpMessageHandler() { - @Override - public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map context, - WxCpService wxCpService, WxSessionManager sessionManager) { - String href = "测试oauth2"; - return WxCpXmlOutMessage - .TEXT() - .content(href) - .fromUser(wxMessage.getToUserName()) - .toUser(wxMessage.getFromUserName()).build(); - } - }; - - wxCpMessageRouter = new WxCpMessageRouter(wxCpService); - wxCpMessageRouter - .rule() - .async(false) - .content("哈哈") // 拦截内容为“哈哈”的消息 - .handler(handler) - .end() - .rule() - .async(false) - .content("oauth") - .handler(oauth2handler) - .end() - ; - + private static void initWeixin() throws IOException { + try (InputStream is1 = ClassLoader + .getSystemResourceAsStream("test-config.xml")) { + WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage + .fromXml(is1); + + wxCpConfigStorage = config; + wxCpService = new WxCpServiceImpl(); + wxCpService.setWxCpConfigStorage(config); + + WxCpMessageHandler handler = new WxCpMessageHandler() { + @Override + public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, + Map context, WxCpService wxService, + WxSessionManager sessionManager) { + WxCpXmlOutTextMessage m = WxCpXmlOutMessage.TEXT().content("测试加密消息") + .fromUser(wxMessage.getToUserName()) + .toUser(wxMessage.getFromUserName()).build(); + return m; + } + }; + + WxCpMessageHandler oauth2handler = new WxCpMessageHandler() { + @Override + public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, + Map context, WxCpService wxService, + WxSessionManager sessionManager) { + String href = "测试oauth2"; + return WxCpXmlOutMessage.TEXT().content(href) + .fromUser(wxMessage.getToUserName()) + .toUser(wxMessage.getFromUserName()).build(); + } + }; + + wxCpMessageRouter = new WxCpMessageRouter(wxCpService); + wxCpMessageRouter.rule().async(false).content("哈哈") // 拦截内容为“哈哈”的消息 + .handler(handler).end().rule().async(false).content("oauth") + .handler(oauth2handler).end(); + + } } } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java index 56683150..d59eb3f3 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java @@ -1,5 +1,11 @@ package me.chanjar.weixin.cp.demo; +import java.io.IOException; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import me.chanjar.weixin.common.util.StringUtils; import me.chanjar.weixin.cp.api.WxCpConfigStorage; import me.chanjar.weixin.cp.api.WxCpMessageRouter; @@ -8,17 +14,11 @@ import me.chanjar.weixin.cp.bean.WxCpXmlMessage; import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - /** * @author Daniel Qian */ public class WxCpEndpointServlet extends HttpServlet { - + private static final long serialVersionUID = 1L; protected WxCpConfigStorage wxCpConfigStorage; protected WxCpService wxCpService; protected WxCpMessageRouter wxCpMessageRouter; @@ -32,7 +32,7 @@ public class WxCpEndpointServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + throws IOException { response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java index 01893e99..edab8966 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java @@ -1,16 +1,17 @@ package me.chanjar.weixin.cp.demo; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.cp.api.WxCpService; +import java.io.IOException; +import java.util.Arrays; -import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.Arrays; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.cp.api.WxCpService; public class WxCpOAuth2Servlet extends HttpServlet { + private static final long serialVersionUID = 1L; protected WxCpService wxCpService; @@ -20,7 +21,7 @@ public class WxCpOAuth2Servlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + throws IOException { response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); From 775f058b227c199ccb408647e101024f5ebe833d Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Thu, 8 Sep 2016 15:47:44 +0800 Subject: [PATCH 26/49] fix warnings --- .../weixin/cp/api/WxCpMessageRouter.java | 22 +-- .../weixin/cp/api/WxCpMessageRouterRule.java | 4 +- .../me/chanjar/weixin/cp/bean/WxCpDepart.java | 16 +- .../chanjar/weixin/cp/bean/WxCpMessage.java | 36 ++-- .../me/chanjar/weixin/cp/bean/WxCpTag.java | 4 +- .../me/chanjar/weixin/cp/bean/WxCpUser.java | 30 ++-- .../weixin/cp/bean/WxCpXmlMessage.java | 154 +++++++++--------- .../cp/bean/WxCpXmlOutImageMessage.java | 2 +- .../weixin/cp/bean/WxCpXmlOutMessage.java | 8 +- .../weixin/cp/bean/WxCpXmlOutNewsMessage.java | 20 +-- .../weixin/cp/bean/WxCpXmlOutTextMessage.java | 2 +- .../cp/bean/WxCpXmlOutVideoMessage.java | 18 +- .../cp/bean/WxCpXmlOutVoiceMessage.java | 2 +- .../cp/bean/messagebuilder/VideoBuilder.java | 6 +- .../cp/bean/outxmlbuilder/NewsBuilder.java | 2 +- .../cp/bean/outxmlbuilder/VideoBuilder.java | 6 +- .../cp/bean/outxmlbuilder/VoiceBuilder.java | 2 +- 17 files changed, 167 insertions(+), 167 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java index bdda1886..ece62e58 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java @@ -144,7 +144,7 @@ public class WxCpMessageRouter { final List matchRules = new ArrayList(); // 收集匹配的规则 - for (final WxCpMessageRouterRule rule : rules) { + for (final WxCpMessageRouterRule rule : this.rules) { if (rule.test(wxMessage)) { matchRules.add(rule); if (!rule.isReEnter()) { @@ -163,34 +163,34 @@ public class WxCpMessageRouter { // 返回最后一个非异步的rule的执行结果 if (rule.isAsync()) { futures.add( - executorService.submit(new Runnable() { + this.executorService.submit(new Runnable() { public void run() { - rule.service(wxMessage, wxCpService, sessionManager, exceptionHandler); + rule.service(wxMessage, WxCpMessageRouter.this.wxCpService, WxCpMessageRouter.this.sessionManager, WxCpMessageRouter.this.exceptionHandler); } }) ); } else { - res = rule.service(wxMessage, wxCpService, sessionManager, exceptionHandler); + res = rule.service(wxMessage, this.wxCpService, this.sessionManager, this.exceptionHandler); // 在同步操作结束,session访问结束 - log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUserName()); + this.log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUserName()); sessionEndAccess(wxMessage); } } if (futures.size() > 0) { - executorService.submit(new Runnable() { + this.executorService.submit(new Runnable() { @Override public void run() { for (Future future : futures) { try { future.get(); - log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUserName()); + WxCpMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUserName()); // 异步操作结束,session访问结束 sessionEndAccess(wxMessage); } catch (InterruptedException e) { - log.error("Error happened when wait task finish", e); + WxCpMessageRouter.this.log.error("Error happened when wait task finish", e); } catch (ExecutionException e) { - log.error("Error happened when wait task finish", e); + WxCpMessageRouter.this.log.error("Error happened when wait task finish", e); } } } @@ -213,7 +213,7 @@ public class WxCpMessageRouter { messageId = String.valueOf(wxMessage.getMsgId()); } - return messageDuplicateChecker.isDuplicate(messageId); + return this.messageDuplicateChecker.isDuplicate(messageId); } @@ -224,7 +224,7 @@ public class WxCpMessageRouter { */ protected void sessionEndAccess(WxCpXmlMessage wxMessage) { - InternalSession session = ((InternalSessionManager) sessionManager).findSession(wxMessage.getFromUserName()); + InternalSession session = ((InternalSessionManager) this.sessionManager).findSession(wxMessage.getFromUserName()); if (session != null) { session.endAccess(); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java index a987841c..9014bde9 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java @@ -300,7 +300,7 @@ public class WxCpMessageRouterRule { } public boolean isAsync() { - return async; + return this.async; } public void setAsync(boolean async) { @@ -308,7 +308,7 @@ public class WxCpMessageRouterRule { } public boolean isReEnter() { - return reEnter; + return this.reEnter; } public void setReEnter(boolean reEnter) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java index e2bfbd39..540501d7 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java @@ -21,7 +21,7 @@ public class WxCpDepart implements Serializable { } public Integer getId() { - return id; + return this.id; } public void setId(Integer id) { @@ -29,7 +29,7 @@ public class WxCpDepart implements Serializable { } public String getName() { - return name; + return this.name; } public void setName(String name) { @@ -37,7 +37,7 @@ public class WxCpDepart implements Serializable { } public Integer getParentId() { - return parentId; + return this.parentId; } public void setParentId(Integer parentId) { @@ -45,7 +45,7 @@ public class WxCpDepart implements Serializable { } public Integer getOrder() { - return order; + return this.order; } public void setOrder(Integer order) { @@ -59,10 +59,10 @@ public class WxCpDepart implements Serializable { @Override public String toString() { return "WxCpDepart{" + - "id=" + id + - ", name='" + name + '\'' + - ", parentId=" + parentId + - ", order=" + order + + "id=" + this.id + + ", name='" + this.name + '\'' + + ", parentId=" + this.parentId + + ", order=" + this.order + '}'; } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java index 89611525..0b5f926e 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java @@ -72,7 +72,7 @@ public class WxCpMessage implements Serializable { } public String getToUser() { - return toUser; + return this.toUser; } public void setToUser(String toUser) { @@ -80,7 +80,7 @@ public class WxCpMessage implements Serializable { } public String getToParty() { - return toParty; + return this.toParty; } public void setToParty(String toParty) { @@ -88,7 +88,7 @@ public class WxCpMessage implements Serializable { } public String getToTag() { - return toTag; + return this.toTag; } public void setToTag(String toTag) { @@ -96,7 +96,7 @@ public class WxCpMessage implements Serializable { } public String getAgentId() { - return agentId; + return this.agentId; } public void setAgentId(String agentId) { @@ -104,7 +104,7 @@ public class WxCpMessage implements Serializable { } public String getMsgType() { - return msgType; + return this.msgType; } /** @@ -125,7 +125,7 @@ public class WxCpMessage implements Serializable { } public String getSafe() { - return safe; + return this.safe; } public void setSafe(String safe) { @@ -133,7 +133,7 @@ public class WxCpMessage implements Serializable { } public String getContent() { - return content; + return this.content; } public void setContent(String content) { @@ -141,7 +141,7 @@ public class WxCpMessage implements Serializable { } public String getMediaId() { - return mediaId; + return this.mediaId; } public void setMediaId(String mediaId) { @@ -149,7 +149,7 @@ public class WxCpMessage implements Serializable { } public String getThumbMediaId() { - return thumbMediaId; + return this.thumbMediaId; } public void setThumbMediaId(String thumbMediaId) { @@ -157,7 +157,7 @@ public class WxCpMessage implements Serializable { } public String getTitle() { - return title; + return this.title; } public void setTitle(String title) { @@ -165,7 +165,7 @@ public class WxCpMessage implements Serializable { } public String getDescription() { - return description; + return this.description; } public void setDescription(String description) { @@ -173,7 +173,7 @@ public class WxCpMessage implements Serializable { } public String getMusicUrl() { - return musicUrl; + return this.musicUrl; } public void setMusicUrl(String musicUrl) { @@ -181,7 +181,7 @@ public class WxCpMessage implements Serializable { } public String getHqMusicUrl() { - return hqMusicUrl; + return this.hqMusicUrl; } public void setHqMusicUrl(String hqMusicUrl) { @@ -189,7 +189,7 @@ public class WxCpMessage implements Serializable { } public List getArticles() { - return articles; + return this.articles; } public void setArticles(List articles) { @@ -208,7 +208,7 @@ public class WxCpMessage implements Serializable { private String picUrl; public String getTitle() { - return title; + return this.title; } public void setTitle(String title) { @@ -216,7 +216,7 @@ public class WxCpMessage implements Serializable { } public String getDescription() { - return description; + return this.description; } public void setDescription(String description) { @@ -224,7 +224,7 @@ public class WxCpMessage implements Serializable { } public String getUrl() { - return url; + return this.url; } public void setUrl(String url) { @@ -232,7 +232,7 @@ public class WxCpMessage implements Serializable { } public String getPicUrl() { - return picUrl; + return this.picUrl; } public void setPicUrl(String picUrl) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java index 72fd6628..07c934b3 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java @@ -28,7 +28,7 @@ public class WxCpTag implements Serializable { } public String getName() { - return name; + return this.name; } public void setName(String name) { @@ -36,7 +36,7 @@ public class WxCpTag implements Serializable { } public String getId() { - return id; + return this.id; } public void setId(String id) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java index e96206eb..1c0cd7f1 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java @@ -32,7 +32,7 @@ public class WxCpUser implements Serializable { } public String getUserId() { - return userId; + return this.userId; } public void setUserId(String userId) { @@ -40,7 +40,7 @@ public class WxCpUser implements Serializable { } public String getName() { - return name; + return this.name; } public void setName(String name) { @@ -48,7 +48,7 @@ public class WxCpUser implements Serializable { } public Integer[] getDepartIds() { - return departIds; + return this.departIds; } public void setDepartIds(Integer[] departIds) { @@ -56,7 +56,7 @@ public class WxCpUser implements Serializable { } public String getGender() { - return gender; + return this.gender; } public void setGender(String gender) { @@ -64,7 +64,7 @@ public class WxCpUser implements Serializable { } public String getPosition() { - return position; + return this.position; } public void setPosition(String position) { @@ -72,7 +72,7 @@ public class WxCpUser implements Serializable { } public String getMobile() { - return mobile; + return this.mobile; } public void setMobile(String mobile) { @@ -80,7 +80,7 @@ public class WxCpUser implements Serializable { } public String getTel() { - return tel; + return this.tel; } public void setTel(String tel) { @@ -88,7 +88,7 @@ public class WxCpUser implements Serializable { } public String getEmail() { - return email; + return this.email; } public void setEmail(String email) { @@ -96,7 +96,7 @@ public class WxCpUser implements Serializable { } public String getWeiXinId() { - return weiXinId; + return this.weiXinId; } public void setWeiXinId(String weiXinId) { @@ -104,7 +104,7 @@ public class WxCpUser implements Serializable { } public String getAvatar() { - return avatar; + return this.avatar; } public void setAvatar(String avatar) { @@ -112,7 +112,7 @@ public class WxCpUser implements Serializable { } public Integer getStatus() { - return status; + return this.status; } public void setStatus(Integer status) { @@ -120,7 +120,7 @@ public class WxCpUser implements Serializable { } public Integer getEnable() { - return enable; + return this.enable; } public void setEnable(Integer enable) { @@ -132,7 +132,7 @@ public class WxCpUser implements Serializable { } public List getExtAttrs() { - return extAttrs; + return this.extAttrs; } public String toJson() { @@ -150,7 +150,7 @@ public class WxCpUser implements Serializable { } public String getName() { - return name; + return this.name; } public void setName(String name) { @@ -158,7 +158,7 @@ public class WxCpUser implements Serializable { } public String getValue() { - return value; + return this.value; } public void setValue(String value) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java index 0b833e06..80cf7d47 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java @@ -200,7 +200,7 @@ public class WxCpXmlMessage implements Serializable { } public Integer getAgentId() { - return agentId; + return this.agentId; } public void setAgentId(Integer agentId) { @@ -208,7 +208,7 @@ public class WxCpXmlMessage implements Serializable { } public String getToUserName() { - return toUserName; + return this.toUserName; } public void setToUserName(String toUserName) { @@ -216,7 +216,7 @@ public class WxCpXmlMessage implements Serializable { } public Long getCreateTime() { - return createTime; + return this.createTime; } public void setCreateTime(Long createTime) { @@ -236,7 +236,7 @@ public class WxCpXmlMessage implements Serializable { *
*/ public String getMsgType() { - return msgType; + return this.msgType; } /** @@ -256,7 +256,7 @@ public class WxCpXmlMessage implements Serializable { } public String getContent() { - return content; + return this.content; } public void setContent(String content) { @@ -264,7 +264,7 @@ public class WxCpXmlMessage implements Serializable { } public Long getMsgId() { - return msgId; + return this.msgId; } public void setMsgId(Long msgId) { @@ -272,7 +272,7 @@ public class WxCpXmlMessage implements Serializable { } public String getPicUrl() { - return picUrl; + return this.picUrl; } public void setPicUrl(String picUrl) { @@ -280,7 +280,7 @@ public class WxCpXmlMessage implements Serializable { } public String getMediaId() { - return mediaId; + return this.mediaId; } public void setMediaId(String mediaId) { @@ -288,7 +288,7 @@ public class WxCpXmlMessage implements Serializable { } public String getFormat() { - return format; + return this.format; } public void setFormat(String format) { @@ -296,7 +296,7 @@ public class WxCpXmlMessage implements Serializable { } public String getThumbMediaId() { - return thumbMediaId; + return this.thumbMediaId; } public void setThumbMediaId(String thumbMediaId) { @@ -304,7 +304,7 @@ public class WxCpXmlMessage implements Serializable { } public Double getLocationX() { - return locationX; + return this.locationX; } public void setLocationX(Double locationX) { @@ -312,7 +312,7 @@ public class WxCpXmlMessage implements Serializable { } public Double getLocationY() { - return locationY; + return this.locationY; } public void setLocationY(Double locationY) { @@ -320,7 +320,7 @@ public class WxCpXmlMessage implements Serializable { } public Double getScale() { - return scale; + return this.scale; } public void setScale(Double scale) { @@ -328,7 +328,7 @@ public class WxCpXmlMessage implements Serializable { } public String getLabel() { - return label; + return this.label; } public void setLabel(String label) { @@ -336,7 +336,7 @@ public class WxCpXmlMessage implements Serializable { } public String getTitle() { - return title; + return this.title; } public void setTitle(String title) { @@ -344,7 +344,7 @@ public class WxCpXmlMessage implements Serializable { } public String getDescription() { - return description; + return this.description; } public void setDescription(String description) { @@ -352,7 +352,7 @@ public class WxCpXmlMessage implements Serializable { } public String getUrl() { - return url; + return this.url; } public void setUrl(String url) { @@ -360,7 +360,7 @@ public class WxCpXmlMessage implements Serializable { } public String getEvent() { - return event; + return this.event; } public void setEvent(String event) { @@ -368,7 +368,7 @@ public class WxCpXmlMessage implements Serializable { } public String getEventKey() { - return eventKey; + return this.eventKey; } public void setEventKey(String eventKey) { @@ -376,7 +376,7 @@ public class WxCpXmlMessage implements Serializable { } public String getTicket() { - return ticket; + return this.ticket; } public void setTicket(String ticket) { @@ -384,7 +384,7 @@ public class WxCpXmlMessage implements Serializable { } public Double getLatitude() { - return latitude; + return this.latitude; } public void setLatitude(Double latitude) { @@ -392,7 +392,7 @@ public class WxCpXmlMessage implements Serializable { } public Double getLongitude() { - return longitude; + return this.longitude; } public void setLongitude(Double longitude) { @@ -400,7 +400,7 @@ public class WxCpXmlMessage implements Serializable { } public Double getPrecision() { - return precision; + return this.precision; } public void setPrecision(Double precision) { @@ -408,7 +408,7 @@ public class WxCpXmlMessage implements Serializable { } public String getRecognition() { - return recognition; + return this.recognition; } public void setRecognition(String recognition) { @@ -416,7 +416,7 @@ public class WxCpXmlMessage implements Serializable { } public String getFromUserName() { - return fromUserName; + return this.fromUserName; } public void setFromUserName(String fromUserName) { @@ -424,7 +424,7 @@ public class WxCpXmlMessage implements Serializable { } public String getStatus() { - return status; + return this.status; } public void setStatus(String status) { @@ -432,7 +432,7 @@ public class WxCpXmlMessage implements Serializable { } public Integer getTotalCount() { - return totalCount; + return this.totalCount; } public void setTotalCount(Integer totalCount) { @@ -440,7 +440,7 @@ public class WxCpXmlMessage implements Serializable { } public Integer getFilterCount() { - return filterCount; + return this.filterCount; } public void setFilterCount(Integer filterCount) { @@ -448,7 +448,7 @@ public class WxCpXmlMessage implements Serializable { } public Integer getSentCount() { - return sentCount; + return this.sentCount; } public void setSentCount(Integer sentCount) { @@ -456,7 +456,7 @@ public class WxCpXmlMessage implements Serializable { } public Integer getErrorCount() { - return errorCount; + return this.errorCount; } public void setErrorCount(Integer errorCount) { @@ -464,7 +464,7 @@ public class WxCpXmlMessage implements Serializable { } public WxCpXmlMessage.ScanCodeInfo getScanCodeInfo() { - return scanCodeInfo; + return this.scanCodeInfo; } public void setScanCodeInfo(WxCpXmlMessage.ScanCodeInfo scanCodeInfo) { @@ -472,7 +472,7 @@ public class WxCpXmlMessage implements Serializable { } public WxCpXmlMessage.SendPicsInfo getSendPicsInfo() { - return sendPicsInfo; + return this.sendPicsInfo; } public void setSendPicsInfo(WxCpXmlMessage.SendPicsInfo sendPicsInfo) { @@ -480,7 +480,7 @@ public class WxCpXmlMessage implements Serializable { } public WxCpXmlMessage.SendLocationInfo getSendLocationInfo() { - return sendLocationInfo; + return this.sendLocationInfo; } public void setSendLocationInfo(WxCpXmlMessage.SendLocationInfo sendLocationInfo) { @@ -490,39 +490,39 @@ public class WxCpXmlMessage implements Serializable { @Override public String toString() { return "WxCpXmlMessage{" + - "agentId=" + agentId + - ", toUserName='" + toUserName + '\'' + - ", fromUserName='" + fromUserName + '\'' + - ", createTime=" + createTime + - ", msgType='" + msgType + '\'' + - ", content='" + content + '\'' + - ", msgId=" + msgId + - ", picUrl='" + picUrl + '\'' + - ", mediaId='" + mediaId + '\'' + - ", format='" + format + '\'' + - ", thumbMediaId='" + thumbMediaId + '\'' + - ", locationX=" + locationX + - ", locationY=" + locationY + - ", scale=" + scale + - ", label='" + label + '\'' + - ", title='" + title + '\'' + - ", description='" + description + '\'' + - ", url='" + url + '\'' + - ", event='" + event + '\'' + - ", eventKey='" + eventKey + '\'' + - ", ticket='" + ticket + '\'' + - ", latitude=" + latitude + - ", longitude=" + longitude + - ", precision=" + precision + - ", recognition='" + recognition + '\'' + - ", status='" + status + '\'' + - ", totalCount=" + totalCount + - ", filterCount=" + filterCount + - ", sentCount=" + sentCount + - ", errorCount=" + errorCount + - ", scanCodeInfo=" + scanCodeInfo + - ", sendPicsInfo=" + sendPicsInfo + - ", sendLocationInfo=" + sendLocationInfo + + "agentId=" + this.agentId + + ", toUserName='" + this.toUserName + '\'' + + ", fromUserName='" + this.fromUserName + '\'' + + ", createTime=" + this.createTime + + ", msgType='" + this.msgType + '\'' + + ", content='" + this.content + '\'' + + ", msgId=" + this.msgId + + ", picUrl='" + this.picUrl + '\'' + + ", mediaId='" + this.mediaId + '\'' + + ", format='" + this.format + '\'' + + ", thumbMediaId='" + this.thumbMediaId + '\'' + + ", locationX=" + this.locationX + + ", locationY=" + this.locationY + + ", scale=" + this.scale + + ", label='" + this.label + '\'' + + ", title='" + this.title + '\'' + + ", description='" + this.description + '\'' + + ", url='" + this.url + '\'' + + ", event='" + this.event + '\'' + + ", eventKey='" + this.eventKey + '\'' + + ", ticket='" + this.ticket + '\'' + + ", latitude=" + this.latitude + + ", longitude=" + this.longitude + + ", precision=" + this.precision + + ", recognition='" + this.recognition + '\'' + + ", status='" + this.status + '\'' + + ", totalCount=" + this.totalCount + + ", filterCount=" + this.filterCount + + ", sentCount=" + this.sentCount + + ", errorCount=" + this.errorCount + + ", scanCodeInfo=" + this.scanCodeInfo + + ", sendPicsInfo=" + this.sendPicsInfo + + ", sendLocationInfo=" + this.sendLocationInfo + '}'; } @@ -542,7 +542,7 @@ public class WxCpXmlMessage implements Serializable { */ public String getScanType() { - return scanType; + return this.scanType; } public void setScanType(String scanType) { @@ -553,7 +553,7 @@ public class WxCpXmlMessage implements Serializable { * 扫描结果,即二维码对应的字符串信息 */ public String getScanResult() { - return scanResult; + return this.scanResult; } public void setScanResult(String scanResult) { @@ -571,7 +571,7 @@ public class WxCpXmlMessage implements Serializable { private Long count; public Long getCount() { - return count; + return this.count; } public void setCount(Long count) { @@ -579,7 +579,7 @@ public class WxCpXmlMessage implements Serializable { } public List getPicList() { - return picList; + return this.picList; } @XStreamAlias("item") @@ -590,11 +590,11 @@ public class WxCpXmlMessage implements Serializable { private String PicMd5Sum; public String getPicMd5Sum() { - return PicMd5Sum; + return this.PicMd5Sum; } public void setPicMd5Sum(String picMd5Sum) { - PicMd5Sum = picMd5Sum; + this.PicMd5Sum = picMd5Sum; } } } @@ -623,7 +623,7 @@ public class WxCpXmlMessage implements Serializable { private String poiname; public String getLocationX() { - return locationX; + return this.locationX; } public void setLocationX(String locationX) { @@ -631,7 +631,7 @@ public class WxCpXmlMessage implements Serializable { } public String getLocationY() { - return locationY; + return this.locationY; } public void setLocationY(String locationY) { @@ -639,7 +639,7 @@ public class WxCpXmlMessage implements Serializable { } public String getScale() { - return scale; + return this.scale; } public void setScale(String scale) { @@ -647,7 +647,7 @@ public class WxCpXmlMessage implements Serializable { } public String getLabel() { - return label; + return this.label; } public void setLabel(String label) { @@ -655,7 +655,7 @@ public class WxCpXmlMessage implements Serializable { } public String getPoiname() { - return poiname; + return this.poiname; } public void setPoiname(String poiname) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java index 1bf4a33f..44de8811 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java @@ -17,7 +17,7 @@ public class WxCpXmlOutImageMessage extends WxCpXmlOutMessage { } public String getMediaId() { - return mediaId; + return this.mediaId; } public void setMediaId(String mediaId) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java index 257778bf..332b5e24 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java @@ -62,7 +62,7 @@ public abstract class WxCpXmlOutMessage { } public String getToUserName() { - return toUserName; + return this.toUserName; } public void setToUserName(String toUserName) { @@ -70,7 +70,7 @@ public abstract class WxCpXmlOutMessage { } public String getFromUserName() { - return fromUserName; + return this.fromUserName; } public void setFromUserName(String fromUserName) { @@ -78,7 +78,7 @@ public abstract class WxCpXmlOutMessage { } public Long getCreateTime() { - return createTime; + return this.createTime; } public void setCreateTime(Long createTime) { @@ -86,7 +86,7 @@ public abstract class WxCpXmlOutMessage { } public String getMsgType() { - return msgType; + return this.msgType; } public void setMsgType(String msgType) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java index 3b7ae3af..b689ce6f 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java @@ -21,7 +21,7 @@ public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage { } public int getArticleCount() { - return articleCount; + return this.articleCount; } public void addArticle(Item item) { @@ -30,7 +30,7 @@ public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage { } public List getArticles() { - return articles; + return this.articles; } @@ -54,35 +54,35 @@ public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage { private String Url; public String getTitle() { - return Title; + return this.Title; } public void setTitle(String title) { - Title = title; + this.Title = title; } public String getDescription() { - return Description; + return this.Description; } public void setDescription(String description) { - Description = description; + this.Description = description; } public String getPicUrl() { - return PicUrl; + return this.PicUrl; } public void setPicUrl(String picUrl) { - PicUrl = picUrl; + this.PicUrl = picUrl; } public String getUrl() { - return Url; + return this.Url; } public void setUrl(String url) { - Url = url; + this.Url = url; } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java index e9dd7183..3c59edf9 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java @@ -17,7 +17,7 @@ public class WxCpXmlOutTextMessage extends WxCpXmlOutMessage { } public String getContent() { - return content; + return this.content; } public void setContent(String content) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java index b5e15801..6e2f268f 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java @@ -16,27 +16,27 @@ public class WxCpXmlOutVideoMessage extends WxCpXmlOutMessage { } public String getMediaId() { - return video.getMediaId(); + return this.video.getMediaId(); } public void setMediaId(String mediaId) { - video.setMediaId(mediaId); + this.video.setMediaId(mediaId); } public String getTitle() { - return video.getTitle(); + return this.video.getTitle(); } public void setTitle(String title) { - video.setTitle(title); + this.video.setTitle(title); } public String getDescription() { - return video.getDescription(); + return this.video.getDescription(); } public void setDescription(String description) { - video.setDescription(description); + this.video.setDescription(description); } @@ -56,7 +56,7 @@ public class WxCpXmlOutVideoMessage extends WxCpXmlOutMessage { private String description; public String getMediaId() { - return mediaId; + return this.mediaId; } public void setMediaId(String mediaId) { @@ -64,7 +64,7 @@ public class WxCpXmlOutVideoMessage extends WxCpXmlOutMessage { } public String getTitle() { - return title; + return this.title; } public void setTitle(String title) { @@ -72,7 +72,7 @@ public class WxCpXmlOutVideoMessage extends WxCpXmlOutMessage { } public String getDescription() { - return description; + return this.description; } public void setDescription(String description) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java index 1730a0cf..1fd6d4ce 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java @@ -17,7 +17,7 @@ public class WxCpXmlOutVoiceMessage extends WxCpXmlOutMessage { } public String getMediaId() { - return mediaId; + return this.mediaId; } public void setMediaId(String mediaId) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java index 66dfc553..da1cf500 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java @@ -50,9 +50,9 @@ public final class VideoBuilder extends BaseBuilder { public WxCpMessage build() { WxCpMessage m = super.build(); m.setMediaId(this.mediaId); - m.setTitle(title); - m.setDescription(description); - m.setThumbMediaId(thumbMediaId); + m.setTitle(this.title); + m.setDescription(this.description); + m.setThumbMediaId(this.thumbMediaId); return m; } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/NewsBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/NewsBuilder.java index 57344ea5..d74ec70e 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/NewsBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/NewsBuilder.java @@ -22,7 +22,7 @@ public final class NewsBuilder extends BaseBuilder Date: Thu, 8 Sep 2016 15:49:43 +0800 Subject: [PATCH 27/49] fix warnings --- .../me/chanjar/weixin/cp/api/WxCpMessageRouter.java | 7 ++++--- .../chanjar/weixin/cp/api/WxCpMessageRouterRule.java | 6 +++--- .../java/me/chanjar/weixin/cp/bean/WxCpDepart.java | 4 ++++ .../java/me/chanjar/weixin/cp/bean/WxCpMessage.java | 6 +++++- .../main/java/me/chanjar/weixin/cp/bean/WxCpTag.java | 5 +++++ .../java/me/chanjar/weixin/cp/bean/WxCpUser.java | 6 +++++- .../me/chanjar/weixin/cp/bean/WxCpXmlMessage.java | 7 ++++++- .../weixin/cp/bean/WxCpXmlOutNewsMessage.java | 2 +- .../weixin/cp/bean/messagebuilder/FileBuilder.java | 1 + .../weixin/cp/bean/messagebuilder/ImageBuilder.java | 1 + .../weixin/cp/bean/messagebuilder/NewsBuilder.java | 3 ++- .../weixin/cp/bean/messagebuilder/TextBuilder.java | 1 + .../weixin/cp/bean/messagebuilder/VideoBuilder.java | 1 + .../weixin/cp/bean/messagebuilder/VoiceBuilder.java | 1 + .../weixin/cp/bean/outxmlbuilder/ImageBuilder.java | 1 + .../weixin/cp/bean/outxmlbuilder/NewsBuilder.java | 3 ++- .../weixin/cp/bean/outxmlbuilder/TextBuilder.java | 1 + .../weixin/cp/bean/outxmlbuilder/VideoBuilder.java | 1 + .../weixin/cp/bean/outxmlbuilder/VoiceBuilder.java | 1 + .../weixin/cp/util/json/WxCpDepartGsonAdapter.java | 2 ++ .../weixin/cp/util/json/WxCpMessageGsonAdapter.java | 1 + .../weixin/cp/util/json/WxCpTagGsonAdapter.java | 2 ++ .../weixin/cp/util/json/WxCpUserGsonAdapter.java | 1 + .../weixin/cp/util/xml/XStreamTransformer.java | 2 +- .../me/chanjar/weixin/mp/bean/tag/WxUserTag.java | 12 +++++++----- 25 files changed, 60 insertions(+), 18 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java index ece62e58..6d4a8a97 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java @@ -52,7 +52,7 @@ public class WxCpMessageRouter { private static final int DEFAULT_THREAD_POOL_SIZE = 100; protected final Logger log = LoggerFactory.getLogger(WxCpMessageRouter.class); - private final List rules = new ArrayList(); + private final List rules = new ArrayList<>(); private final WxCpService wxCpService; @@ -142,7 +142,7 @@ public class WxCpMessageRouter { return null; } - final List matchRules = new ArrayList(); + final List matchRules = new ArrayList<>(); // 收集匹配的规则 for (final WxCpMessageRouterRule rule : this.rules) { if (rule.test(wxMessage)) { @@ -158,12 +158,13 @@ public class WxCpMessageRouter { } WxCpXmlOutMessage res = null; - final List futures = new ArrayList(); + final List futures = new ArrayList<>(); for (final WxCpMessageRouterRule rule : matchRules) { // 返回最后一个非异步的rule的执行结果 if (rule.isAsync()) { futures.add( this.executorService.submit(new Runnable() { + @Override public void run() { rule.service(wxMessage, WxCpMessageRouter.this.wxCpService, WxCpMessageRouter.this.sessionManager, WxCpMessageRouter.this.exceptionHandler); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java index 9014bde9..c81f045f 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java @@ -36,9 +36,9 @@ public class WxCpMessageRouterRule { private Integer agentId; - private List handlers = new ArrayList(); + private List handlers = new ArrayList<>(); - private List interceptors = new ArrayList(); + private List interceptors = new ArrayList<>(); protected WxCpMessageRouterRule(WxCpMessageRouter routerBuilder) { this.routerBuilder = routerBuilder; @@ -235,7 +235,7 @@ public class WxCpMessageRouterRule { try { - Map context = new HashMap(); + Map context = new HashMap<>(); // 如果拦截器不通过 for (WxCpMessageInterceptor interceptor : this.interceptors) { if (!interceptor.intercept(wxMessage, context, wxCpService, sessionManager)) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java index 540501d7..c8735086 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java @@ -11,6 +11,10 @@ import java.io.Serializable; */ public class WxCpDepart implements Serializable { + /** + * + */ + private static final long serialVersionUID = -5028321625140879571L; private Integer id; private String name; private Integer parentId; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java index 0b5f926e..6dba9091 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java @@ -14,6 +14,10 @@ import java.util.List; */ public class WxCpMessage implements Serializable { + /** + * + */ + private static final long serialVersionUID = -2082278303476631708L; private String toUser; private String toParty; private String toTag; @@ -27,7 +31,7 @@ public class WxCpMessage implements Serializable { private String musicUrl; private String hqMusicUrl; private String safe; - private List articles = new ArrayList(); + private List articles = new ArrayList<>(); /** * 获得文本消息builder diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java index 07c934b3..ca11cb1f 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java @@ -9,6 +9,11 @@ import java.io.Serializable; */ public class WxCpTag implements Serializable { + /** + * + */ + private static final long serialVersionUID = -7243320279646928402L; + private String id; private String name; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java index 1c0cd7f1..d1737d5d 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java @@ -13,7 +13,11 @@ import java.util.List; */ public class WxCpUser implements Serializable { - private final List extAttrs = new ArrayList(); + /** + * + */ + private static final long serialVersionUID = -5696099236344075582L; + private final List extAttrs = new ArrayList<>(); private String userId; private String name; private Integer[] departIds; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java index 80cf7d47..352fa2e6 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java @@ -32,6 +32,11 @@ public class WxCpXmlMessage implements Serializable { // 以下都是微信推送过来的消息的xml的element所对应的属性 /////////////////////// + /** + * + */ + private static final long serialVersionUID = -1042994982179476410L; + @XStreamAlias("AgentID") private Integer agentId; @@ -566,7 +571,7 @@ public class WxCpXmlMessage implements Serializable { public static class SendPicsInfo { @XStreamAlias("PicList") - protected final List picList = new ArrayList(); + protected final List picList = new ArrayList<>(); @XStreamAlias("Count") private Long count; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java index b689ce6f..5906a324 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java @@ -12,7 +12,7 @@ import java.util.List; public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage { @XStreamAlias("Articles") - protected final List articles = new ArrayList(); + protected final List articles = new ArrayList<>(); @XStreamAlias("ArticleCount") protected int articleCount; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java index d8295454..1da78169 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java @@ -23,6 +23,7 @@ public final class FileBuilder extends BaseBuilder { return this; } + @Override public WxCpMessage build() { WxCpMessage m = super.build(); m.setMediaId(this.mediaId); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java index 99195c26..a74f5016 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java @@ -23,6 +23,7 @@ public final class ImageBuilder extends BaseBuilder { return this; } + @Override public WxCpMessage build() { WxCpMessage m = super.build(); m.setMediaId(this.mediaId); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java index e2d2086a..8ea90872 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java @@ -17,7 +17,7 @@ import java.util.List; */ public final class NewsBuilder extends BaseBuilder { - private List articles = new ArrayList(); + private List articles = new ArrayList<>(); public NewsBuilder() { this.msgType = WxConsts.CUSTOM_MSG_NEWS; @@ -28,6 +28,7 @@ public final class NewsBuilder extends BaseBuilder { return this; } + @Override public WxCpMessage build() { WxCpMessage m = super.build(); m.setArticles(this.articles); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java index 076db2f1..8c1ee1d0 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java @@ -23,6 +23,7 @@ public final class TextBuilder extends BaseBuilder { return this; } + @Override public WxCpMessage build() { WxCpMessage m = super.build(); m.setContent(this.content); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java index da1cf500..52cba287 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java @@ -47,6 +47,7 @@ public final class VideoBuilder extends BaseBuilder { return this; } + @Override public WxCpMessage build() { WxCpMessage m = super.build(); m.setMediaId(this.mediaId); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java index 10b2b0fe..0960fe8f 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java @@ -23,6 +23,7 @@ public final class VoiceBuilder extends BaseBuilder { return this; } + @Override public WxCpMessage build() { WxCpMessage m = super.build(); m.setMediaId(this.mediaId); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/ImageBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/ImageBuilder.java index ae774e40..f8cd25f4 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/ImageBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/ImageBuilder.java @@ -16,6 +16,7 @@ public final class ImageBuilder extends BaseBuilder { - protected final List articles = new ArrayList(); + protected final List articles = new ArrayList<>(); public NewsBuilder addArticle(Item item) { this.articles.add(item); return this; } + @Override public WxCpXmlOutNewsMessage build() { WxCpXmlOutNewsMessage m = new WxCpXmlOutNewsMessage(); for (Item item : this.articles) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TextBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TextBuilder.java index 909a0ec9..dcdb58ca 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TextBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TextBuilder.java @@ -15,6 +15,7 @@ public final class TextBuilder extends BaseBuilder, JsonDeserializer { + @Override public JsonElement serialize(WxCpDepart group, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); if (group.getId() != null) { @@ -36,6 +37,7 @@ public class WxCpDepartGsonAdapter implements JsonSerializer, JsonDe return json; } + @Override public WxCpDepart deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { WxCpDepart depart = new WxCpDepart(); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java index 45df80b3..322658c2 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java @@ -20,6 +20,7 @@ import java.lang.reflect.Type; */ public class WxCpMessageGsonAdapter implements JsonSerializer { + @Override public JsonElement serialize(WxCpMessage message, Type typeOfSrc, JsonSerializationContext context) { JsonObject messageJson = new JsonObject(); messageJson.addProperty("agentid", message.getAgentId()); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpTagGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpTagGsonAdapter.java index b8599a1c..43e84a00 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpTagGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpTagGsonAdapter.java @@ -19,6 +19,7 @@ import java.lang.reflect.Type; */ public class WxCpTagGsonAdapter implements JsonSerializer, JsonDeserializer { + @Override public JsonElement serialize(WxCpTag tag, Type typeOfSrc, JsonSerializationContext context) { JsonObject o = new JsonObject(); o.addProperty("tagid", tag.getId()); @@ -26,6 +27,7 @@ public class WxCpTagGsonAdapter implements JsonSerializer, JsonDeserial return o; } + @Override public WxCpTag deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java index 7a88f47e..bbabf054 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java @@ -19,6 +19,7 @@ import java.lang.reflect.Type; */ public class WxCpUserGsonAdapter implements JsonDeserializer, JsonSerializer { + @Override public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject o = json.getAsJsonObject(); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java index ae46d8f2..6b580630 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java @@ -45,7 +45,7 @@ public class XStreamTransformer { } private static Map configXStreamInstance() { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put(WxCpXmlMessage.class, config_WxCpXmlMessage()); map.put(WxCpXmlOutNewsMessage.class, config_WxCpXmlOutNewsMessage()); map.put(WxCpXmlOutTextMessage.class, config_WxCpXmlOutTextMessage()); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java index 79d28f20..1f03019e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java @@ -1,10 +1,12 @@ package me.chanjar.weixin.mp.bean.tag; -import com.google.gson.JsonParser; -import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import com.google.gson.JsonParser; + +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + /** * 用户标签对象 * @author binarywang(https://github.com/binarywang) @@ -27,7 +29,7 @@ public class WxUserTag { private Integer count; public String getName() { - return name; + return this.name; } public void setName(String name) { @@ -35,7 +37,7 @@ public class WxUserTag { } public Integer getCount() { - return count; + return this.count; } public void setCount(Integer count) { @@ -43,7 +45,7 @@ public class WxUserTag { } public Integer getId() { - return id; + return this.id; } public void setId(Integer id) { From 7bf7f2827b86d3c28f11a5b3ab1313eb64968795 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 8 Sep 2016 15:58:34 +0800 Subject: [PATCH 28/49] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/util/json/WxMpIndustryGsonAdapter.java | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java index 79fb5f0b..60361249 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.util.json; +import java.lang.reflect.Type; + import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; @@ -7,38 +9,43 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; + import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.mp.bean.Industry; import me.chanjar.weixin.mp.bean.WxMpIndustry; -import java.lang.reflect.Type; - /** * @author miller */ -public class WxMpIndustryGsonAdapter implements JsonSerializer, JsonDeserializer { - @Override - public JsonElement serialize(WxMpIndustry wxMpIndustry, Type type, JsonSerializationContext jsonSerializationContext) { - JsonObject json = new JsonObject(); - json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId()); - json.addProperty("industry_id2", wxMpIndustry.getSecondIndustry().getId()); - return json; - } +public class WxMpIndustryGsonAdapter + implements JsonSerializer, JsonDeserializer { + @Override + public JsonElement serialize(WxMpIndustry wxMpIndustry, Type type, + JsonSerializationContext jsonSerializationContext) { + JsonObject json = new JsonObject(); + json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId()); + json.addProperty("industry_id2", wxMpIndustry.getSecondIndustry().getId()); + return json; + } - @Override - public WxMpIndustry deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - WxMpIndustry wxMpIndustry = new WxMpIndustry(); - JsonObject primaryIndustry = jsonElement.getAsJsonObject().get("primary_industry").getAsJsonObject(); - wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry)); - JsonObject secondaryIndustry = jsonElement.getAsJsonObject().get("secondary_industry").getAsJsonObject(); - wxMpIndustry.setSecondIndustry(convertFromJson(secondaryIndustry)); - return wxMpIndustry; - } + @Override + public WxMpIndustry deserialize(JsonElement jsonElement, Type type, + JsonDeserializationContext jsonDeserializationContext) + throws JsonParseException { + WxMpIndustry wxMpIndustry = new WxMpIndustry(); + JsonObject primaryIndustry = jsonElement.getAsJsonObject() + .get("primary_industry").getAsJsonObject(); + wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry)); + JsonObject secondaryIndustry = jsonElement.getAsJsonObject() + .get("secondary_industry").getAsJsonObject(); + wxMpIndustry.setSecondIndustry(convertFromJson(secondaryIndustry)); + return wxMpIndustry; + } - private Industry convertFromJson(JsonObject json) { - Industry industry = new Industry(); - industry.setFirstClass(GsonHelper.getString(json, "first_class")); - industry.setSecondClass(GsonHelper.getString(json, "second_class")); - return industry; - } + private static Industry convertFromJson(JsonObject json) { + Industry industry = new Industry(); + industry.setFirstClass(GsonHelper.getString(json, "first_class")); + industry.setSecondClass(GsonHelper.getString(json, "second_class")); + return industry; + } } From 3ab8a3c7c6b094cca6ec1fa7615a4296314e1713 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Thu, 8 Sep 2016 21:11:02 +0800 Subject: [PATCH 29/49] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpUserTagService.java | 18 +++++++++-- .../mp/api/impl/WxMpUserTagServiceImpl.java | 30 +++++++++++++------ .../chanjar/weixin/mp/bean/tag/WxUserTag.java | 13 +++++++- .../api/impl/WxMpUserTagServiceImplTest.java | 10 +++++++ 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java index c909f9ce..1f4277da 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.api; +import java.util.List; + import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.bean.tag.WxUserTag; @@ -13,14 +15,24 @@ public interface WxMpUserTagService { /** *
-   *   创建标签
-   *   一个公众号,最多可以创建100个标签。
+   * 创建标签
+   * 一个公众号,最多可以创建100个标签。
    * 详情请见:用户标签管理
    * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/create?access_token=ACCESS_TOKEN
    * 
* - * @param name 分组名字(30个字符以内) + * @param name 标签名字(30个字符以内) */ WxUserTag tagCreate(String name) throws WxErrorException; + /** + *
+   * 获取公众号已创建的标签
+   * 详情请见:用户标签管理
+   * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/get?access_token=ACCESS_TOKEN
+   * 
+ * + */ + List tagGet() throws WxErrorException; + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java index 2fce5443..fb934961 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java @@ -1,13 +1,16 @@ package me.chanjar.weixin.mp.api.impl; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.gson.JsonObject; + import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpUserTagService; import me.chanjar.weixin.mp.bean.tag.WxUserTag; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * @@ -15,7 +18,8 @@ import org.slf4j.LoggerFactory; * Created by Binary Wang on 2016/9/2. */ public class WxMpUserTagServiceImpl implements WxMpUserTagService { - protected final Logger log = LoggerFactory.getLogger(WxMpDataCubeServiceImpl.class); + protected final Logger log = LoggerFactory + .getLogger(WxMpDataCubeServiceImpl.class); private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/tags"; private WxMpService wxMpService; @@ -32,11 +36,19 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { groupJson.addProperty("name", name); json.add("tag", groupJson); - String responseContent = this.wxMpService.execute( - new SimplePostRequestExecutor(), - url, - json.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, name, responseContent); + String responseContent = this.wxMpService.post(url, json.toString()); + this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, name, + responseContent); return WxUserTag.fromJson(responseContent); } + + @Override + public List tagGet() throws WxErrorException { + String url = API_URL_PREFIX + "/get"; + + String responseContent = this.wxMpService.get(url, null); + this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, "[empty]", + responseContent); + return WxUserTag.listFromJson(responseContent); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java index 1f03019e..d9e07d04 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java @@ -1,9 +1,12 @@ package me.chanjar.weixin.mp.bean.tag; +import java.util.List; + import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -53,7 +56,15 @@ public class WxUserTag { } public static WxUserTag fromJson(String json) { - return WxMpGsonBuilder.create().fromJson(new JsonParser().parse(json).getAsJsonObject().get("tag"), WxUserTag.class); + return WxMpGsonBuilder.create().fromJson( + new JsonParser().parse(json).getAsJsonObject().get("tag"), + WxUserTag.class); + } + + public static List listFromJson(String json) { + return WxMpGsonBuilder.create().fromJson( + new JsonParser().parse(json).getAsJsonObject().get("tags"), + new TypeToken>(){}.getType()); } public String toJson() { diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java index af8125bf..ea7799dd 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java @@ -3,6 +3,9 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.bean.tag.WxUserTag; + +import java.util.List; + import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; @@ -26,4 +29,11 @@ public class WxMpUserTagServiceImplTest { Assert.assertEquals(tagName, res.getName()); } + @Test + public void testTagGet() throws Exception { + List res = this.wxService.getUserTagService().tagGet(); + System.out.println(res); + Assert.assertNotNull(res); + } + } \ No newline at end of file From f66c0b02e29c782bae40277cdae418b0be6c97b4 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Fri, 9 Sep 2016 09:43:01 +0800 Subject: [PATCH 30/49] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=B1=E4=BA=8E?= =?UTF-8?q?=E9=9D=99=E6=80=81=E5=BC=95=E7=94=A8SimpleDateFormat=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=BA=BF=E7=A8=8B=E4=B8=8D=E5=AE=89=E5=85=A8=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/WxMpService.java | 20 +++-- .../mp/api/impl/WxMpDataCubeServiceImpl.java | 85 ++++++++++--------- .../util/json/WxLongTimeJsonSerializer.java | 6 +- .../json/WxMpUserCumulateGsonAdapter.java | 19 +++-- .../util/json/WxMpUserSummaryGsonAdapter.java | 19 +++-- .../api/impl/WxMpDataCubeServiceImplTest.java | 24 +++--- 6 files changed, 102 insertions(+), 71 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 503dd55b..077488b7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -3,18 +3,26 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; -import me.chanjar.weixin.mp.bean.*; -import me.chanjar.weixin.mp.bean.result.*; - -import java.text.SimpleDateFormat; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; +import me.chanjar.weixin.mp.bean.WxMpIndustry; +import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage; +import me.chanjar.weixin.mp.bean.WxMpMassNews; +import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; +import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage; +import me.chanjar.weixin.mp.bean.WxMpMassVideo; +import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; +import me.chanjar.weixin.mp.bean.WxMpTemplateMessage; +import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; +import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; +import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; +import me.chanjar.weixin.mp.bean.result.WxMpUser; /** * 微信API的Service */ public interface WxMpService { - SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); - /** *
    * 验证推送过来的消息的正确性
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java
index 092d6af1..0c668e06 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java
@@ -1,8 +1,17 @@
 package me.chanjar.weixin.mp.api.impl;
 
+import java.text.Format;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.lang3.time.FastDateFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import com.google.gson.reflect.TypeToken;
+
 import me.chanjar.weixin.common.exception.WxErrorException;
 import me.chanjar.weixin.mp.api.WxMpDataCubeService;
 import me.chanjar.weixin.mp.api.WxMpService;
@@ -13,11 +22,6 @@ import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
 import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Date;
-import java.util.List;
 
 /**
  *  Created by Binary Wang on 2016/8/23.
@@ -27,6 +31,9 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
   protected final Logger log = LoggerFactory.getLogger(WxMpDataCubeServiceImpl.class);
 
   private static final String API_URL_PREFIX = "https://api.weixin.qq.com/datacube";
+
+  private final Format dateFormat = FastDateFormat.getInstance("yyyy-MM-dd");
+
   private WxMpService wxMpService;
 
   public WxMpDataCubeServiceImpl(WxMpService wxMpService) {
@@ -37,8 +44,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
   public List getUserSummary(Date beginDate, Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getusersummary";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -50,8 +57,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
   public List getUserCumulate(Date beginDate, Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getusercumulate";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -63,8 +70,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
   public List getArticleSummary(Date beginDate, Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getarticlesummary";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -76,8 +83,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
   public List getArticleTotal(Date beginDate, Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getarticletotal";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -89,8 +96,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
   public List getUserRead(Date beginDate, Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getuserread";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -102,8 +109,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
   public List getUserReadHour(Date beginDate, Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getuserreadhour";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -115,8 +122,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
   public List getUserShare(Date beginDate, Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getusershare";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -128,8 +135,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
   public List getUserShareHour(Date beginDate, Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getusersharehour";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -142,8 +149,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
       throws WxErrorException {
     String url = API_URL_PREFIX + "/getupstreammsg";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -156,8 +163,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
       Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getupstreammsghour";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -170,8 +177,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
       Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getupstreammsgweek";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -184,8 +191,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
       Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getupstreammsgmonth";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -198,8 +205,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
       Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getupstreammsgdist";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -212,8 +219,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
       Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getupstreammsgdistweek";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -226,8 +233,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
       Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getupstreammsgdistmonth";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -240,8 +247,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
       Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getinterfacesummary";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
@@ -254,8 +261,8 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
       Date endDate) throws WxErrorException {
     String url = API_URL_PREFIX + "/getinterfacesummaryhour";
     JsonObject param = new JsonObject();
-    param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
-    param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
+    param.addProperty("begin_date", this.dateFormat.format(beginDate));
+    param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
     return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxLongTimeJsonSerializer.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxLongTimeJsonSerializer.java
index 388139f2..957600da 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxLongTimeJsonSerializer.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxLongTimeJsonSerializer.java
@@ -1,7 +1,9 @@
 package me.chanjar.weixin.mp.util.json;
 
 import java.io.IOException;
-import java.text.SimpleDateFormat;
+import java.text.Format;
+
+import org.apache.commons.lang3.time.FastDateFormat;
 
 import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.databind.JsonSerializer;
@@ -11,7 +13,7 @@ import com.fasterxml.jackson.databind.SerializerProvider;
  * Created by Binary Wang on 2016/7/13.
  */
 public class WxLongTimeJsonSerializer extends JsonSerializer {
-  private static SimpleDateFormat DF = new SimpleDateFormat(
+  private static Format DF = FastDateFormat.getInstance(
       "yyyy-MM-dd HH:mm:ss");
 
   @Override
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java
index fcf1d403..b1a7ecf9 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java
@@ -8,13 +8,19 @@
  */
 package me.chanjar.weixin.mp.util.json;
 
-import com.google.gson.*;
-import me.chanjar.weixin.common.util.json.GsonHelper;
-import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
-
 import java.lang.reflect.Type;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
+
+import org.apache.commons.lang3.time.FastDateFormat;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+
+import me.chanjar.weixin.common.util.json.GsonHelper;
+import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
 
 /**
  * 
@@ -23,7 +29,8 @@ import java.text.SimpleDateFormat;
  */
 public class WxMpUserCumulateGsonAdapter implements JsonDeserializer {
 
-  private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
+  private static final FastDateFormat SIMPLE_DATE_FORMAT = FastDateFormat
+      .getInstance("yyyy-MM-dd");
 
   @Override
   public WxDataCubeUserCumulate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserSummaryGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserSummaryGsonAdapter.java
index 848b82ce..adcc0af7 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserSummaryGsonAdapter.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserSummaryGsonAdapter.java
@@ -8,20 +8,27 @@
  */
 package me.chanjar.weixin.mp.util.json;
 
-import com.google.gson.*;
-import me.chanjar.weixin.common.util.json.GsonHelper;
-import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
-
 import java.lang.reflect.Type;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
+
+import org.apache.commons.lang3.time.FastDateFormat;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+
+import me.chanjar.weixin.common.util.json.GsonHelper;
+import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
 
 /**
  * @author Daniel Qian
  */
 public class WxMpUserSummaryGsonAdapter implements JsonDeserializer {
 
-  private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
+  private static final FastDateFormat SIMPLE_DATE_FORMAT = FastDateFormat
+      .getInstance("yyyy-MM-dd");
 
   @Override
   public WxDataCubeUserSummary deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java
index bfb8cf58..1111f96a 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java
@@ -1,10 +1,10 @@
 package me.chanjar.weixin.mp.api.impl;
 
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 
+import org.apache.commons.lang3.time.FastDateFormat;
 import org.testng.Assert;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Guice;
@@ -28,39 +28,39 @@ import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
  */
 @Guice(modules = ApiTestModule.class)
 public class WxMpDataCubeServiceImplTest {
-  private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
-      "yyyy-MM-dd");
+  private FastDateFormat simpleDateFormat = FastDateFormat
+      .getInstance("yyyy-MM-dd");
 
   @Inject
   protected WxMpServiceImpl wxService;
 
   @DataProvider
   public Object[][] oneDay() throws ParseException {
-    return new Object[][] { { simpleDateFormat.parse("2016-08-22") } };
+    return new Object[][] { { this.simpleDateFormat.parse("2016-08-22") } };
   }
 
   @DataProvider
   public Object[][] threeDays() throws ParseException {
-    return new Object[][] { { simpleDateFormat.parse("2016-08-20"),
-        simpleDateFormat.parse("2016-08-22") } };
+    return new Object[][] { { this.simpleDateFormat.parse("2016-08-20"),
+        this.simpleDateFormat.parse("2016-08-22") } };
   }
 
   @DataProvider
   public Object[][] sevenDays() throws ParseException {
-    return new Object[][] { { simpleDateFormat.parse("2016-08-16"),
-        simpleDateFormat.parse("2016-08-22") } };
+    return new Object[][] { { this.simpleDateFormat.parse("2016-08-16"),
+        this.simpleDateFormat.parse("2016-08-22") } };
   }
 
   @DataProvider
   public Object[][] fifteenDays() throws ParseException {
-    return new Object[][] { { simpleDateFormat.parse("2016-08-14"),
-        simpleDateFormat.parse("2016-08-27") } };
+    return new Object[][] { { this.simpleDateFormat.parse("2016-08-14"),
+        this.simpleDateFormat.parse("2016-08-27") } };
   }
 
   @DataProvider
   public Object[][] thirtyDays() throws ParseException {
-    return new Object[][] { { simpleDateFormat.parse("2016-07-30"),
-        simpleDateFormat.parse("2016-08-27") } };
+    return new Object[][] { { this.simpleDateFormat.parse("2016-07-30"),
+        this.simpleDateFormat.parse("2016-08-27") } };
   }
 
   @Test(dataProvider = "sevenDays")

From 82d71ea4185b18366fde72dea0b9a059d184357f Mon Sep 17 00:00:00 2001
From: BinaryWang 
Date: Fri, 9 Sep 2016 09:51:18 +0800
Subject: [PATCH 31/49] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=B9=E5=BA=94?=
 =?UTF-8?q?=E5=B8=B8=E9=87=8F=E5=90=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java      | 4 ++--
 .../weixin/mp/util/json/WxMpUserSummaryGsonAdapter.java       | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java
index b1a7ecf9..74ccd154 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserCumulateGsonAdapter.java
@@ -29,7 +29,7 @@ import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
  */
 public class WxMpUserCumulateGsonAdapter implements JsonDeserializer {
 
-  private static final FastDateFormat SIMPLE_DATE_FORMAT = FastDateFormat
+  private static final FastDateFormat DATE_FORMAT = FastDateFormat
       .getInstance("yyyy-MM-dd");
 
   @Override
@@ -40,7 +40,7 @@ public class WxMpUserCumulateGsonAdapter implements JsonDeserializer {
 
-  private static final FastDateFormat SIMPLE_DATE_FORMAT = FastDateFormat
+  private static final FastDateFormat DATE_FORMAT = FastDateFormat
       .getInstance("yyyy-MM-dd");
 
   @Override
@@ -39,7 +39,7 @@ public class WxMpUserSummaryGsonAdapter implements JsonDeserializer
Date: Fri, 9 Sep 2016 10:18:04 +0800
Subject: [PATCH 32/49] =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=BB=9F=E8=AE=A1?=
 =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../mp/api/impl/WxMpDataCubeServiceImpl.java  | 71 +++++--------------
 .../datacube/WxDataCubeArticleResult.java     | 16 ++++-
 .../bean/datacube/WxDataCubeArticleTotal.java | 16 ++++-
 .../datacube/WxDataCubeInterfaceResult.java   | 15 ++++
 .../mp/bean/datacube/WxDataCubeMsgResult.java | 15 ++++
 .../bean/datacube/WxDataCubeUserCumulate.java | 21 +++++-
 .../bean/datacube/WxDataCubeUserSummary.java  | 21 +++++-
 7 files changed, 112 insertions(+), 63 deletions(-)

diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java
index 0c668e06..b82b7eaa 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java
@@ -9,8 +9,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.reflect.TypeToken;
 
 import me.chanjar.weixin.common.exception.WxErrorException;
 import me.chanjar.weixin.mp.api.WxMpDataCubeService;
@@ -21,7 +19,6 @@ import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
-import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
 
 /**
  *  Created by Binary Wang on 2016/8/23.
@@ -48,9 +45,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeUserSummary.fromJson(responseContent);
   }
 
   @Override
@@ -61,9 +56,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeUserCumulate.fromJson(responseContent);
   }
 
   @Override
@@ -74,9 +67,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeArticleResult.fromJson(responseContent);
   }
 
   @Override
@@ -87,9 +78,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeArticleTotal.fromJson(responseContent);
   }
 
   @Override
@@ -100,9 +89,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeArticleResult.fromJson(responseContent);
   }
 
   @Override
@@ -113,9 +100,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeArticleResult.fromJson(responseContent);
   }
 
   @Override
@@ -126,9 +111,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeArticleResult.fromJson(responseContent);
   }
 
   @Override
@@ -139,9 +122,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeArticleResult.fromJson(responseContent);
   }
 
   @Override
@@ -153,9 +134,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeMsgResult.fromJson(responseContent);
   }
 
   @Override
@@ -167,9 +146,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeMsgResult.fromJson(responseContent);
   }
 
   @Override
@@ -181,9 +158,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeMsgResult.fromJson(responseContent);
   }
 
   @Override
@@ -195,9 +170,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeMsgResult.fromJson(responseContent);
   }
 
   @Override
@@ -209,9 +182,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeMsgResult.fromJson(responseContent);
   }
 
   @Override
@@ -223,9 +194,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeMsgResult.fromJson(responseContent);
   }
 
   @Override
@@ -237,9 +206,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeMsgResult.fromJson(responseContent);
   }
 
   @Override
@@ -251,9 +218,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeInterfaceResult.fromJson(responseContent);
   }
 
   @Override
@@ -265,8 +230,6 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
     param.addProperty("end_date", this.dateFormat.format(endDate));
     String responseContent = this.wxMpService.post(url, param.toString());
     this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
-    return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
-            new TypeToken>() {
-            }.getType());
+    return WxDataCubeInterfaceResult.fromJson(responseContent);
   }
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java
index ce1f4269..3dd28459 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java
@@ -1,6 +1,12 @@
 package me.chanjar.weixin.mp.bean.datacube;
 
+import java.util.List;
+
+import com.google.gson.JsonParser;
 import com.google.gson.annotations.SerializedName;
+import com.google.gson.reflect.TypeToken;
+
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
 
 /**
  * 图文分析数据接口返回结果对象
@@ -9,6 +15,8 @@ import com.google.gson.annotations.SerializedName;
  */
 public class WxDataCubeArticleResult extends WxDataCubeBaseResult {
 
+  private static final JsonParser JSON_PARSER = new JsonParser();
+
   /**
    * ref_hour
    * 数据的小时,包括从000到2300,分别代表的是[000,100)到[2300,2400),即每日的第1小时和最后1小时
@@ -203,5 +211,11 @@ public class WxDataCubeArticleResult extends WxDataCubeBaseResult {
   public void setUserSource(Integer userSource) {
     this.userSource = userSource;
   }
-  
+
+  public static List fromJson(String json) {
+    return WxMpGsonBuilder.INSTANCE.create().fromJson(
+        JSON_PARSER.parse(json).getAsJsonObject().get("list"),
+        new TypeToken>() {
+        }.getType());
+  }
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java
index 1832f734..37401cf8 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java
@@ -1,8 +1,12 @@
 package me.chanjar.weixin.mp.bean.datacube;
 
+import java.util.List;
+
+import com.google.gson.JsonParser;
 import com.google.gson.annotations.SerializedName;
+import com.google.gson.reflect.TypeToken;
 
-import java.util.List;
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
 
 /**
  * 图文分析数据接口返回结果对象
@@ -11,6 +15,8 @@ import java.util.List;
  */
 public class WxDataCubeArticleTotal extends WxDataCubeBaseResult {
 
+  private static final JsonParser JSON_PARSER = new JsonParser();
+
   /**
    * msgid
    * 请注意:这里的msgid实际上是由msgid(图文消息id,这也就是群发接口调用后返回的msg_data_id)和index(消息次序索引)组成, 例如12003_3, 其中12003是msgid,即一次群发的消息的id; 3为index,假设该次群发的图文消息共5个文章(因为可能为多图文),3表示5个中的第3个
@@ -55,5 +61,11 @@ public class WxDataCubeArticleTotal extends WxDataCubeBaseResult {
   public void setDetails(List details) {
     this.details = details;
   }
-  
+
+  public static List fromJson(String json) {
+    return WxMpGsonBuilder.INSTANCE.create().fromJson(
+        JSON_PARSER.parse(json).getAsJsonObject().get("list"),
+        new TypeToken>() {
+        }.getType());
+  }
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java
index 4abbe277..82a45dcf 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java
@@ -1,6 +1,12 @@
 package me.chanjar.weixin.mp.bean.datacube;
 
+import java.util.List;
+
+import com.google.gson.JsonParser;
 import com.google.gson.annotations.SerializedName;
+import com.google.gson.reflect.TypeToken;
+
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
 
 /**
  * 接口分析数据接口返回结果对象
@@ -9,6 +15,8 @@ import com.google.gson.annotations.SerializedName;
  */
 public class WxDataCubeInterfaceResult extends WxDataCubeBaseResult {
 
+  private static final JsonParser JSON_PARSER = new JsonParser();
+
   /**
    * ref_hour
    * 数据的小时,包括从000到2300,分别代表的是[000,100)到[2300,2400),即每日的第1小时和最后1小时
@@ -83,5 +91,12 @@ public class WxDataCubeInterfaceResult extends WxDataCubeBaseResult {
   public void setMaxTimeCost(Integer maxTimeCost) {
     this.maxTimeCost = maxTimeCost;
   }
+
+  public static List fromJson(String json) {
+    return WxMpGsonBuilder.INSTANCE.create().fromJson(
+        JSON_PARSER.parse(json).getAsJsonObject().get("list"),
+        new TypeToken>() {
+        }.getType());
+  }
  
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java
index bbeb3b36..908dfca8 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java
@@ -1,6 +1,12 @@
 package me.chanjar.weixin.mp.bean.datacube;
 
+import java.util.List;
+
+import com.google.gson.JsonParser;
 import com.google.gson.annotations.SerializedName;
+import com.google.gson.reflect.TypeToken;
+
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
 
 /**
  * 消息分析数据接口返回结果对象
@@ -9,6 +15,8 @@ import com.google.gson.annotations.SerializedName;
  */
 public class WxDataCubeMsgResult extends WxDataCubeBaseResult {
 
+  private static final JsonParser JSON_PARSER = new JsonParser();
+
   /**
    * ref_hour
    * 数据的小时,包括从000到2300,分别代表的是[000,100)到[2300,2400),即每日的第1小时和最后1小时
@@ -114,4 +122,11 @@ public class WxDataCubeMsgResult extends WxDataCubeBaseResult {
     this.oriPageReadUser = oriPageReadUser;
   }
 
+  public static List fromJson(String json) {
+    return WxMpGsonBuilder.INSTANCE.create().fromJson(
+        JSON_PARSER.parse(json).getAsJsonObject().get("list"),
+        new TypeToken>() {
+        }.getType());
+  }
+
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java
index 7192cfb4..039bd189 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java
@@ -1,19 +1,27 @@
 package me.chanjar.weixin.mp.bean.datacube;
 
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 
-import java.io.Serializable;
-import java.util.Date;
+import com.google.gson.JsonParser;
+import com.google.gson.reflect.TypeToken;
+
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
 
 /**
  * 
  * 累计用户数据接口的返回JSON数据包
- * http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
+ * 详情查看文档:用户分析数据接口
  * 
*/ public class WxDataCubeUserCumulate implements Serializable { + private static final JsonParser JSON_PARSER = new JsonParser(); + private static final long serialVersionUID = -3570981300225093657L; private Date refDate; @@ -40,4 +48,11 @@ public class WxDataCubeUserCumulate implements Serializable { public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); } + + public static List fromJson(String json) { + return WxMpGsonBuilder.INSTANCE.create().fromJson( + JSON_PARSER.parse(json).getAsJsonObject().get("list"), + new TypeToken>() { + }.getType()); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java index cfb41842..4802027e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java @@ -1,20 +1,28 @@ package me.chanjar.weixin.mp.bean.datacube; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import java.io.Serializable; -import java.util.Date; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; + +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; /** *
  * 用户增减数据接口的返回JSON数据包
- * http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
+ * 详情查看文档:用户分析数据接口
  * 
*/ public class WxDataCubeUserSummary implements Serializable { private static final long serialVersionUID = -2336654489906694173L; + private static final JsonParser JSON_PARSER = new JsonParser(); + private Date refDate; private Integer userSource; @@ -59,4 +67,11 @@ public class WxDataCubeUserSummary implements Serializable { public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); } + + public static List fromJson(String json) { + return WxMpGsonBuilder.INSTANCE.create().fromJson( + JSON_PARSER.parse(json).getAsJsonObject().get("list"), + new TypeToken>() { + }.getType()); + } } From ea35246d7639c1e4f278f894b4a5725f36ac86a9 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Fri, 9 Sep 2016 14:03:18 +0800 Subject: [PATCH 33/49] =?UTF-8?q?=E6=9A=82=E6=97=B6=E5=8E=BB=E6=8E=89jacks?= =?UTF-8?q?on=E4=BB=A3=E7=A0=81=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E6=95=B0=E6=8D=AE=E7=9A=84=E4=BB=A3=E7=A0=81=E6=94=BE?= =?UTF-8?q?=E5=9C=A8=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=AF=94=E8=BE=83=E5=A5=BD?= =?UTF-8?q?=E4=BA=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 ----- .../weixin/mp/bean/WxMpXmlMessage.java | 3 --- .../mp/bean/kefu/result/WxMpKfMsgRecord.java | 6 ++--- .../util/json/WxLongTimeJsonSerializer.java | 25 ------------------- .../mp/api/impl/WxMpKefuServiceImplTest.java | 10 +++----- 5 files changed, 6 insertions(+), 44 deletions(-) delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxLongTimeJsonSerializer.java diff --git a/pom.xml b/pom.xml index 54782c38..357471f9 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,6 @@ 1.7.10 1.1.2 3.6.7 - 2.8.0 2.9.0 2.7 3.4 @@ -106,11 +105,6 @@ commons-lang3 ${commons-lang3.version} - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - redis.clients jedis diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java index 823558fe..047961ea 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java @@ -6,8 +6,6 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import me.chanjar.weixin.mp.util.json.WxLongTimeJsonSerializer; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -49,7 +47,6 @@ public class WxMpXmlMessage implements Serializable { private String fromUserName; @XStreamAlias("CreateTime") - @JsonSerialize(using = WxLongTimeJsonSerializer.class) private Long createTime; @XStreamAlias("MsgType") diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java index 3fe2002c..7f326ac1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java @@ -1,11 +1,10 @@ package me.chanjar.weixin.mp.bean.kefu.result; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.google.gson.annotations.SerializedName; -import me.chanjar.weixin.mp.util.json.WxLongTimeJsonSerializer; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import com.google.gson.annotations.SerializedName; + /** * Created by Binary Wang on 2016/7/18. */ @@ -38,7 +37,6 @@ public class WxMpKfMsgRecord { * time 操作时间,unix时间戳 */ @SerializedName("time") - @JsonSerialize(using = WxLongTimeJsonSerializer.class) private Long time; @Override diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxLongTimeJsonSerializer.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxLongTimeJsonSerializer.java deleted file mode 100644 index 957600da..00000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxLongTimeJsonSerializer.java +++ /dev/null @@ -1,25 +0,0 @@ -package me.chanjar.weixin.mp.util.json; - -import java.io.IOException; -import java.text.Format; - -import org.apache.commons.lang3.time.FastDateFormat; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; - -/** - * Created by Binary Wang on 2016/7/13. - */ -public class WxLongTimeJsonSerializer extends JsonSerializer { - private static Format DF = FastDateFormat.getInstance( - "yyyy-MM-dd HH:mm:ss"); - - @Override - public void serialize(Long value, JsonGenerator gen, - SerializerProvider serializers) - throws IOException { - gen.writeString(DF.format(value * 1000)); - } -} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java index c1812ab0..45ad1804 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java @@ -9,8 +9,6 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; @@ -150,20 +148,20 @@ public class WxMpKefuServiceImplTest { } @Test - public void testKfMsgList() throws WxErrorException, JsonProcessingException { + public void testKfMsgList() throws WxErrorException { Date startTime = DateTime.now().minusDays(1).toDate(); Date endTime = DateTime.now().minusDays(0).toDate(); WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime,endTime, 1L, 50); Assert.assertNotNull(result); - System.err.println(new ObjectMapper().writeValueAsString(result)); + System.err.println(result); } @Test - public void testKfMsgListAll() throws WxErrorException, JsonProcessingException { + public void testKfMsgListAll() throws WxErrorException { Date startTime = DateTime.now().minusDays(1).toDate(); Date endTime = DateTime.now().minusDays(0).toDate(); WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime,endTime); Assert.assertNotNull(result); - System.err.println(new ObjectMapper().writeValueAsString(result)); + System.err.println(result); } } From 8970b2c62d02b48e2d00d350843c0824e3a18756 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Fri, 9 Sep 2016 19:49:21 +0800 Subject: [PATCH 34/49] =?UTF-8?q?=E8=84=B1=E6=95=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java index 45ad1804..431792e4 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java @@ -78,7 +78,7 @@ public class WxMpKefuServiceImplTest { "testKfAccountAdd" }, dataProvider = "getKfAccount") public void testKfAccountInviteWorker(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() - .kfAccount(kfAccount).inviteWx("www_ucredit_com").build(); + .kfAccount(kfAccount).inviteWx(" ").build(); Assert.assertTrue(this.wxService.getKefuService().kfAccountInviteWorker(request)); } From 8c862d8a489397bc1621568668dc37901e604b0a Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sat, 10 Sep 2016 13:59:29 +0800 Subject: [PATCH 35/49] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chanjar/weixin/mp/api/ApiTestModule.java | 1 + .../weixin/mp/api/impl/WxMpServiceImplTest.java | 11 ++++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java index 4557c342..3955f87d 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java @@ -31,6 +31,7 @@ public class ApiTestModule implements Module { } } + @SuppressWarnings("unchecked") public static T fromXml(Class clazz, InputStream is) { XStream xstream = XStreamInitializer.getInstance(); xstream.alias("xml", clazz); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java index 5791367b..33242ba4 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.api.impl; +import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; @@ -9,8 +10,6 @@ import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.ApiTestModule.WxXmlMpInMemoryConfigStorage; -import org.testng.Assert; - @Test @Guice(modules = ApiTestModule.class) public class WxMpServiceImplTest { @@ -110,11 +109,9 @@ public class WxMpServiceImplTest { @Test public void testBuildQrConnectUrl() { - String qrConnectUrl = this.wxService - .buildQrConnectUrl( - ((WxXmlMpInMemoryConfigStorage) this.wxService - .getWxMpConfigStorage()).getOauth2redirectUri(), - WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); + String qrconnectRedirectUrl = ((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl(); + String qrConnectUrl = this.wxService.buildQrConnectUrl(qrconnectRedirectUrl, + WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); Assert.assertNotNull(qrConnectUrl); System.out.println(qrConnectUrl); } From d49c3dce603d14fd4666fadda25fcb1a0c688966 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sat, 10 Sep 2016 14:11:49 +0800 Subject: [PATCH 36/49] fix some format --- .../api/impl/WxMpMaterialServiceImplTest.java | 39 +++++++++++++------ .../weixin/mp/demo/WxMpEndpointServlet.java | 17 ++++---- .../weixin/mp/demo/WxMpOAuth2Servlet.java | 4 +- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java index 6ab7c7c4..73349626 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java @@ -1,6 +1,24 @@ package me.chanjar.weixin.mp.api.impl; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.io.IOUtils; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + import com.google.inject.Inject; + import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.exception.WxErrorException; @@ -9,17 +27,11 @@ import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.bean.WxMpMaterial; import me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate; import me.chanjar.weixin.mp.bean.WxMpMaterialNews; -import me.chanjar.weixin.mp.bean.result.*; -import org.apache.commons.io.IOUtils; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.*; +import me.chanjar.weixin.mp.bean.result.WxMpMaterialCountResult; +import me.chanjar.weixin.mp.bean.result.WxMpMaterialFileBatchGetResult; +import me.chanjar.weixin.mp.bean.result.WxMpMaterialNewsBatchGetResult; +import me.chanjar.weixin.mp.bean.result.WxMpMaterialUploadResult; +import me.chanjar.weixin.mp.bean.result.WxMpMaterialVideoInfoResult; /** * 素材管理相关接口的测试 @@ -199,6 +211,7 @@ public class WxMpMaterialServiceImplTest { @Test(dependsOnMethods = {"testUpdateNewsInfo"}) public void testMaterialNewsList() throws WxErrorException { WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = this.wxService.getMaterialService().materialNewsBatchGet(0, 20); + Assert.assertNotNull(wxMpMaterialNewsBatchGetResult); return; } @@ -207,6 +220,10 @@ public class WxMpMaterialServiceImplTest { WxMpMaterialFileBatchGetResult wxMpMaterialVoiceBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MATERIAL_VOICE, 0, 20); WxMpMaterialFileBatchGetResult wxMpMaterialVideoBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MATERIAL_VIDEO, 0, 20); WxMpMaterialFileBatchGetResult wxMpMaterialImageBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MATERIAL_IMAGE, 0, 20); + + Assert.assertNotNull(wxMpMaterialVoiceBatchGetResult); + Assert.assertNotNull(wxMpMaterialVideoBatchGetResult); + Assert.assertNotNull(wxMpMaterialImageBatchGetResult); return; } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java index 2921e5fb..ae5fcba0 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java @@ -1,5 +1,12 @@ package me.chanjar.weixin.mp.demo; +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import me.chanjar.weixin.common.util.StringUtils; import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.mp.api.WxMpMessageRouter; @@ -7,16 +14,11 @@ import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - /** * @author Daniel Qian */ public class WxMpEndpointServlet extends HttpServlet { + private static final long serialVersionUID = 1L; protected WxMpConfigStorage wxMpConfigStorage; protected WxMpService wxMpService; @@ -29,7 +31,8 @@ public class WxMpEndpointServlet extends HttpServlet { this.wxMpMessageRouter = wxMpMessageRouter; } - @Override protected void service(HttpServletRequest request, HttpServletResponse response) + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java index e0291b10..b5a4f5f6 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java @@ -12,6 +12,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; public class WxMpOAuth2Servlet extends HttpServlet { + private static final long serialVersionUID = 1L; protected WxMpService wxMpService; @@ -19,7 +20,8 @@ public class WxMpOAuth2Servlet extends HttpServlet { this.wxMpService = wxMpService; } - @Override protected void service(HttpServletRequest request, HttpServletResponse response) + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); From 214661b6c68635652c154764f19a218da80a82fc Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 11 Sep 2016 17:49:22 +0800 Subject: [PATCH 37/49] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpUserTagService.java | 10 ++++++++ .../mp/api/impl/WxMpUserTagServiceImpl.java | 25 ++++++++++++++++--- .../api/impl/WxMpUserTagServiceImplTest.java | 22 ++++++++++++---- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java index 1f4277da..864d9cd0 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java @@ -35,4 +35,14 @@ public interface WxMpUserTagService { */ List tagGet() throws WxErrorException; + /** + *
+   * 编辑标签
+   * 详情请见:用户标签管理
+   * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/update?access_token=ACCESS_TOKEN
+   * 
+ * + */ + Boolean tagUpdate(Integer id, String name) throws WxErrorException; + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java index fb934961..18ff67c7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import com.google.gson.JsonObject; +import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpUserTagService; @@ -32,12 +33,12 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { public WxUserTag tagCreate(String name) throws WxErrorException { String url = API_URL_PREFIX + "/create"; JsonObject json = new JsonObject(); - JsonObject groupJson = new JsonObject(); - groupJson.addProperty("name", name); - json.add("tag", groupJson); + JsonObject tagJson = new JsonObject(); + tagJson.addProperty("name", name); + json.add("tag", tagJson); String responseContent = this.wxMpService.post(url, json.toString()); - this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, name, + this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(), responseContent); return WxUserTag.fromJson(responseContent); } @@ -51,4 +52,20 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { responseContent); return WxUserTag.listFromJson(responseContent); } + + @Override + public Boolean tagUpdate(Integer id, String name) throws WxErrorException { + String url = API_URL_PREFIX + "/update"; + + JsonObject json = new JsonObject(); + JsonObject tagJson = new JsonObject(); + tagJson.addProperty("id", id); + tagJson.addProperty("name", name); + json.add("tag", tagJson); + + String responseContent = this.wxMpService.post(url, json.toString()); + this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(), responseContent); + WxError wxError = WxError.fromJson(responseContent); + return wxError.getErrorCode() == 0; + } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java index ea7799dd..1aab8889 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java @@ -1,15 +1,16 @@ package me.chanjar.weixin.mp.api.impl; -import com.google.inject.Inject; -import me.chanjar.weixin.mp.api.ApiTestModule; -import me.chanjar.weixin.mp.bean.tag.WxUserTag; - import java.util.List; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; +import com.google.inject.Inject; + +import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.bean.tag.WxUserTag; + /** * * @author binarywang(https://github.com/binarywang) @@ -21,11 +22,14 @@ public class WxMpUserTagServiceImplTest { @Inject protected WxMpServiceImpl wxService; + private Integer tagId; + @Test public void testTagCreate() throws Exception { - String tagName = "测试标签"; + String tagName = "测试标签" + System.currentTimeMillis(); WxUserTag res = this.wxService.getUserTagService().tagCreate(tagName); System.out.println(res); + this.tagId = res.getId(); Assert.assertEquals(tagName, res.getName()); } @@ -36,4 +40,12 @@ public class WxMpUserTagServiceImplTest { Assert.assertNotNull(res); } + @Test(dependsOnMethods = { "testTagCreate" }) + public void testTagUpdate() throws Exception { + String tagName = "修改标签" + System.currentTimeMillis(); + Boolean res = this.wxService.getUserTagService().tagUpdate(this.tagId, tagName); + System.out.println(res); + Assert.assertTrue(res); + } + } \ No newline at end of file From 8374971045bf238afda6f411560eb5258b9f42e0 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 11 Sep 2016 17:51:45 +0800 Subject: [PATCH 38/49] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=A0=87=E7=AD=BE=E4=BF=AE=E6=94=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java index 18ff67c7..83c24042 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java @@ -66,6 +66,10 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { String responseContent = this.wxMpService.post(url, json.toString()); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(), responseContent); WxError wxError = WxError.fromJson(responseContent); - return wxError.getErrorCode() == 0; + if (wxError.getErrorCode() == 0) { + return true; + } + + throw new WxErrorException(wxError); } } From ede249643cbaddd24e9091490e45b859a2819852 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Mon, 12 Sep 2016 17:51:17 +0800 Subject: [PATCH 39/49] parameterized some generic types --- .../weixin/mp/api/WxMpMessageRouter.java | 29 ++++++++++--------- .../mp/util/xml/XStreamTransformer.java | 25 +++++++++++----- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java index b72cc45a..0c7a7105 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java @@ -1,24 +1,25 @@ package me.chanjar.weixin.mp.api; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import me.chanjar.weixin.common.api.WxErrorExceptionHandler; +import me.chanjar.weixin.common.api.WxMessageDuplicateChecker; +import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker; import me.chanjar.weixin.common.session.InternalSession; import me.chanjar.weixin.common.session.InternalSessionManager; import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.util.LogExceptionHandler; -import me.chanjar.weixin.common.api.WxErrorExceptionHandler; -import me.chanjar.weixin.common.api.WxMessageDuplicateChecker; -import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker; import me.chanjar.weixin.mp.bean.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; /** *
@@ -155,7 +156,7 @@ public class WxMpMessageRouter {
     }
 
     WxMpXmlOutMessage res = null;
-    final List futures = new ArrayList<>();
+    final List> futures = new ArrayList<>();
     for (final WxMpMessageRouterRule rule : matchRules) {
       // 返回最后一个非异步的rule的执行结果
       if(rule.isAsync()) {
@@ -179,7 +180,7 @@ public class WxMpMessageRouter {
       this.executorService.submit(new Runnable() {
         @Override
         public void run() {
-          for (Future future : futures) {
+          for (Future future : futures) {
             try {
               future.get();
               WxMpMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUserName());
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XStreamTransformer.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XStreamTransformer.java
index 61ecac41..39e3d1dc 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XStreamTransformer.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XStreamTransformer.java
@@ -1,16 +1,25 @@
 package me.chanjar.weixin.mp.util.xml;
 
-import com.thoughtworks.xstream.XStream;
-import me.chanjar.weixin.common.util.xml.XStreamInitializer;
-import me.chanjar.weixin.mp.bean.*;
-
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
+import com.thoughtworks.xstream.XStream;
+
+import me.chanjar.weixin.common.util.xml.XStreamInitializer;
+import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.WxMpXmlOutImageMessage;
+import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
+import me.chanjar.weixin.mp.bean.WxMpXmlOutMusicMessage;
+import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
+import me.chanjar.weixin.mp.bean.WxMpXmlOutTextMessage;
+import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferCustomerServiceMessage;
+import me.chanjar.weixin.mp.bean.WxMpXmlOutVideoMessage;
+import me.chanjar.weixin.mp.bean.WxMpXmlOutVoiceMessage;
+
 public class XStreamTransformer {
 
-  protected static final Map CLASS_2_XSTREAM_INSTANCE = configXStreamInstance();
+  protected static final Map, XStream> CLASS_2_XSTREAM_INSTANCE = configXStreamInstance();
 
   /**
    * xml -> pojo
@@ -32,7 +41,7 @@ public class XStreamTransformer {
    * @param clz 类型
    * @param xStream xml解析器
    */
-  public static void register(Class clz,XStream xStream){
+  public static void register(Class clz, XStream xStream) {
     CLASS_2_XSTREAM_INSTANCE.put(clz,xStream);
   }
 
@@ -44,8 +53,8 @@ public class XStreamTransformer {
     return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object);
   }
 
-  private static Map configXStreamInstance() {
-    Map map = new HashMap<>();
+  private static Map, XStream> configXStreamInstance() {
+    Map, XStream> map = new HashMap<>();
     map.put(WxMpXmlMessage.class, config_WxMpXmlMessage());
     map.put(WxMpXmlOutMusicMessage.class, config_WxMpXmlOutMusicMessage());
     map.put(WxMpXmlOutNewsMessage.class, config_WxMpXmlOutNewsMessage());

From f13dcaa1fc09199925ecf7d3581cf1a19fe3a921 Mon Sep 17 00:00:00 2001
From: BinaryWang 
Date: Tue, 13 Sep 2016 19:54:03 +0800
Subject: [PATCH 40/49] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4?=
 =?UTF-8?q?=E6=A0=87=E7=AD=BE=E7=9A=84=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../weixin/mp/api/WxMpUserTagService.java     | 10 ++++++++++
 .../mp/api/impl/WxMpUserTagServiceImpl.java   | 20 +++++++++++++++++++
 .../api/impl/WxMpUserTagServiceImplTest.java  |  7 +++++++
 3 files changed, 37 insertions(+)

diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java
index 864d9cd0..bcf657fa 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java
@@ -45,4 +45,14 @@ public interface WxMpUserTagService {
    */
   Boolean tagUpdate(Integer id, String name) throws WxErrorException;
 
+  /**
+   * 
+   * 删除标签
+   * 详情请见:用户标签管理
+   * 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=ACCESS_TOKEN
+   * 
+ * + */ + Boolean tagDelete(Integer id) throws WxErrorException; + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java index 83c24042..c2167556 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java @@ -72,4 +72,24 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { throw new WxErrorException(wxError); } + + @Override + public Boolean tagDelete(Integer id) throws WxErrorException { + String url = API_URL_PREFIX + "/delete"; + + JsonObject json = new JsonObject(); + JsonObject tagJson = new JsonObject(); + tagJson.addProperty("id", id); + json.add("tag", tagJson); + + String responseContent = this.wxMpService.post(url, json.toString()); + this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(), + responseContent); + WxError wxError = WxError.fromJson(responseContent); + if (wxError.getErrorCode() == 0) { + return true; + } + + throw new WxErrorException(wxError); + } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java index 1aab8889..6471b88c 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java @@ -48,4 +48,11 @@ public class WxMpUserTagServiceImplTest { Assert.assertTrue(res); } + @Test(dependsOnMethods = { "testTagCreate" }) + public void testTagDelete() throws Exception { + Boolean res = this.wxService.getUserTagService().tagDelete(this.tagId); + System.out.println(res); + Assert.assertTrue(res); + } + } \ No newline at end of file From 5aa51e2f958167220812795d48095984fffd177e Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Tue, 13 Sep 2016 19:54:34 +0800 Subject: [PATCH 41/49] fix some warnings --- .../weixin/mp/api/WxMpBusyRetryTest.java | 19 +++++++++++-------- .../chanjar/weixin/mp/api/WxMpJsAPITest.java | 12 ++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java index c9edbdc5..a302cc2f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java @@ -1,17 +1,18 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.http.RequestExecutor; -import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.http.RequestExecutor; +import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; + @Test public class WxMpBusyRetryTest { @@ -20,7 +21,9 @@ public class WxMpBusyRetryTest { WxMpService service = new WxMpServiceImpl() { @Override - protected T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { + protected synchronized T executeInternal( + RequestExecutor executor, String uri, E data) + throws WxErrorException { WxError error = new WxError(); error.setErrorCode(-1); throw new WxErrorException(error); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java index c6a4556d..d4c49a0b 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java @@ -1,14 +1,14 @@ package me.chanjar.weixin.mp.api; -import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.crypto.SHA1; -import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import java.security.NoSuchAlgorithmException; +import com.google.inject.Inject; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.crypto.SHA1; +import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; /** * 测试jsapi ticket接口 @@ -29,7 +29,7 @@ public class WxMpJsAPITest { Assert.assertNotNull(jsapiTicket); } - public void test() throws NoSuchAlgorithmException { + public void test() { long timestamp = 1419835025l; String url = "http://omstest.vmall.com:23568/thirdparty/wechat/vcode/gotoshare?quantity=1&batchName=MATE7"; String noncestr = "82693e11-b9bc-448e-892f-f5289f46cd0f"; From 023ed9a2a14e6159388e911bfe95092188eebc74 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Wed, 14 Sep 2016 11:07:43 +0800 Subject: [PATCH 42/49] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=8F=B7proxy=E4=B8=BA=E7=A9=BA=E7=9A=84bug=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=A7=84=E8=8C=83=E8=8B=A5=E5=B9=B2=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E7=9A=84=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/cp/api/WxCpConfigStorage.java | 8 ++-- .../cp/api/WxCpInMemoryConfigStorage.java | 40 +++++++++---------- .../weixin/cp/api/WxCpJedisConfigStorage.java | 40 +++++++++---------- .../weixin/cp/api/WxCpServiceImpl.java | 10 +++-- 4 files changed, 50 insertions(+), 48 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java index 4e4ab238..b334b85b 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java @@ -55,13 +55,13 @@ public interface WxCpConfigStorage { String getOauth2redirectUri(); - String getHttp_proxy_host(); + String getHttpProxyHost(); - int getHttp_proxy_port(); + int getHttpProxyPort(); - String getHttp_proxy_username(); + String getHttpProxyUsername(); - String getHttp_proxy_password(); + String getHttpProxyPassword(); File getTmpDirFile(); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java index cd4a8575..17fda4ca 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java @@ -26,10 +26,10 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { protected volatile String oauth2redirectUri; - protected volatile String http_proxy_host; - protected volatile int http_proxy_port; - protected volatile String http_proxy_username; - protected volatile String http_proxy_password; + protected volatile String httpProxyHost; + protected volatile int httpProxyPort; + protected volatile String httpProxyUsername; + protected volatile String httpProxyPassword; protected volatile String jsapiTicket; protected volatile long jsapiTicketExpiresTime; @@ -166,39 +166,39 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { } @Override - public String getHttp_proxy_host() { - return this.http_proxy_host; + public String getHttpProxyHost() { + return this.httpProxyHost; } - public void setHttp_proxy_host(String http_proxy_host) { - this.http_proxy_host = http_proxy_host; + public void setHttpProxyHost(String httpProxyHost) { + this.httpProxyHost = httpProxyHost; } @Override - public int getHttp_proxy_port() { - return this.http_proxy_port; + public int getHttpProxyPort() { + return this.httpProxyPort; } - public void setHttp_proxy_port(int http_proxy_port) { - this.http_proxy_port = http_proxy_port; + public void setHttpProxyPort(int httpProxyPort) { + this.httpProxyPort = httpProxyPort; } @Override - public String getHttp_proxy_username() { - return this.http_proxy_username; + public String getHttpProxyUsername() { + return this.httpProxyUsername; } - public void setHttp_proxy_username(String http_proxy_username) { - this.http_proxy_username = http_proxy_username; + public void setHttpProxyUsername(String httpProxyUsername) { + this.httpProxyUsername = httpProxyUsername; } @Override - public String getHttp_proxy_password() { - return this.http_proxy_password; + public String getHttpProxyPassword() { + return this.httpProxyPassword; } - public void setHttp_proxy_password(String http_proxy_password) { - this.http_proxy_password = http_proxy_password; + public void setHttpProxyPassword(String httpProxyPassword) { + this.httpProxyPassword = httpProxyPassword; } @Override diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpJedisConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpJedisConfigStorage.java index 8d3b6bbd..5209479f 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpJedisConfigStorage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpJedisConfigStorage.java @@ -29,10 +29,10 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage { private volatile String oauth2redirectUri; - private volatile String http_proxy_host; - private volatile int http_proxy_port; - private volatile String http_proxy_username; - private volatile String http_proxy_password; + private volatile String httpProxyHost; + private volatile int httpProxyPort; + private volatile String httpProxyUsername; + private volatile String httpProxyPassword; private volatile File tmpDirFile; @@ -185,23 +185,23 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage { } @Override - public String getHttp_proxy_host() { - return this.http_proxy_host; + public String getHttpProxyHost() { + return this.httpProxyHost; } @Override - public int getHttp_proxy_port() { - return this.http_proxy_port; + public int getHttpProxyPort() { + return this.httpProxyPort; } @Override - public String getHttp_proxy_username() { - return this.http_proxy_username; + public String getHttpProxyUsername() { + return this.httpProxyUsername; } @Override - public String getHttp_proxy_password() { - return this.http_proxy_password; + public String getHttpProxyPassword() { + return this.httpProxyPassword; } @Override @@ -240,20 +240,20 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage { this.oauth2redirectUri = oauth2redirectUri; } - public void setHttp_proxy_host(String http_proxy_host) { - this.http_proxy_host = http_proxy_host; + public void setHttpProxyHost(String httpProxyHost) { + this.httpProxyHost = httpProxyHost; } - public void setHttp_proxy_port(int http_proxy_port) { - this.http_proxy_port = http_proxy_port; + public void setHttpProxyPort(int httpProxyPort) { + this.httpProxyPort = httpProxyPort; } - public void setHttp_proxy_username(String http_proxy_username) { - this.http_proxy_username = http_proxy_username; + public void setHttpProxyUsername(String httpProxyUsername) { + this.httpProxyUsername = httpProxyUsername; } - public void setHttp_proxy_password(String http_proxy_password) { - this.http_proxy_password = http_proxy_password; + public void setHttpProxyPassword(String httpProxyPassword) { + this.httpProxyPassword = httpProxyPassword; } public void setTmpDirFile(File tmpDirFile) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java index 741daf15..519aa2fc 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java @@ -626,11 +626,13 @@ public class WxCpServiceImpl implements WxCpService { apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get(); } apacheHttpClientBuilder - .httpProxyHost(this.wxCpConfigStorage.getHttp_proxy_host()) - .httpProxyPort(this.wxCpConfigStorage.getHttp_proxy_port()) - .httpProxyUsername(this.wxCpConfigStorage.getHttp_proxy_username()) - .httpProxyPassword(this.wxCpConfigStorage.getHttp_proxy_password()); + .httpProxyHost(this.wxCpConfigStorage.getHttpProxyHost()) + .httpProxyPort(this.wxCpConfigStorage.getHttpProxyPort()) + .httpProxyUsername(this.wxCpConfigStorage.getHttpProxyUsername()) + .httpProxyPassword(this.wxCpConfigStorage.getHttpProxyPassword()); + this.httpProxy = new HttpHost(this.wxCpConfigStorage.getHttpProxyHost(), + this.wxCpConfigStorage.getHttpProxyPort()); this.httpClient = apacheHttpClientBuilder.build(); } From 1d8326e7a1cc4f04177495f612e3f29a417e3bbd Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Wed, 14 Sep 2016 11:22:46 +0800 Subject: [PATCH 43/49] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=AC=E4=BC=97?= =?UTF-8?q?=E5=8F=B7proxy=E4=B8=BA=E7=A9=BA=E7=9A=84bug=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E4=B8=B4=E6=97=B6=E7=89=88=E6=9C=AC2.1.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- .../weixin/mp/api/impl/WxMpServiceImpl.java | 128 +++++++++++------- 5 files changed, 86 insertions(+), 50 deletions(-) diff --git a/pom.xml b/pom.xml index 357471f9..7ca43e66 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.1.1 + 2.1.2 pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index d77b70b8..54922f7f 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.1.1 + 2.1.2 weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 2aa6f0fe..9de144fe 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.1.1 + 2.1.2 weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index fedbba6e..0cfb1048 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.1.1 + 2.1.2 weixin-java-mp WeiXin Java Tools - MP diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java index e08432b9..deddaab6 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java @@ -1,9 +1,23 @@ package me.chanjar.weixin.mp.api.impl; +import java.io.IOException; + +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.BasicResponseHandler; +import org.apache.http.impl.client.CloseableHttpClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; + import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.result.WxError; @@ -12,22 +26,38 @@ import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.util.RandomUtils; import me.chanjar.weixin.common.util.crypto.SHA1; -import me.chanjar.weixin.common.util.http.*; -import me.chanjar.weixin.mp.api.*; -import me.chanjar.weixin.mp.bean.*; -import me.chanjar.weixin.mp.bean.result.*; -import org.apache.http.HttpHost; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.ssl.DefaultHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.BasicResponseHandler; -import org.apache.http.impl.client.CloseableHttpClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; +import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; +import me.chanjar.weixin.common.util.http.DefaultApacheHttpClientBuilder; +import me.chanjar.weixin.common.util.http.RequestExecutor; +import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; +import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; +import me.chanjar.weixin.common.util.http.URIUtil; +import me.chanjar.weixin.mp.api.WxMpCardService; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.mp.api.WxMpDataCubeService; +import me.chanjar.weixin.mp.api.WxMpGroupService; +import me.chanjar.weixin.mp.api.WxMpKefuService; +import me.chanjar.weixin.mp.api.WxMpMaterialService; +import me.chanjar.weixin.mp.api.WxMpMenuService; +import me.chanjar.weixin.mp.api.WxMpPayService; +import me.chanjar.weixin.mp.api.WxMpQrcodeService; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.WxMpUserService; +import me.chanjar.weixin.mp.api.WxMpUserTagService; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; +import me.chanjar.weixin.mp.bean.WxMpIndustry; +import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage; +import me.chanjar.weixin.mp.bean.WxMpMassNews; +import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; +import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage; +import me.chanjar.weixin.mp.bean.WxMpMassVideo; +import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; +import me.chanjar.weixin.mp.bean.WxMpTemplateMessage; +import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; +import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; +import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; +import me.chanjar.weixin.mp.bean.result.WxMpUser; public class WxMpServiceImpl implements WxMpService { @@ -45,7 +75,7 @@ public class WxMpServiceImpl implements WxMpService { */ private final Object globalJsapiTicketRefreshLock = new Object(); - private WxMpConfigStorage wxMpConfigStorage; + private WxMpConfigStorage configStorage; private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); @@ -80,7 +110,8 @@ public class WxMpServiceImpl implements WxMpService { @Override public boolean checkSignature(String timestamp, String nonce, String signature) { try { - return SHA1.gen(this.wxMpConfigStorage.getToken(), timestamp, nonce).equals(signature); + return SHA1.gen(this.configStorage.getToken(), timestamp, nonce) + .equals(signature); } catch (Exception e) { return false; } @@ -94,14 +125,14 @@ public class WxMpServiceImpl implements WxMpService { @Override public String getAccessToken(boolean forceRefresh) throws WxErrorException { if (forceRefresh) { - this.wxMpConfigStorage.expireAccessToken(); + this.configStorage.expireAccessToken(); } - if (this.wxMpConfigStorage.isAccessTokenExpired()) { + if (this.configStorage.isAccessTokenExpired()) { synchronized (this.globalAccessTokenRefreshLock) { - if (this.wxMpConfigStorage.isAccessTokenExpired()) { + if (this.configStorage.isAccessTokenExpired()) { String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" + - "&appid=" + this.wxMpConfigStorage.getAppId() + - "&secret=" + this.wxMpConfigStorage.getSecret(); + "&appid=" + this.configStorage.getAppId() + "&secret=" + + this.configStorage.getSecret(); try { HttpGet httpGet = new HttpGet(url); if (this.httpProxy != null) { @@ -115,7 +146,8 @@ public class WxMpServiceImpl implements WxMpService { throw new WxErrorException(error); } WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); - this.wxMpConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn()); + this.configStorage.updateAccessToken(accessToken.getAccessToken(), + accessToken.getExpiresIn()); }finally { httpGet.releaseConnection(); } @@ -125,7 +157,7 @@ public class WxMpServiceImpl implements WxMpService { } } } - return this.wxMpConfigStorage.getAccessToken(); + return this.configStorage.getAccessToken(); } @Override @@ -136,23 +168,23 @@ public class WxMpServiceImpl implements WxMpService { @Override public String getJsapiTicket(boolean forceRefresh) throws WxErrorException { if (forceRefresh) { - this.wxMpConfigStorage.expireJsapiTicket(); + this.configStorage.expireJsapiTicket(); } - if (this.wxMpConfigStorage.isJsapiTicketExpired()) { + if (this.configStorage.isJsapiTicketExpired()) { synchronized (this.globalJsapiTicketRefreshLock) { - if (this.wxMpConfigStorage.isJsapiTicketExpired()) { + if (this.configStorage.isJsapiTicketExpired()) { String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi"; String responseContent = execute(new SimpleGetRequestExecutor(), url, null); JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); String jsapiTicket = tmpJsonObject.get("ticket").getAsString(); int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt(); - this.wxMpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds); + this.configStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds); } } } - return this.wxMpConfigStorage.getJsapiTicket(); + return this.configStorage.getJsapiTicket(); } @Override @@ -163,7 +195,7 @@ public class WxMpServiceImpl implements WxMpService { String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket, "noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url); WxJsapiSignature jsapiSignature = new WxJsapiSignature(); - jsapiSignature.setAppid(this.wxMpConfigStorage.getAppId()); + jsapiSignature.setAppid(this.configStorage.getAppId()); jsapiSignature.setTimestamp(timestamp); jsapiSignature.setNoncestr(noncestr); jsapiSignature.setUrl(url); @@ -264,7 +296,7 @@ public class WxMpServiceImpl implements WxMpService { public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) { StringBuilder url = new StringBuilder(); url.append("https://open.weixin.qq.com/connect/oauth2/authorize?"); - url.append("appid=").append(this.wxMpConfigStorage.getAppId()); + url.append("appid=").append(this.configStorage.getAppId()); url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI)); url.append("&response_type=code"); url.append("&scope=").append(scope); @@ -280,7 +312,7 @@ public class WxMpServiceImpl implements WxMpService { String state) { StringBuilder url = new StringBuilder(); url.append("https://open.weixin.qq.com/connect/qrconnect?"); - url.append("appid=").append(this.wxMpConfigStorage.getAppId()); + url.append("appid=").append(this.configStorage.getAppId()); url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI)); url.append("&response_type=code"); url.append("&scope=").append(scope); @@ -306,8 +338,8 @@ public class WxMpServiceImpl implements WxMpService { public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException { StringBuilder url = new StringBuilder(); url.append("https://api.weixin.qq.com/sns/oauth2/access_token?"); - url.append("appid=").append(this.wxMpConfigStorage.getAppId()); - url.append("&secret=").append(this.wxMpConfigStorage.getSecret()); + url.append("appid=").append(this.configStorage.getAppId()); + url.append("&secret=").append(this.configStorage.getSecret()); url.append("&code=").append(code); url.append("&grant_type=authorization_code"); @@ -318,7 +350,7 @@ public class WxMpServiceImpl implements WxMpService { public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException { StringBuilder url = new StringBuilder(); url.append("https://api.weixin.qq.com/sns/oauth2/refresh_token?"); - url.append("appid=").append(this.wxMpConfigStorage.getAppId()); + url.append("appid=").append(this.configStorage.getAppId()); url.append("&grant_type=refresh_token"); url.append("&refresh_token=").append(refreshToken); @@ -438,7 +470,7 @@ public class WxMpServiceImpl implements WxMpService { */ if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) { // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token - this.wxMpConfigStorage.expireAccessToken(); + this.configStorage.expireAccessToken(); return execute(executor, uri, data); } if (error.getErrorCode() != 0) { @@ -460,33 +492,37 @@ public class WxMpServiceImpl implements WxMpService { @Override public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) { - this.wxMpConfigStorage = wxConfigProvider; + this.configStorage = wxConfigProvider; this.initHttpClient(); } private void initHttpClient() { - ApacheHttpClientBuilder apacheHttpClientBuilder = this.wxMpConfigStorage.getApacheHttpClientBuilder(); + ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage + .getApacheHttpClientBuilder(); if (null == apacheHttpClientBuilder) { apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get(); } - apacheHttpClientBuilder.httpProxyHost(this.wxMpConfigStorage.getHttpProxyHost()) - .httpProxyPort(this.wxMpConfigStorage.getHttpProxyPort()) - .httpProxyUsername(this.wxMpConfigStorage.getHttpProxyUsername()) - .httpProxyPassword(this.wxMpConfigStorage.getHttpProxyPassword()); + apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost()) + .httpProxyPort(this.configStorage.getHttpProxyPort()) + .httpProxyUsername(this.configStorage.getHttpProxyUsername()) + .httpProxyPassword(this.configStorage.getHttpProxyPassword()); - if (this.wxMpConfigStorage.getSSLContext() != null){ + if (this.configStorage.getSSLContext() != null) { SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - this.wxMpConfigStorage.getSSLContext(), new String[] { "TLSv1" }, null, new DefaultHostnameVerifier()); + this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null, + new DefaultHostnameVerifier()); apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf); } + this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), + this.configStorage.getHttpProxyPort()); this.httpClient = apacheHttpClientBuilder.build(); } @Override public WxMpConfigStorage getWxMpConfigStorage() { - return this.wxMpConfigStorage; + return this.configStorage; } @Override From 6d3b065f32174824886f0d70d44659f10cf7082c Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 14 Sep 2016 14:31:10 +0800 Subject: [PATCH 44/49] =?UTF-8?q?=E5=A2=9E=E5=8A=A0editorconfig=E6=96=87?= =?UTF-8?q?=E4=BB=B6,=E7=BB=9F=E4=B8=80=E8=AE=BE=E7=BD=AE=E7=BC=A9?= =?UTF-8?q?=E8=BF=9B=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..50339b8e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# EditorConfig: http://editorconfig.org/ + +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false From 15f17b2a27f627662d705ac9159898fc0466e38c Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 14 Sep 2016 16:39:37 +0800 Subject: [PATCH 45/49] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BE=E7=BD=AEsetCo?= =?UTF-8?q?nnectionManagerShared=E5=8F=82=E6=95=B0=E9=81=BF=E5=85=8DPoolin?= =?UTF-8?q?gHttpClientConnectionManager=E8=A2=ABCloseableHttpClient?= =?UTF-8?q?=E8=BF=9E=E5=B8=A6=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../http/DefaultApacheHttpClientBuilder.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java index f01d0d9e..f69dcc6c 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java @@ -1,8 +1,6 @@ package me.chanjar.weixin.common.util.http; -import java.io.IOException; -import java.util.concurrent.TimeUnit; - +import me.chanjar.weixin.common.util.StringUtils; import org.apache.http.annotation.NotThreadSafe; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; @@ -23,7 +21,8 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.protocol.HttpContext; -import me.chanjar.weixin.common.util.StringUtils; +import java.io.IOException; +import java.util.concurrent.TimeUnit; /** * httpclient 连接管理器 @@ -104,44 +103,45 @@ public class DefaultApacheHttpClientBuilder implements ApacheHttpClientBuilder { private void prepare() { Registry registry = RegistryBuilder.create() - .register("http", this.plainConnectionSocketFactory) - .register("https", this.sslConnectionSocketFactory) - .build(); + .register("http", this.plainConnectionSocketFactory) + .register("https", this.sslConnectionSocketFactory) + .build(); @SuppressWarnings("resource") PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry); connectionManager.setMaxTotal(this.maxTotalConn); connectionManager.setDefaultMaxPerRoute(this.maxConnPerHost); connectionManager.setDefaultSocketConfig( - SocketConfig.copy(SocketConfig.DEFAULT) - .setSoTimeout(this.soTimeout) - .build() + SocketConfig.copy(SocketConfig.DEFAULT) + .setSoTimeout(this.soTimeout) + .build() ); this.idleConnectionMonitorThread = new IdleConnectionMonitorThread( - connectionManager, this.idleConnTimeout, this.checkWaitTime); + connectionManager, this.idleConnTimeout, this.checkWaitTime); this.idleConnectionMonitorThread.setDaemon(true); this.idleConnectionMonitorThread.start(); this.httpClientBuilder = HttpClients.custom() - .setConnectionManager(connectionManager) - .setDefaultRequestConfig( - RequestConfig.custom() - .setSocketTimeout(this.soTimeout) - .setConnectTimeout(this.connectionTimeout) - .setConnectionRequestTimeout(this.connectionRequestTimeout) - .build() - ) - .setRetryHandler(this.httpRequestRetryHandler); + .setConnectionManager(connectionManager) + .setConnectionManagerShared(true) + .setDefaultRequestConfig( + RequestConfig.custom() + .setSocketTimeout(this.soTimeout) + .setConnectTimeout(this.connectionTimeout) + .setConnectionRequestTimeout(this.connectionRequestTimeout) + .build() + ) + .setRetryHandler(this.httpRequestRetryHandler); if (StringUtils.isNotBlank(this.httpProxyHost) - && StringUtils.isNotBlank(this.httpProxyUsername)) { + && StringUtils.isNotBlank(this.httpProxyUsername)) { // 使用代理服务器 需要用户认证的代理服务器 CredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials( - new AuthScope(this.httpProxyHost, this.httpProxyPort), - new UsernamePasswordCredentials(this.httpProxyUsername, - this.httpProxyPassword)); + new AuthScope(this.httpProxyHost, this.httpProxyPort), + new UsernamePasswordCredentials(this.httpProxyUsername, + this.httpProxyPassword)); this.httpClientBuilder.setDefaultCredentialsProvider(provider); } @@ -182,7 +182,7 @@ public class DefaultApacheHttpClientBuilder implements ApacheHttpClientBuilder { wait(this.checkWaitTime); this.connMgr.closeExpiredConnections(); this.connMgr.closeIdleConnections(this.idleConnTimeout, - TimeUnit.MILLISECONDS); + TimeUnit.MILLISECONDS); } } } catch (InterruptedException ignore) { From 21f14971c13a8edbfc2037b51d53d8aa31242e76 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 16 Sep 2016 21:52:40 +0800 Subject: [PATCH 46/49] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E8=AE=BE=E7=BD=AE=E6=97=B6=E4=BC=9A=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/cp/api/WxCpServiceImpl.java | 70 ++++++++++--------- .../weixin/cp/api/WxCpBaseAPITest.java | 10 +-- .../weixin/cp/api/WxCpMessageAPITest.java | 10 +-- .../weixin/mp/api/impl/WxMpServiceImpl.java | 6 +- 4 files changed, 52 insertions(+), 44 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java index 519aa2fc..e3723a71 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java @@ -65,7 +65,7 @@ public class WxCpServiceImpl implements WxCpService { */ protected final Object globalJsapiTicketRefreshLock = new Object(); - protected WxCpConfigStorage wxCpConfigStorage; + protected WxCpConfigStorage configStorage; protected CloseableHttpClient httpClient; @@ -81,7 +81,7 @@ public class WxCpServiceImpl implements WxCpService { @Override public boolean checkSignature(String msgSignature, String timestamp, String nonce, String data) { try { - return SHA1.gen(this.wxCpConfigStorage.getToken(), timestamp, nonce, data) + return SHA1.gen(this.configStorage.getToken(), timestamp, nonce, data) .equals(msgSignature); } catch (Exception e) { return false; @@ -102,14 +102,14 @@ public class WxCpServiceImpl implements WxCpService { @Override public String getAccessToken(boolean forceRefresh) throws WxErrorException { if (forceRefresh) { - this.wxCpConfigStorage.expireAccessToken(); + this.configStorage.expireAccessToken(); } - if (this.wxCpConfigStorage.isAccessTokenExpired()) { + if (this.configStorage.isAccessTokenExpired()) { synchronized (this.globalAccessTokenRefreshLock) { - if (this.wxCpConfigStorage.isAccessTokenExpired()) { + if (this.configStorage.isAccessTokenExpired()) { String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?" - + "&corpid=" + this.wxCpConfigStorage.getCorpId() + "&corpsecret=" - + this.wxCpConfigStorage.getCorpSecret(); + + "&corpid=" + this.configStorage.getCorpId() + + "&corpsecret=" + this.configStorage.getCorpSecret(); try { HttpGet httpGet = new HttpGet(url); if (this.httpProxy != null) { @@ -129,7 +129,7 @@ public class WxCpServiceImpl implements WxCpService { throw new WxErrorException(error); } WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); - this.wxCpConfigStorage.updateAccessToken( + this.configStorage.updateAccessToken( accessToken.getAccessToken(), accessToken.getExpiresIn()); } catch (ClientProtocolException e) { throw new RuntimeException(e); @@ -139,7 +139,7 @@ public class WxCpServiceImpl implements WxCpService { } } } - return this.wxCpConfigStorage.getAccessToken(); + return this.configStorage.getAccessToken(); } @Override @@ -150,23 +150,23 @@ public class WxCpServiceImpl implements WxCpService { @Override public String getJsapiTicket(boolean forceRefresh) throws WxErrorException { if (forceRefresh) { - this.wxCpConfigStorage.expireJsapiTicket(); + this.configStorage.expireJsapiTicket(); } - if (this.wxCpConfigStorage.isJsapiTicketExpired()) { + if (this.configStorage.isJsapiTicketExpired()) { synchronized (this.globalJsapiTicketRefreshLock) { - if (this.wxCpConfigStorage.isJsapiTicketExpired()) { + if (this.configStorage.isJsapiTicketExpired()) { String url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket"; String responseContent = execute(new SimpleGetRequestExecutor(), url, null); JsonElement tmpJsonElement = new JsonParser().parse(responseContent); JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); String jsapiTicket = tmpJsonObject.get("ticket").getAsString(); int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt(); - this.wxCpConfigStorage.updateJsapiTicket(jsapiTicket, + this.configStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds); } } } - return this.wxCpConfigStorage.getJsapiTicket(); + return this.configStorage.getJsapiTicket(); } @Override @@ -187,7 +187,7 @@ public class WxCpServiceImpl implements WxCpService { jsapiSignature.setSignature(signature); // Fixed bug - jsapiSignature.setAppid(this.wxCpConfigStorage.getCorpId()); + jsapiSignature.setAppid(this.configStorage.getCorpId()); return jsapiSignature; } @@ -200,19 +200,19 @@ public class WxCpServiceImpl implements WxCpService { @Override public void menuCreate(WxMenu menu) throws WxErrorException { - menuCreate(this.wxCpConfigStorage.getAgentId(), menu); + menuCreate(this.configStorage.getAgentId(), menu); } @Override public void menuCreate(String agentId, WxMenu menu) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid=" - + this.wxCpConfigStorage.getAgentId(); + + this.configStorage.getAgentId(); post(url, menu.toJson()); } @Override public void menuDelete() throws WxErrorException { - menuDelete(this.wxCpConfigStorage.getAgentId()); + menuDelete(this.configStorage.getAgentId()); } @Override @@ -223,7 +223,7 @@ public class WxCpServiceImpl implements WxCpService { @Override public WxMenu menuGet() throws WxErrorException { - return menuGet(this.wxCpConfigStorage.getAgentId()); + return menuGet(this.configStorage.getAgentId()); } @Override @@ -258,7 +258,7 @@ public class WxCpServiceImpl implements WxCpService { String url = "https://qyapi.weixin.qq.com/cgi-bin/media/get"; return execute( new MediaDownloadRequestExecutor( - this.wxCpConfigStorage.getTmpDirFile()), +this.configStorage.getTmpDirFile()), url, "media_id=" + media_id); } @@ -475,7 +475,7 @@ public class WxCpServiceImpl implements WxCpService { @Override public String oauth2buildAuthorizationUrl(String state) { return this.oauth2buildAuthorizationUrl( - this.wxCpConfigStorage.getOauth2redirectUri(), +this.configStorage.getOauth2redirectUri(), state ); } @@ -483,7 +483,7 @@ public class WxCpServiceImpl implements WxCpService { @Override public String oauth2buildAuthorizationUrl(String redirectUri, String state) { String url = "https://open.weixin.qq.com/connect/oauth2/authorize?"; - url += "appid=" + this.wxCpConfigStorage.getCorpId(); + url += "appid=" + this.configStorage.getCorpId(); url += "&redirect_uri=" + URIUtil.encodeURIComponent(redirectUri); url += "&response_type=code"; url += "&scope=snsapi_base"; @@ -496,7 +496,7 @@ public class WxCpServiceImpl implements WxCpService { @Override public String[] oauth2getUserInfo(String code) throws WxErrorException { - return oauth2getUserInfo(this.wxCpConfigStorage.getAgentId(), code); + return oauth2getUserInfo(this.configStorage.getAgentId(), code); } @Override @@ -599,7 +599,7 @@ public class WxCpServiceImpl implements WxCpService { */ if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) { // 强制设置wxCpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token - this.wxCpConfigStorage.expireAccessToken(); + this.configStorage.expireAccessToken(); return execute(executor, uri, data); } if (error.getErrorCode() != 0) { @@ -619,20 +619,22 @@ public class WxCpServiceImpl implements WxCpService { @Override public void setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider) { - this.wxCpConfigStorage = wxConfigProvider; - ApacheHttpClientBuilder apacheHttpClientBuilder = this.wxCpConfigStorage + this.configStorage = wxConfigProvider; + ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage .getApacheHttpClientBuilder(); if (null == apacheHttpClientBuilder) { apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get(); } - apacheHttpClientBuilder - .httpProxyHost(this.wxCpConfigStorage.getHttpProxyHost()) - .httpProxyPort(this.wxCpConfigStorage.getHttpProxyPort()) - .httpProxyUsername(this.wxCpConfigStorage.getHttpProxyUsername()) - .httpProxyPassword(this.wxCpConfigStorage.getHttpProxyPassword()); - - this.httpProxy = new HttpHost(this.wxCpConfigStorage.getHttpProxyHost(), - this.wxCpConfigStorage.getHttpProxyPort()); + + apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost()) + .httpProxyPort(this.configStorage.getHttpProxyPort()) + .httpProxyUsername(this.configStorage.getHttpProxyUsername()) + .httpProxyPassword(this.configStorage.getHttpProxyPassword()); + + if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) { + this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort()); + } + this.httpClient = apacheHttpClientBuilder.build(); } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java index d2ac69e8..d2eb2ec6 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java @@ -1,12 +1,14 @@ package me.chanjar.weixin.cp.api; -import com.google.inject.Inject; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.StringUtils; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; +import com.google.inject.Inject; + +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.StringUtils; + /** * 基础API测试 * @@ -20,7 +22,7 @@ public class WxCpBaseAPITest { protected WxCpServiceImpl wxService; public void testRefreshAccessToken() throws WxErrorException { - WxCpConfigStorage configStorage = this.wxService.wxCpConfigStorage; + WxCpConfigStorage configStorage = this.wxService.configStorage; String before = configStorage.getAccessToken(); this.wxService.getAccessToken(false); diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java index 8bfe07e6..b7bcf7a3 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java @@ -1,11 +1,13 @@ package me.chanjar.weixin.cp.api; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + import com.google.inject.Inject; + import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.cp.bean.WxCpMessage; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; /*** * 测试发送消息 @@ -20,7 +22,7 @@ public class WxCpMessageAPITest { protected WxCpServiceImpl wxService; public void testSendCustomMessage() throws WxErrorException { - ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlCpInMemoryConfigStorage) this.wxService.wxCpConfigStorage; + ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlCpInMemoryConfigStorage) this.wxService.configStorage; WxCpMessage message1 = new WxCpMessage(); message1.setAgentId(configStorage.getAgentId()); message1.setMsgType(WxConsts.CUSTOM_MSG_TEXT); @@ -32,7 +34,7 @@ public class WxCpMessageAPITest { .TEXT() .agentId(configStorage.getAgentId()) .toUser(configStorage.getUserId()) - .content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World") + .content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World") .build(); this.wxService.messageSend(message2); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java index deddaab6..2bff6482 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java @@ -515,8 +515,10 @@ public class WxMpServiceImpl implements WxMpService { apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf); } - this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), - this.configStorage.getHttpProxyPort()); + if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) { + this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort()); + } + this.httpClient = apacheHttpClientBuilder.build(); } From b17041ea96ff87f5ad9fd8be79dbd17e221a904a Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Mon, 19 Sep 2016 16:03:21 +0800 Subject: [PATCH 47/49] =?UTF-8?q?=E5=8F=91=E9=80=81=E5=AE=A2=E6=9C=8D?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A5=E5=8F=A3=E8=BD=AC=E7=A7=BB=E5=88=B0?= =?UTF-8?q?=E5=AE=A2=E6=9C=8D=E4=B8=93=E7=94=A8service=E4=B8=AD=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=97=B6=E9=9C=80=E8=A6=81=E5=8A=A0=E5=85=A5?= =?UTF-8?q?getKefuService()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpKefuService.java | 22 ++++- .../me/chanjar/weixin/mp/api/WxMpService.java | 9 -- .../mp/api/impl/WxMpKefuServiceImpl.java | 87 +++++++++++++------ .../weixin/mp/api/impl/WxMpServiceImpl.java | 7 -- .../mp/api/WxMpCustomMessageAPITest.java | 44 ---------- .../mp/api/impl/WxMpKefuServiceImplTest.java | 29 ++++++- .../mp/demo/DemoGuessNumberHandler.java | 18 ++-- 7 files changed, 115 insertions(+), 101 deletions(-) delete mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpCustomMessageAPITest.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java index c4731cb5..fc678b42 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java @@ -1,12 +1,18 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; -import me.chanjar.weixin.mp.bean.kefu.result.*; - import java.io.File; import java.util.Date; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; +import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; +import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList; +import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfMsgList; +import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList; +import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionGetResult; +import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionList; +import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList; + /** * 客服接口 , * 命名采用kefu拼音的原因是: @@ -17,6 +23,14 @@ import java.util.Date; */ public interface WxMpKefuService { + /** + *
+   * 发送客服消息
+   * 详情请见: 发送客服消息
+   * 
+ */ + boolean customMessageSend(WxMpCustomMessage message) throws WxErrorException; + //*******************客服管理接口***********************// /** diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 077488b7..952cf8f5 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -3,7 +3,6 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; -import me.chanjar.weixin.mp.bean.WxMpCustomMessage; import me.chanjar.weixin.mp.bean.WxMpIndustry; import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage; import me.chanjar.weixin.mp.bean.WxMpMassNews; @@ -82,14 +81,6 @@ public interface WxMpService { */ WxJsapiSignature createJsapiSignature(String url) throws WxErrorException; - /** - *
-   * 发送客服消息
-   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=发送客服消息
-   * 
- */ - void customMessageSend(WxMpCustomMessage message) throws WxErrorException; - /** *
    * 上传群发用的图文消息,上传后才能群发图文消息
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java
index 6d6cf14c..b65fdeaa 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java
@@ -3,15 +3,18 @@ package me.chanjar.weixin.mp.api.impl;
 import java.io.File;
 import java.util.Date;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.google.gson.JsonObject;
 
 import me.chanjar.weixin.common.bean.result.WxError;
+import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
 import me.chanjar.weixin.common.exception.WxErrorException;
 import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
-import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
-import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
 import me.chanjar.weixin.mp.api.WxMpKefuService;
 import me.chanjar.weixin.mp.api.WxMpService;
+import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
 import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
 import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfSessionRequest;
 import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList;
@@ -27,6 +30,8 @@ import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList;
  *
  */
 public class WxMpKefuServiceImpl implements WxMpKefuService {
+  protected final Logger log = LoggerFactory
+      .getLogger(WxMpKefuServiceImpl.class);
   private static final String API_URL_PREFIX = "https://api.weixin.qq.com/customservice";
   private WxMpService wxMpService;
 
@@ -34,19 +39,31 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
     this.wxMpService = wxMpService;
   }
 
+  @Override
+  public boolean customMessageSend(WxMpCustomMessage message)
+      throws WxErrorException {
+    String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send";
+    String responseContent = this.wxMpService.post(url, message.toJson());
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, message.toJson(),
+        responseContent);
+    return true;
+  }
+
   @Override
   public WxMpKfList kfList() throws WxErrorException {
-    String url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist";
-    String responseContent = this.wxMpService
-        .execute(new SimpleGetRequestExecutor(), url, null);
+    String url = API_URL_PREFIX + "/getkflist";
+    String responseContent = this.wxMpService.get(url, null);
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
+        responseContent);
     return WxMpKfList.fromJson(responseContent);
   }
 
   @Override
   public WxMpKfOnlineList kfOnlineList() throws WxErrorException {
-    String url = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist";
-    String responseContent = this.wxMpService
-        .execute(new SimpleGetRequestExecutor(), url, null);
+    String url = API_URL_PREFIX + "/getonlinekflist";
+    String responseContent = this.wxMpService.get(url, null);
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
+        responseContent);
     return WxMpKfOnlineList.fromJson(responseContent);
   }
 
@@ -54,8 +71,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
   public boolean kfAccountAdd(WxMpKfAccountRequest request)
       throws WxErrorException {
     String url = API_URL_PREFIX + "/kfaccount/add";
-    this.wxMpService.execute(new SimplePostRequestExecutor(), url,
-        request.toJson());
+    String responseContent = this.wxMpService.post(url, request.toJson());
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, request.toJson(),
+        responseContent);
     return true;
   }
 
@@ -63,16 +81,18 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
   public boolean kfAccountUpdate(WxMpKfAccountRequest request)
       throws WxErrorException {
     String url = API_URL_PREFIX + "/kfaccount/update";
-    this.wxMpService.execute(new SimplePostRequestExecutor(), url,
-        request.toJson());
+    String responseContent = this.wxMpService.post(url, request.toJson());
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, request.toJson(),
+        responseContent);
     return true;
   }
 
   @Override
   public boolean kfAccountInviteWorker(WxMpKfAccountRequest request) throws WxErrorException {
     String url = API_URL_PREFIX + "/kfaccount/inviteworker";
-    this.wxMpService.execute(new SimplePostRequestExecutor(), url,
-            request.toJson());
+    String responseContent = this.wxMpService.post(url, request.toJson());
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, request.toJson(),
+        responseContent);
     return true;
   }
 
@@ -80,14 +100,20 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
   public boolean kfAccountUploadHeadImg(String kfAccount, File imgFile)
       throws WxErrorException {
     String url = API_URL_PREFIX + "/kfaccount/uploadheadimg?kf_account=" + kfAccount;
-    this.wxMpService.execute(new MediaUploadRequestExecutor(), url, imgFile);
+    WxMediaUploadResult responseContent = this.wxMpService
+        .execute(new MediaUploadRequestExecutor(), url, imgFile);
+    this.log.debug("\nurl:{}\nparams:{}&file:{}\nresponse:{}", url, kfAccount,
+        imgFile.getAbsolutePath(),
+        responseContent);
     return true;
   }
 
   @Override
   public boolean kfAccountDel(String kfAccount) throws WxErrorException {
     String url = API_URL_PREFIX + "/kfaccount/del?kf_account=" + kfAccount;
-    this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null);
+    String responseContent = this.wxMpService.get(url, null);
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
+        responseContent);
     return true;
   }
 
@@ -96,8 +122,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
       throws WxErrorException {
     WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid);
     String url = API_URL_PREFIX + "/kfsession/create";
-    this.wxMpService.execute(new SimplePostRequestExecutor(), url,
-        request.toJson());
+    String responseContent = this.wxMpService.post(url, request.toJson());
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, request.toJson(),
+        responseContent);
     return true;
   }
 
@@ -106,8 +133,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
       throws WxErrorException {
     WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid);
     String url = API_URL_PREFIX + "/kfsession/close";
-    this.wxMpService.execute(new SimplePostRequestExecutor(), url,
-        request.toJson());
+    String responseContent = this.wxMpService.post(url, request.toJson());
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, request.toJson(),
+        responseContent);
     return true;
   }
 
@@ -115,8 +143,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
   public WxMpKfSessionGetResult kfSessionGet(String openid)
       throws WxErrorException {
     String url = API_URL_PREFIX + "/kfsession/getsession?openid=" + openid;
-    String responseContent = this.wxMpService
-        .execute(new SimpleGetRequestExecutor(), url, null);
+    String responseContent = this.wxMpService.get(url, null);
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
+        responseContent);
     return WxMpKfSessionGetResult.fromJson(responseContent);
   }
 
@@ -124,8 +153,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
   public WxMpKfSessionList kfSessionList(String kfAccount)
       throws WxErrorException {
     String url = API_URL_PREFIX + "/kfsession/getsessionlist?kf_account=" + kfAccount;
-    String responseContent = this.wxMpService
-        .execute(new SimpleGetRequestExecutor(), url, null);
+    String responseContent = this.wxMpService.get(url, null);
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
+        responseContent);
     return WxMpKfSessionList.fromJson(responseContent);
   }
 
@@ -133,8 +163,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
   public WxMpKfSessionWaitCaseList kfSessionGetWaitCase()
       throws WxErrorException {
     String url = API_URL_PREFIX + "/kfsession/getwaitcase";
-    String responseContent = this.wxMpService
-        .execute(new SimpleGetRequestExecutor(), url, null);
+    String responseContent = this.wxMpService.get(url, null);
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
+        responseContent);
     return WxMpKfSessionWaitCaseList.fromJson(responseContent);
   }
 
@@ -156,7 +187,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
     param.addProperty("msgid", msgId); //msgid	消息id顺序从小到大,从1开始
     param.addProperty("number", number); //number	每次获取条数,最多10000条
 
-    String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, param.toString());
+    String responseContent = this.wxMpService.post(url, param.toString());
+    this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, param.toString(),
+        responseContent);
     return WxMpKfMsgList.fromJson(responseContent);
   }
 
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java
index 2bff6482..3f2c9808 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java
@@ -44,7 +44,6 @@ import me.chanjar.weixin.mp.api.WxMpQrcodeService;
 import me.chanjar.weixin.mp.api.WxMpService;
 import me.chanjar.weixin.mp.api.WxMpUserService;
 import me.chanjar.weixin.mp.api.WxMpUserTagService;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
 import me.chanjar.weixin.mp.bean.WxMpIndustry;
 import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
 import me.chanjar.weixin.mp.bean.WxMpMassNews;
@@ -203,12 +202,6 @@ public class WxMpServiceImpl implements WxMpService {
     return jsapiSignature;
   }
 
-  @Override
-  public void customMessageSend(WxMpCustomMessage message) throws WxErrorException {
-    String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send";
-    execute(new SimplePostRequestExecutor(), url, message.toJson());
-  }
-
   @Override
   public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews";
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpCustomMessageAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpCustomMessageAPITest.java
deleted file mode 100644
index 730ab726..00000000
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpCustomMessageAPITest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package me.chanjar.weixin.mp.api;
-
-import com.google.inject.Inject;
-import me.chanjar.weixin.common.api.WxConsts;
-import me.chanjar.weixin.common.exception.WxErrorException;
-import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
-import org.testng.annotations.Guice;
-import org.testng.annotations.Test;
-
-/***
- * 测试发送客服消息
- * @author chanjarster
- *
- */
-@Test(groups="customMessageAPI")
-@Guice(modules = ApiTestModule.class)
-public class WxMpCustomMessageAPITest {
-
-  @Inject
-  protected WxMpServiceImpl wxService;
-
-  public void testSendCustomMessage() throws WxErrorException {
-    ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage();
-    WxMpCustomMessage message = new WxMpCustomMessage();
-    message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
-    message.setToUser(configStorage.getOpenId());
-    message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World");
-
-    this.wxService.customMessageSend(message);
-  }
-
-  public void testSendCustomMessageWithKfAccount() throws WxErrorException {
-    ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage();
-    WxMpCustomMessage message = new WxMpCustomMessage();
-    message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
-    message.setToUser(configStorage.getOpenId());
-    message.setKfAccount(configStorage.getKfAccount());
-    message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World");
-
-    this.wxService.customMessageSend(message);
-  }
-
-}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java
index 431792e4..21096f61 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java
@@ -11,9 +11,11 @@ import org.testng.annotations.Test;
 
 import com.google.inject.Inject;
 
+import me.chanjar.weixin.common.api.WxConsts;
 import me.chanjar.weixin.common.exception.WxErrorException;
 import me.chanjar.weixin.mp.api.ApiTestModule;
 import me.chanjar.weixin.mp.api.ApiTestModule.WxXmlMpInMemoryConfigStorage;
+import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
 import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
 import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfInfo;
 import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList;
@@ -35,6 +37,31 @@ public class WxMpKefuServiceImplTest {
   @Inject
   protected WxMpServiceImpl wxService;
 
+  public void testSendCustomMessage() throws WxErrorException {
+    ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService
+        .getWxMpConfigStorage();
+    WxMpCustomMessage message = new WxMpCustomMessage();
+    message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
+    message.setToUser(configStorage.getOpenId());
+    message.setContent(
+        "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World");
+
+    this.wxService.getKefuService().customMessageSend(message);
+  }
+
+  public void testSendCustomMessageWithKfAccount() throws WxErrorException {
+    ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService
+        .getWxMpConfigStorage();
+    WxMpCustomMessage message = new WxMpCustomMessage();
+    message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
+    message.setToUser(configStorage.getOpenId());
+    message.setKfAccount(configStorage.getKfAccount());
+    message.setContent(
+        "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World");
+
+    this.wxService.getKefuService().customMessageSend(message);
+  }
+
   public void testKfList() throws WxErrorException {
     WxMpKfList kfList = this.wxService.getKefuService().kfList();
     Assert.assertNotNull(kfList);
@@ -123,7 +150,7 @@ public class WxMpKefuServiceImplTest {
   }
 
   @Test(dataProvider = "getKfAccountAndOpenid")
-  public void testKfSessionGet(String kfAccount,
+  public void testKfSessionGet(@SuppressWarnings("unused") String kfAccount,
       String openid) throws WxErrorException {
     WxMpKfSessionGetResult result = this.wxService.getKefuService()
         .kfSessionGet(openid);
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java
index 6db18923..a6fb1e53 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java
@@ -1,5 +1,9 @@
 package me.chanjar.weixin.mp.demo;
 
+import java.util.Map;
+import java.util.Random;
+import java.util.regex.Pattern;
+
 import me.chanjar.weixin.common.exception.WxErrorException;
 import me.chanjar.weixin.common.session.WxSession;
 import me.chanjar.weixin.common.session.WxSessionManager;
@@ -10,10 +14,6 @@ import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
 import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
 import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
 
-import java.util.Map;
-import java.util.Random;
-import java.util.regex.Pattern;
-
 public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMatcher {
 
   private Random random = new Random();
@@ -57,14 +57,14 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa
           .toUser(wxMessage.getFromUserName())
           .content("请猜一个100以内的数字")
           .build();
-      wxMpService.customMessageSend(m);
+      wxMpService.getKefuService().customMessageSend(m);
     } else {
       WxMpCustomMessage m = WxMpCustomMessage
           .TEXT()
           .toUser(wxMessage.getFromUserName())
           .content("放弃了吗?那请重新猜一个100以内的数字")
           .build();
-      wxMpService.customMessageSend(m);
+      wxMpService.getKefuService().customMessageSend(m);
     }
 
     session.setAttribute("guessing", Boolean.TRUE);
@@ -92,7 +92,7 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa
           .toUser(wxMessage.getFromUserName())
           .content("小了")
           .build();
-      wxMpService.customMessageSend(m);
+      wxMpService.getKefuService().customMessageSend(m);
 
     } else if (guessNumber > answer) {
       WxMpCustomMessage m = WxMpCustomMessage
@@ -100,7 +100,7 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa
           .toUser(wxMessage.getFromUserName())
           .content("大了")
           .build();
-      wxMpService.customMessageSend(m);
+      wxMpService.getKefuService().customMessageSend(m);
     } else {
       WxMpCustomMessage m = WxMpCustomMessage
           .TEXT()
@@ -108,7 +108,7 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa
           .content("Bingo!")
           .build();
       session.removeAttribute("guessing");
-      wxMpService.customMessageSend(m);
+      wxMpService.getKefuService().customMessageSend(m);
     }
 
   }

From b941a57ccd62b3fd6f7049577259b9a45cb5541a Mon Sep 17 00:00:00 2001
From: miller 
Date: Tue, 20 Sep 2016 14:39:39 +0800
Subject: [PATCH 48/49] add user black list api and impl

---
 .../me/chanjar/weixin/mp/api/WxMpService.java |  9 ++-
 .../mp/api/WxMpUserBlackListService.java      | 35 ++++++++++++
 .../weixin/mp/api/impl/WxMpServiceImpl.java   | 42 ++++++++------
 .../impl/WxMpUserBlackListServiceImpl.java    | 50 ++++++++++++++++
 .../result/WxMpUserBlackListGetResult.java    | 57 +++++++++++++++++++
 .../weixin/mp/util/json/WxMpGsonBuilder.java  |  1 +
 .../WxUserBlackListGetResultGsonAdapter.java  | 28 +++++++++
 .../WxMpUserBlackListServiceImplTest.java     | 48 ++++++++++++++++
 8 files changed, 251 insertions(+), 19 deletions(-)
 create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlackListService.java
 create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImpl.java
 create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlackListGetResult.java
 create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlackListGetResultGsonAdapter.java
 create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImplTest.java

diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
index 952cf8f5..8816b34d 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
@@ -327,7 +327,7 @@ public interface WxMpService {
    *
    * @return WxMpGroupService
    */
-  
+
   WxMpGroupService getGroupService();
 
   /**
@@ -364,4 +364,11 @@ public interface WxMpService {
    * @return WxMpDataCubeService
    */
   WxMpDataCubeService getDataCubeService();
+
+  /**
+   * 返回用户黑名单管理相关接口的方法实现类,以方便调用其各种借口
+   *
+   * @return WxMpUserBlackListService
+   */
+  WxMpUserBlackListService getBlackListService();
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlackListService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlackListService.java
new file mode 100644
index 00000000..17dd5821
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlackListService.java
@@ -0,0 +1,35 @@
+package me.chanjar.weixin.mp.api;
+
+import me.chanjar.weixin.common.exception.WxErrorException;
+import me.chanjar.weixin.mp.bean.result.WxMpUserBlackListGetResult;
+
+import java.util.List;
+
+/**
+ * @author miller
+ */
+public interface WxMpUserBlackListService {
+  /**
+   * 
+   * 获取公众号的黑名单列表
+   * 详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN
+   * 
+ */ + WxMpUserBlackListGetResult blackList(String nextOpenid) throws WxErrorException; + + /** + *
+   *   拉黑用户
+   *   详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN
+   * 
+ */ + void pushToBlackList(List openIdList) throws WxErrorException; + + /** + *
+   *   取消拉黑用户
+   *   详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN
+   * 
+ */ + void pullFromBlackList(List openIdList) throws WxErrorException; +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java index 3f2c9808..96031b6c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java @@ -1,23 +1,9 @@ package me.chanjar.weixin.mp.api.impl; -import java.io.IOException; - -import org.apache.http.HttpHost; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.ssl.DefaultHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.BasicResponseHandler; -import org.apache.http.impl.client.CloseableHttpClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; - import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.result.WxError; @@ -42,6 +28,7 @@ import me.chanjar.weixin.mp.api.WxMpMenuService; import me.chanjar.weixin.mp.api.WxMpPayService; import me.chanjar.weixin.mp.api.WxMpQrcodeService; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.WxMpUserBlackListService; import me.chanjar.weixin.mp.api.WxMpUserService; import me.chanjar.weixin.mp.api.WxMpUserTagService; import me.chanjar.weixin.mp.bean.WxMpIndustry; @@ -57,6 +44,18 @@ import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; import me.chanjar.weixin.mp.bean.result.WxMpUser; +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.BasicResponseHandler; +import org.apache.http.impl.client.CloseableHttpClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; public class WxMpServiceImpl implements WxMpService { @@ -75,7 +74,7 @@ public class WxMpServiceImpl implements WxMpService { private final Object globalJsapiTicketRefreshLock = new Object(); private WxMpConfigStorage configStorage; - + private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this); @@ -96,6 +95,8 @@ public class WxMpServiceImpl implements WxMpService { private WxMpDataCubeService dataCubeService = new WxMpDataCubeServiceImpl(this); + private WxMpUserBlackListService blackListService = new WxMpUserBlackListServiceImpl(this); + private CloseableHttpClient httpClient; private HttpHost httpProxy; @@ -312,7 +313,7 @@ public class WxMpServiceImpl implements WxMpService { if (state != null) { url.append("&state=").append(state); } - + url.append("#wechat_redirect"); return url.toString(); } @@ -474,7 +475,7 @@ public class WxMpServiceImpl implements WxMpService { throw new RuntimeException(e); } } - + public HttpHost getHttpProxy() { return this.httpProxy; } @@ -495,7 +496,7 @@ public class WxMpServiceImpl implements WxMpService { if (null == apacheHttpClientBuilder) { apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get(); } - + apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost()) .httpProxyPort(this.configStorage.getHttpProxyPort()) .httpProxyUsername(this.configStorage.getHttpProxyUsername()) @@ -580,4 +581,9 @@ public class WxMpServiceImpl implements WxMpService { return this.dataCubeService; } + @Override + public WxMpUserBlackListService getBlackListService() { + return this.blackListService; + } + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImpl.java new file mode 100644 index 00000000..d749ed8c --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImpl.java @@ -0,0 +1,50 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.WxMpUserBlackListService; +import me.chanjar.weixin.mp.bean.result.WxMpUserBlackListGetResult; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author miller + */ +public class WxMpUserBlackListServiceImpl implements WxMpUserBlackListService { + private static final String API_BLACK_LIST_PREFIX = "https://api.weixin.qq.com/cgi-bin/tags/members"; + private WxMpService wxMpService; + + public WxMpUserBlackListServiceImpl(WxMpService wxMpService) { + this.wxMpService = wxMpService; + } + + @Override + public WxMpUserBlackListGetResult blackList(String nextOpenid) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("begin_openid", nextOpenid); + String url = API_BLACK_LIST_PREFIX + "/getblacklist"; + String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, jsonObject.toString()); + return WxMpUserBlackListGetResult.fromJson(responseContent); + } + + @Override + public void pushToBlackList(List openIdList) throws WxErrorException { + Map map = new HashMap<>(); + map.put("openid_list", openIdList); + String url = API_BLACK_LIST_PREFIX + "/batchblacklist"; + this.wxMpService.execute(new SimplePostRequestExecutor(), url, new Gson().toJson(map)); + } + + @Override + public void pullFromBlackList(List openIdList) throws WxErrorException { + Map map = new HashMap<>(); + map.put("openid_list", openIdList); + String url = API_BLACK_LIST_PREFIX + "/batchunblacklist"; + this.wxMpService.execute(new SimplePostRequestExecutor(), url, new Gson().toJson(map)); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlackListGetResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlackListGetResult.java new file mode 100644 index 00000000..12a48e3d --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlackListGetResult.java @@ -0,0 +1,57 @@ +package me.chanjar.weixin.mp.bean.result; + +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author miller + */ +public class WxMpUserBlackListGetResult { + protected int total = -1; + protected int count = -1; + protected List openIds = new ArrayList<>(); + protected String nextOpenId; + + public static WxMpUserBlackListGetResult fromJson(String json) { + return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUserBlackListGetResult.class); + } + + public int getTotal() { + return this.total; + } + + public void setTotal(int total) { + this.total = total; + } + + public int getCount() { + return this.count; + } + + public void setCount(int count) { + this.count = count; + } + + public List getOpenIds() { + return this.openIds; + } + + public void setOpenIds(List openIds) { + this.openIds = openIds; + } + + public String getNextOpenId() { + return this.nextOpenId; + } + + public void setNextOpenId(String nextOpenId) { + this.nextOpenId = nextOpenId; + } + + @Override + public String toString() { + return WxMpGsonBuilder.INSTANCE.create().toJson(this); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java index bf920fff..4152a8da 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java @@ -45,6 +45,7 @@ public class WxMpGsonBuilder { INSTANCE.registerTypeAdapter(WxMpMassPreviewMessage.class, new WxMpMassPreviewMessageGsonAdapter()); INSTANCE.registerTypeAdapter(WxMediaImgUploadResult.class, new WxMediaImgUploadResultGsonAdapter()); INSTANCE.registerTypeAdapter(WxMpIndustry.class, new WxMpIndustryGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMpUserBlackListGetResult.class, new WxUserBlackListGetResultGsonAdapter()); } public static Gson create() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlackListGetResultGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlackListGetResultGsonAdapter.java new file mode 100644 index 00000000..5f68f12a --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlackListGetResultGsonAdapter.java @@ -0,0 +1,28 @@ +package me.chanjar.weixin.mp.util.json; + +import com.google.gson.*; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.mp.bean.result.WxMpUserBlackListGetResult; + +import java.lang.reflect.Type; + +/** + * @author miller + */ +public class WxUserBlackListGetResultGsonAdapter implements JsonDeserializer { + @Override + public WxMpUserBlackListGetResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + JsonObject o = json.getAsJsonObject(); + WxMpUserBlackListGetResult wxMpUserBlackListGetResult = new WxMpUserBlackListGetResult(); + wxMpUserBlackListGetResult.setTotal(GsonHelper.getInteger(o, "total")); + wxMpUserBlackListGetResult.setCount(GsonHelper.getInteger(o, "count")); + wxMpUserBlackListGetResult.setNextOpenId(GsonHelper.getString(o, "next_openid")); + if (o.get("data") != null && !o.get("data").isJsonNull() && !o.get("data").getAsJsonObject().get("openid").isJsonNull()) { + JsonArray data = o.get("data").getAsJsonObject().get("openid").getAsJsonArray(); + for (int i = 0; i < data.size(); i++) { + wxMpUserBlackListGetResult.getOpenIds().add(GsonHelper.getAsString(data.get(i))); + } + } + return wxMpUserBlackListGetResult; + } +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImplTest.java new file mode 100644 index 00000000..b511f5e7 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImplTest.java @@ -0,0 +1,48 @@ +package me.chanjar.weixin.mp.api.impl; + +import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.bean.result.WxMpUserBlackListGetResult; +import org.testng.Assert; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; + +/** + * @author miller + */ +@Test(groups = "userAPI") +@Guice(modules = ApiTestModule.class) +public class WxMpUserBlackListServiceImplTest { + //此处openid只是开发的时候测试用 使用者测试的时候请替换自己公众号的openid + private final String TEST_OPENID = "o9VAswOI0KSXFUtFHgk9Kb9Rtkys"; + @Inject + protected WxMpServiceImpl wxService; + + @Test + public void testBlackList() throws Exception { + WxMpUserBlackListGetResult wxMpUserBlackListGetResult = this.wxService.getBlackListService().blackList(TEST_OPENID); + Assert.assertNotNull(wxMpUserBlackListGetResult); + Assert.assertFalse(wxMpUserBlackListGetResult.getCount() == -1); + Assert.assertFalse(wxMpUserBlackListGetResult.getTotal() == -1); + Assert.assertFalse(wxMpUserBlackListGetResult.getOpenIds().size() == -1); + System.out.println(wxMpUserBlackListGetResult); + } + + @Test + public void testPushToBlackList() throws Exception { + List openIdList = new ArrayList<>(); + openIdList.add(TEST_OPENID); + this.wxService.getBlackListService().pushToBlackList(openIdList); + } + + @Test + public void testPullFromBlackList() throws Exception { + List openIdList = new ArrayList<>(); + openIdList.add(TEST_OPENID); + this.wxService.getBlackListService().pullFromBlackList(openIdList); + } + +} From 63c41d44ab972b5c078e56c2387aaa07a18a8142 Mon Sep 17 00:00:00 2001 From: miller Date: Tue, 20 Sep 2016 15:22:59 +0800 Subject: [PATCH 49/49] 1.rename openId to openid 2.rename blackList to blacklist 3.refine blacklist test --- .../me/chanjar/weixin/mp/api/WxMpService.java | 2 +- ...ice.java => WxMpUserBlacklistService.java} | 10 ++-- .../weixin/mp/api/impl/WxMpServiceImpl.java | 6 +-- ...java => WxMpUserBlacklistServiceImpl.java} | 28 +++++----- ...t.java => WxMpUserBlacklistGetResult.java} | 26 +++++----- .../weixin/mp/util/json/WxMpGsonBuilder.java | 2 +- .../WxUserBlackListGetResultGsonAdapter.java | 28 ---------- .../WxUserBlacklistGetResultGsonAdapter.java | 28 ++++++++++ .../chanjar/weixin/mp/api/ApiTestModule.java | 10 ++-- .../weixin/mp/api/WxMpMassMessageAPITest.java | 20 +++---- .../mp/api/impl/WxMpGroupServiceImplTest.java | 10 ++-- .../mp/api/impl/WxMpKefuServiceImplTest.java | 6 +-- .../WxMpUserBlackListServiceImplTest.java | 48 ----------------- .../WxMpUserBlacklistServiceImplTest.java | 52 +++++++++++++++++++ .../mp/api/impl/WxMpUserServiceImplTest.java | 4 +- .../src/test/resources/test-config.sample.xml | 2 +- 16 files changed, 143 insertions(+), 139 deletions(-) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/{WxMpUserBlackListService.java => WxMpUserBlacklistService.java} (68%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/{WxMpUserBlackListServiceImpl.java => WxMpUserBlacklistServiceImpl.java} (53%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/{WxMpUserBlackListGetResult.java => WxMpUserBlacklistGetResult.java} (55%) delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlackListGetResultGsonAdapter.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlacklistGetResultGsonAdapter.java delete mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImplTest.java create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 8816b34d..adef735d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -370,5 +370,5 @@ public interface WxMpService { * * @return WxMpUserBlackListService */ - WxMpUserBlackListService getBlackListService(); + WxMpUserBlacklistService getBlackListService(); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlackListService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlacklistService.java similarity index 68% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlackListService.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlacklistService.java index 17dd5821..d93384f0 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlackListService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserBlacklistService.java @@ -1,21 +1,21 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.bean.result.WxMpUserBlackListGetResult; +import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; import java.util.List; /** * @author miller */ -public interface WxMpUserBlackListService { +public interface WxMpUserBlacklistService { /** *
    * 获取公众号的黑名单列表
    * 详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN
    * 
*/ - WxMpUserBlackListGetResult blackList(String nextOpenid) throws WxErrorException; + WxMpUserBlacklistGetResult getBlacklist(String nextOpenid) throws WxErrorException; /** *
@@ -23,7 +23,7 @@ public interface WxMpUserBlackListService {
    *   详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN
    * 
*/ - void pushToBlackList(List openIdList) throws WxErrorException; + void pushToBlacklist(List openidList) throws WxErrorException; /** *
@@ -31,5 +31,5 @@ public interface WxMpUserBlackListService {
    *   详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN
    * 
*/ - void pullFromBlackList(List openIdList) throws WxErrorException; + void pullFromBlacklist(List openidList) throws WxErrorException; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java index 96031b6c..f1c8388e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java @@ -28,7 +28,7 @@ import me.chanjar.weixin.mp.api.WxMpMenuService; import me.chanjar.weixin.mp.api.WxMpPayService; import me.chanjar.weixin.mp.api.WxMpQrcodeService; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxMpUserBlackListService; +import me.chanjar.weixin.mp.api.WxMpUserBlacklistService; import me.chanjar.weixin.mp.api.WxMpUserService; import me.chanjar.weixin.mp.api.WxMpUserTagService; import me.chanjar.weixin.mp.bean.WxMpIndustry; @@ -95,7 +95,7 @@ public class WxMpServiceImpl implements WxMpService { private WxMpDataCubeService dataCubeService = new WxMpDataCubeServiceImpl(this); - private WxMpUserBlackListService blackListService = new WxMpUserBlackListServiceImpl(this); + private WxMpUserBlacklistService blackListService = new WxMpUserBlacklistServiceImpl(this); private CloseableHttpClient httpClient; @@ -582,7 +582,7 @@ public class WxMpServiceImpl implements WxMpService { } @Override - public WxMpUserBlackListService getBlackListService() { + public WxMpUserBlacklistService getBlackListService() { return this.blackListService; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImpl.java similarity index 53% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImpl.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImpl.java index d749ed8c..b0b35343 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImpl.java @@ -5,8 +5,8 @@ import com.google.gson.JsonObject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxMpUserBlackListService; -import me.chanjar.weixin.mp.bean.result.WxMpUserBlackListGetResult; +import me.chanjar.weixin.mp.api.WxMpUserBlacklistService; +import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; import java.util.HashMap; import java.util.List; @@ -15,36 +15,36 @@ import java.util.Map; /** * @author miller */ -public class WxMpUserBlackListServiceImpl implements WxMpUserBlackListService { - private static final String API_BLACK_LIST_PREFIX = "https://api.weixin.qq.com/cgi-bin/tags/members"; +public class WxMpUserBlacklistServiceImpl implements WxMpUserBlacklistService { + private static final String API_BLACKLIST_PREFIX = "https://api.weixin.qq.com/cgi-bin/tags/members"; private WxMpService wxMpService; - public WxMpUserBlackListServiceImpl(WxMpService wxMpService) { + public WxMpUserBlacklistServiceImpl(WxMpService wxMpService) { this.wxMpService = wxMpService; } @Override - public WxMpUserBlackListGetResult blackList(String nextOpenid) throws WxErrorException { + public WxMpUserBlacklistGetResult getBlacklist(String nextOpenid) throws WxErrorException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("begin_openid", nextOpenid); - String url = API_BLACK_LIST_PREFIX + "/getblacklist"; + String url = API_BLACKLIST_PREFIX + "/getblacklist"; String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, jsonObject.toString()); - return WxMpUserBlackListGetResult.fromJson(responseContent); + return WxMpUserBlacklistGetResult.fromJson(responseContent); } @Override - public void pushToBlackList(List openIdList) throws WxErrorException { + public void pushToBlacklist(List openidList) throws WxErrorException { Map map = new HashMap<>(); - map.put("openid_list", openIdList); - String url = API_BLACK_LIST_PREFIX + "/batchblacklist"; + map.put("openid_list", openidList); + String url = API_BLACKLIST_PREFIX + "/batchblacklist"; this.wxMpService.execute(new SimplePostRequestExecutor(), url, new Gson().toJson(map)); } @Override - public void pullFromBlackList(List openIdList) throws WxErrorException { + public void pullFromBlacklist(List openidList) throws WxErrorException { Map map = new HashMap<>(); - map.put("openid_list", openIdList); - String url = API_BLACK_LIST_PREFIX + "/batchunblacklist"; + map.put("openid_list", openidList); + String url = API_BLACKLIST_PREFIX + "/batchunblacklist"; this.wxMpService.execute(new SimplePostRequestExecutor(), url, new Gson().toJson(map)); } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlackListGetResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlacklistGetResult.java similarity index 55% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlackListGetResult.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlacklistGetResult.java index 12a48e3d..3cfbc009 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlackListGetResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserBlacklistGetResult.java @@ -8,14 +8,14 @@ import java.util.List; /** * @author miller */ -public class WxMpUserBlackListGetResult { +public class WxMpUserBlacklistGetResult { protected int total = -1; protected int count = -1; - protected List openIds = new ArrayList<>(); - protected String nextOpenId; + protected List openidList = new ArrayList<>(); + protected String nextOpenid; - public static WxMpUserBlackListGetResult fromJson(String json) { - return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUserBlackListGetResult.class); + public static WxMpUserBlacklistGetResult fromJson(String json) { + return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUserBlacklistGetResult.class); } public int getTotal() { @@ -34,20 +34,20 @@ public class WxMpUserBlackListGetResult { this.count = count; } - public List getOpenIds() { - return this.openIds; + public List getOpenidList() { + return this.openidList; } - public void setOpenIds(List openIds) { - this.openIds = openIds; + public void setOpenidList(List openidList) { + this.openidList = openidList; } - public String getNextOpenId() { - return this.nextOpenId; + public String getNextOpenid() { + return this.nextOpenid; } - public void setNextOpenId(String nextOpenId) { - this.nextOpenId = nextOpenId; + public void setNextOpenid(String nextOpenid) { + this.nextOpenid = nextOpenid; } @Override diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java index 4152a8da..ab3d5769 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java @@ -45,7 +45,7 @@ public class WxMpGsonBuilder { INSTANCE.registerTypeAdapter(WxMpMassPreviewMessage.class, new WxMpMassPreviewMessageGsonAdapter()); INSTANCE.registerTypeAdapter(WxMediaImgUploadResult.class, new WxMediaImgUploadResultGsonAdapter()); INSTANCE.registerTypeAdapter(WxMpIndustry.class, new WxMpIndustryGsonAdapter()); - INSTANCE.registerTypeAdapter(WxMpUserBlackListGetResult.class, new WxUserBlackListGetResultGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMpUserBlacklistGetResult.class, new WxUserBlacklistGetResultGsonAdapter()); } public static Gson create() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlackListGetResultGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlackListGetResultGsonAdapter.java deleted file mode 100644 index 5f68f12a..00000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlackListGetResultGsonAdapter.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.chanjar.weixin.mp.util.json; - -import com.google.gson.*; -import me.chanjar.weixin.common.util.json.GsonHelper; -import me.chanjar.weixin.mp.bean.result.WxMpUserBlackListGetResult; - -import java.lang.reflect.Type; - -/** - * @author miller - */ -public class WxUserBlackListGetResultGsonAdapter implements JsonDeserializer { - @Override - public WxMpUserBlackListGetResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - JsonObject o = json.getAsJsonObject(); - WxMpUserBlackListGetResult wxMpUserBlackListGetResult = new WxMpUserBlackListGetResult(); - wxMpUserBlackListGetResult.setTotal(GsonHelper.getInteger(o, "total")); - wxMpUserBlackListGetResult.setCount(GsonHelper.getInteger(o, "count")); - wxMpUserBlackListGetResult.setNextOpenId(GsonHelper.getString(o, "next_openid")); - if (o.get("data") != null && !o.get("data").isJsonNull() && !o.get("data").getAsJsonObject().get("openid").isJsonNull()) { - JsonArray data = o.get("data").getAsJsonObject().get("openid").getAsJsonArray(); - for (int i = 0; i < data.size(); i++) { - wxMpUserBlackListGetResult.getOpenIds().add(GsonHelper.getAsString(data.get(i))); - } - } - return wxMpUserBlackListGetResult; - } -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlacklistGetResultGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlacklistGetResultGsonAdapter.java new file mode 100644 index 00000000..64582f64 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserBlacklistGetResultGsonAdapter.java @@ -0,0 +1,28 @@ +package me.chanjar.weixin.mp.util.json; + +import com.google.gson.*; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; + +import java.lang.reflect.Type; + +/** + * @author miller + */ +public class WxUserBlacklistGetResultGsonAdapter implements JsonDeserializer { + @Override + public WxMpUserBlacklistGetResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + JsonObject o = json.getAsJsonObject(); + WxMpUserBlacklistGetResult wxMpUserBlacklistGetResult = new WxMpUserBlacklistGetResult(); + wxMpUserBlacklistGetResult.setTotal(GsonHelper.getInteger(o, "total")); + wxMpUserBlacklistGetResult.setCount(GsonHelper.getInteger(o, "count")); + wxMpUserBlacklistGetResult.setNextOpenid(GsonHelper.getString(o, "next_openid")); + if (o.get("data") != null && !o.get("data").isJsonNull() && !o.get("data").getAsJsonObject().get("openid").isJsonNull()) { + JsonArray data = o.get("data").getAsJsonObject().get("openid").getAsJsonArray(); + for (int i = 0; i < data.size(); i++) { + wxMpUserBlacklistGetResult.getOpenidList().add(GsonHelper.getAsString(data.get(i))); + } + } + return wxMpUserBlacklistGetResult; + } +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java index 3955f87d..f4b79ae2 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java @@ -43,16 +43,16 @@ public class ApiTestModule implements Module { public static class WxXmlMpInMemoryConfigStorage extends WxMpInMemoryConfigStorage { - private String openId; + private String openid; private String kfAccount; private String qrconnectRedirectUrl; - public String getOpenId() { - return this.openId; + public String getOpenid() { + return this.openid; } - public void setOpenId(String openId) { - this.openId = openId; + public void setOpenid(String openid) { + this.openid = openid; } @Override diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java index 168f96cf..ee99b6e1 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java @@ -41,7 +41,7 @@ public class WxMpMassMessageAPITest { WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); - massMessage.getToUsers().add(configProvider.getOpenId()); + massMessage.getToUsers().add(configProvider.getOpenid()); WxMpMassSendResult massResult = this.wxService .massOpenIdsMessageSend(massMessage); @@ -58,7 +58,7 @@ public class WxMpMassMessageAPITest { WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(massMsgType); massMessage.setMediaId(mediaId); - massMessage.getToUsers().add(configProvider.getOpenId()); + massMessage.getToUsers().add(configProvider.getOpenid()); WxMpMassSendResult massResult = this.wxService .massOpenIdsMessageSend(massMessage); @@ -73,13 +73,13 @@ public class WxMpMassMessageAPITest { massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); massMessage .setGroupId(this.wxService.getGroupService().groupGet().get(0).getId()); - + WxMpMassSendResult massResult = this.wxService .massGroupMessageSend(massMessage); Assert.assertNotNull(massResult); Assert.assertNotNull(massResult.getMsgId()); } - + @Test(dataProvider="massMessages") public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) throws WxErrorException { @@ -94,7 +94,7 @@ public class WxMpMassMessageAPITest { Assert.assertNotNull(massResult); Assert.assertNotNull(massResult.getMsgId()); } - + @DataProvider public Object[][] massMessages() throws WxErrorException, IOException { Object[][] messages = new Object[4][]; @@ -109,7 +109,7 @@ public class WxMpMassMessageAPITest { .mediaUpload(WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, inputStream); Assert.assertNotNull(uploadMediaRes); Assert.assertNotNull(uploadMediaRes.getMediaId()); - + // 把视频变成可被群发的媒体 WxMpMassVideo video = new WxMpMassVideo(); video.setTitle("测试标题"); @@ -155,7 +155,7 @@ public class WxMpMassMessageAPITest { .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream); Assert.assertNotNull(uploadMediaRes); Assert.assertNotNull(uploadMediaRes.getMediaId()); - + // 上传图文消息 WxMpMassNews news = new WxMpMassNews(); WxMpMassNews.WxMpMassNewsArticle article1 = new WxMpMassNews.WxMpMassNewsArticle(); @@ -163,7 +163,7 @@ public class WxMpMassMessageAPITest { article1.setContent("内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1"); article1.setThumbMediaId(uploadMediaRes.getMediaId()); news.addArticle(article1); - + WxMpMassNews.WxMpMassNewsArticle article2 = new WxMpMassNews.WxMpMassNewsArticle(); article2.setTitle("标题2"); article2.setContent("内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2"); @@ -173,7 +173,7 @@ public class WxMpMassMessageAPITest { article2.setContentSourceUrl("www.baidu.com"); article2.setDigest("摘要2"); news.addArticle(article2); - + WxMpMassUploadResult massUploadResult = this.wxService .massNewsUpload(news); Assert.assertNotNull(massUploadResult); @@ -183,5 +183,5 @@ public class WxMpMassMessageAPITest { return messages; } - + } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java index d0ba6029..5d114cc4 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java @@ -12,7 +12,7 @@ import java.util.List; /** * 测试分组接口 - * + * * @author chanjarster */ @Deprecated @@ -24,7 +24,7 @@ public class WxMpGroupServiceImplTest { protected WxMpServiceImpl wxService; protected WxMpGroup group; - + public void testGroupCreate() throws WxErrorException { WxMpGroup res = this.wxService.getGroupService().groupCreate("测试分组1"); Assert.assertEquals(res.getName(), "测试分组1"); @@ -40,7 +40,7 @@ public class WxMpGroupServiceImplTest { Assert.assertNotNull(g.getName()); } } - + @Test(dependsOnMethods={"testGroupGet", "testGroupCreate"}) public void getGroupUpdate() throws WxErrorException { this.group.setName("分组改名"); @@ -49,13 +49,13 @@ public class WxMpGroupServiceImplTest { public void testGroupQueryUserGroup() throws WxErrorException { ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); - long groupid = this.wxService.getGroupService().userGetGroup(configStorage.getOpenId()); + long groupid = this.wxService.getGroupService().userGetGroup(configStorage.getOpenid()); Assert.assertTrue(groupid != -1l); } public void testGroupMoveUser() throws WxErrorException { ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); - this.wxService.getGroupService().userUpdateGroup(configStorage.getOpenId(), this.wxService.getGroupService().groupGet().get(3).getId()); + this.wxService.getGroupService().userUpdateGroup(configStorage.getOpenid(), this.wxService.getGroupService().groupGet().get(3).getId()); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java index 21096f61..66ff3c30 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java @@ -42,7 +42,7 @@ public class WxMpKefuServiceImplTest { .getWxMpConfigStorage(); WxMpCustomMessage message = new WxMpCustomMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); - message.setToUser(configStorage.getOpenId()); + message.setToUser(configStorage.getOpenid()); message.setContent( "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); @@ -54,7 +54,7 @@ public class WxMpKefuServiceImplTest { .getWxMpConfigStorage(); WxMpCustomMessage message = new WxMpCustomMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); - message.setToUser(configStorage.getOpenId()); + message.setToUser(configStorage.getOpenid()); message.setKfAccount(configStorage.getKfAccount()); message.setContent( "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); @@ -130,7 +130,7 @@ public class WxMpKefuServiceImplTest { WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService .getWxMpConfigStorage(); return new Object[][] { - { configStorage.getKfAccount(), configStorage.getOpenId() } }; + { configStorage.getKfAccount(), configStorage.getOpenid() } }; } @Test(dataProvider = "getKfAccountAndOpenid") diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImplTest.java deleted file mode 100644 index b511f5e7..00000000 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlackListServiceImplTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package me.chanjar.weixin.mp.api.impl; - -import me.chanjar.weixin.mp.api.ApiTestModule; -import me.chanjar.weixin.mp.bean.result.WxMpUserBlackListGetResult; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; - -import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; - -/** - * @author miller - */ -@Test(groups = "userAPI") -@Guice(modules = ApiTestModule.class) -public class WxMpUserBlackListServiceImplTest { - //此处openid只是开发的时候测试用 使用者测试的时候请替换自己公众号的openid - private final String TEST_OPENID = "o9VAswOI0KSXFUtFHgk9Kb9Rtkys"; - @Inject - protected WxMpServiceImpl wxService; - - @Test - public void testBlackList() throws Exception { - WxMpUserBlackListGetResult wxMpUserBlackListGetResult = this.wxService.getBlackListService().blackList(TEST_OPENID); - Assert.assertNotNull(wxMpUserBlackListGetResult); - Assert.assertFalse(wxMpUserBlackListGetResult.getCount() == -1); - Assert.assertFalse(wxMpUserBlackListGetResult.getTotal() == -1); - Assert.assertFalse(wxMpUserBlackListGetResult.getOpenIds().size() == -1); - System.out.println(wxMpUserBlackListGetResult); - } - - @Test - public void testPushToBlackList() throws Exception { - List openIdList = new ArrayList<>(); - openIdList.add(TEST_OPENID); - this.wxService.getBlackListService().pushToBlackList(openIdList); - } - - @Test - public void testPullFromBlackList() throws Exception { - List openIdList = new ArrayList<>(); - openIdList.add(TEST_OPENID); - this.wxService.getBlackListService().pullFromBlackList(openIdList); - } - -} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java new file mode 100644 index 00000000..6d31ea97 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java @@ -0,0 +1,52 @@ +package me.chanjar.weixin.mp.api.impl; + +import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; +import org.testng.Assert; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; + +/** + * @author miller + */ +@Test(groups = "userAPI") +@Guice(modules = ApiTestModule.class) +public class WxMpUserBlacklistServiceImplTest { + @Inject + protected WxMpServiceImpl wxService; + + @Test + public void testGetBlacklist() throws Exception { + ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService + .getWxMpConfigStorage(); + WxMpUserBlacklistGetResult wxMpUserBlacklistGetResult = this.wxService.getBlackListService().getBlacklist(configStorage.getOpenid()); + Assert.assertNotNull(wxMpUserBlacklistGetResult); + Assert.assertFalse(wxMpUserBlacklistGetResult.getCount() == -1); + Assert.assertFalse(wxMpUserBlacklistGetResult.getTotal() == -1); + Assert.assertFalse(wxMpUserBlacklistGetResult.getOpenidList().size() == -1); + System.out.println(wxMpUserBlacklistGetResult); + } + + @Test + public void testPushToBlacklist() throws Exception { + ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService + .getWxMpConfigStorage(); + List openidList = new ArrayList<>(); + openidList.add(configStorage.getOpenid()); + this.wxService.getBlackListService().pushToBlacklist(openidList); + } + + @Test + public void testPullFromBlacklist() throws Exception { + ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService + .getWxMpConfigStorage(); + List openidList = new ArrayList<>(); + openidList.add(configStorage.getOpenid()); + this.wxService.getBlackListService().pullFromBlacklist(openidList); + } + +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java index bc598285..95671b40 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java @@ -26,12 +26,12 @@ public class WxMpUserServiceImplTest { public void testUserUpdateRemark() throws WxErrorException { ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); - this.wxService.getUserService().userUpdateRemark(configProvider.getOpenId(), "测试备注名"); + this.wxService.getUserService().userUpdateRemark(configProvider.getOpenid(), "测试备注名"); } public void testUserInfo() throws WxErrorException { ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); - WxMpUser user = this.wxService.getUserService().userInfo(configProvider.getOpenId(), null); + WxMpUser user = this.wxService.getUserService().userInfo(configProvider.getOpenid(), null); Assert.assertNotNull(user); System.out.println(user); } diff --git a/weixin-java-mp/src/test/resources/test-config.sample.xml b/weixin-java-mp/src/test/resources/test-config.sample.xml index 836b26c4..0df87b09 100644 --- a/weixin-java-mp/src/test/resources/test-config.sample.xml +++ b/weixin-java-mp/src/test/resources/test-config.sample.xml @@ -5,7 +5,7 @@ 公众号EncodingAESKey 可以不填写 可以不填写 - 某个加你公众号的用户的openId + 某个加你公众号的用户的openId 网页授权获取用户信息回调地址 网页应用授权登陆回调地址 完整客服账号,格式为:账号前缀@公众号微信号