From 637fc87c0dfb11f0027c45b1476a88e538fa6873 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 23 Dec 2016 11:03:08 +0800 Subject: [PATCH 01/76] =?UTF-8?q?=E4=B8=BAWxMenuButton=E5=92=8CWxMenuRule?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=8F=E5=88=97=E5=8C=96=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/common/bean/menu/WxMenuButton.java | 4 +++- .../java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java index 02efac31..48979f7c 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java @@ -2,10 +2,12 @@ package me.chanjar.weixin.common.bean.menu; import me.chanjar.weixin.common.util.ToStringUtils; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; -public class WxMenuButton { +public class WxMenuButton implements Serializable { + private static final long serialVersionUID = -1070939403109776555L; private String type; private String name; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java index 714466f2..e0182c96 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java @@ -2,7 +2,11 @@ package me.chanjar.weixin.common.bean.menu; import me.chanjar.weixin.common.util.ToStringUtils; -public class WxMenuRule { +import java.io.Serializable; + +public class WxMenuRule implements Serializable { + private static final long serialVersionUID = -4587181819499286670L; + private String tagId; private String sex; private String country; From c70bf9b0c3941862eb54a743bda50eee558563b5 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 23 Dec 2016 14:14:01 +0800 Subject: [PATCH 02/76] =?UTF-8?q?=E7=94=9F=E6=88=90=E5=B8=A6=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E4=BA=8C=E7=BB=B4=E7=A0=81=E6=97=B6=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E5=9C=BA=E6=99=AF=E5=80=BC=E7=9A=84=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=20#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpQrcodeService.java | 14 +++++----- .../mp/api/impl/WxMpQrcodeServiceImpl.java | 28 ++++++++++++------- .../api/impl/WxMpQrCodeServiceImplTest.java | 17 +++++++---- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java index 7997a70d..89371208 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java @@ -18,10 +18,10 @@ public interface WxMpQrcodeService { * 详情请见: 生成带参数的二维码 * * - * @param scene_id 参数。 - * @param expire_seconds 过期秒数,默认60秒,最小60秒,最大1800秒 + * @param sceneId 参数。 + * @param expireSeconds 过期秒数,默认60秒,最小60秒,最大1800秒 */ - WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException; + WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException; /** *
@@ -29,9 +29,9 @@ public interface WxMpQrcodeService {
    * 详情请见: 生成带参数的二维码
    * 
* - * @param scene_id 参数。永久二维码时最大值为100000(目前参数只支持1--100000) + * @param sceneId 参数。永久二维码时最大值为100000(目前参数只支持1--100000) */ - WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException; + WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException; /** *
@@ -39,9 +39,9 @@ public interface WxMpQrcodeService {
    * 详情请见: 生成带参数的二维码
    * 
* - * @param scene_str 参数。字符串类型长度现在为1到64 + * @param sceneStr 参数。字符串类型长度现在为1到64 */ - WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException; + WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorException; /** *
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
index bb0e112c..9726b373 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
@@ -26,16 +26,20 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService {
   }
 
   @Override
-  public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException {
+  public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException {
+    if (sceneId == 0) {
+      throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景只不能为0!").build());
+    }
+
     String url = API_URL_PREFIX + "/create";
     JsonObject json = new JsonObject();
     json.addProperty("action_name", "QR_SCENE");
-    if (expire_seconds != null) {
-      json.addProperty("expire_seconds", expire_seconds);
+    if (expireSeconds != null) {
+      json.addProperty("expire_seconds", expireSeconds);
     }
     JsonObject actionInfo = new JsonObject();
     JsonObject scene = new JsonObject();
-    scene.addProperty("scene_id", scene_id);
+    scene.addProperty("scene_id", sceneId);
     actionInfo.add("scene", scene);
     json.add("action_info", actionInfo);
     String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
@@ -43,13 +47,17 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService {
   }
 
   @Override
-  public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException {
+  public WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException {
+    if (sceneId < 1 || sceneId > 100000) {
+      throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("永久二维码的场景值目前只支持1--100000!").build());
+    }
+
     String url = API_URL_PREFIX + "/create";
     JsonObject json = new JsonObject();
     json.addProperty("action_name", "QR_LIMIT_SCENE");
     JsonObject actionInfo = new JsonObject();
     JsonObject scene = new JsonObject();
-    scene.addProperty("scene_id", scene_id);
+    scene.addProperty("scene_id", sceneId);
     actionInfo.add("scene", scene);
     json.add("action_info", actionInfo);
     String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
@@ -57,13 +65,13 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService {
   }
 
   @Override
-  public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException {
+  public WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorException {
     String url = API_URL_PREFIX + "/create";
     JsonObject json = new JsonObject();
     json.addProperty("action_name", "QR_LIMIT_STR_SCENE");
     JsonObject actionInfo = new JsonObject();
     JsonObject scene = new JsonObject();
-    scene.addProperty("scene_str", scene_str);
+    scene.addProperty("scene_str", sceneStr);
     actionInfo.add("scene", scene);
     json.add("action_info", actionInfo);
     String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
@@ -81,7 +89,7 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService {
     String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s";
     try {
       String resultUrl = String.format(url,
-              URLEncoder.encode(ticket, StandardCharsets.UTF_8.name()));
+        URLEncoder.encode(ticket, StandardCharsets.UTF_8.name()));
       if (needShortUrl) {
         return this.wxMpService.shortUrl(resultUrl);
       }
@@ -89,7 +97,7 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService {
       return resultUrl;
     } catch (UnsupportedEncodingException e) {
       WxError error = WxError.newBuilder().setErrorCode(-1)
-              .setErrorMsg(e.getMessage()).build();
+        .setErrorMsg(e.getMessage()).build();
       throw new WxErrorException(error);
     }
   }
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java
index 4c53ac17..a2ab5328 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java
@@ -6,6 +6,7 @@ import me.chanjar.weixin.mp.api.ApiTestModule;
 import me.chanjar.weixin.mp.api.WxMpService;
 import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
 import org.testng.Assert;
+import org.testng.annotations.DataProvider;
 import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
@@ -19,20 +20,26 @@ import java.io.File;
 @Test(groups = "qrCodeAPI")
 @Guice(modules = ApiTestModule.class)
 public class WxMpQrCodeServiceImplTest {
-
   @Inject
   protected WxMpService wxService;
 
-  public void testQrCodeCreateTmpTicket() throws WxErrorException {
-    WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(1, null);
+  @DataProvider
+  public Object[][] sceneIds() {
+    return new Object[][]{{-1}, {0}, {1}, {200000}};
+  }
+
+  @Test(dataProvider = "sceneIds")
+  public void testQrCodeCreateTmpTicket(int sceneId) throws WxErrorException {
+    WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(sceneId, null);
     Assert.assertNotNull(ticket.getUrl());
     Assert.assertNotNull(ticket.getTicket());
     Assert.assertTrue(ticket.getExpire_seconds() != -1);
     System.out.println(ticket);
   }
 
-  public void testQrCodeCreateLastTicket() throws WxErrorException {
-    WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1);
+  @Test(dataProvider = "sceneIds")
+  public void testQrCodeCreateLastTicket(int sceneId) throws WxErrorException {
+    WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(sceneId);
     Assert.assertNotNull(ticket.getUrl());
     Assert.assertNotNull(ticket.getTicket());
     Assert.assertTrue(ticket.getExpire_seconds() == -1);

From 55c6ea500e3fc14e6b547ade328da4323e5add26 Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Fri, 23 Dec 2016 18:14:11 +0800
Subject: [PATCH 03/76] release 2.4.5.BETA

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

diff --git a/pom.xml b/pom.xml
index 5d10472b..56763023 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
   4.0.0
   com.github.binarywang
   weixin-java-parent
-  2.4.4-beta
+  2.4.5.BETA
   pom
   WeiXin Java Tools - Parent
   微信公众号、企业号上级POM
diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml
index 25265a91..60f734d9 100644
--- a/weixin-java-common/pom.xml
+++ b/weixin-java-common/pom.xml
@@ -6,7 +6,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.4.4-beta
+    2.4.5.BETA
   
 
   weixin-java-common
diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
index 2e8a5515..43e5d414 100644
--- a/weixin-java-cp/pom.xml
+++ b/weixin-java-cp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.4.4-beta
+        2.4.5.BETA
     
 
     weixin-java-cp
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index 5c817853..9952c4cb 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.4.4-beta
+        2.4.5.BETA
     
     weixin-java-mp
     WeiXin Java Tools - MP
diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml
index 0c7c1f6d..a0f8d7e8 100644
--- a/weixin-java-osgi/pom.xml
+++ b/weixin-java-osgi/pom.xml
@@ -6,7 +6,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.4.4-beta
+    2.4.5.BETA
   
 
   weixin-java-osgi

From 99d9fa7904d5236f452e496fbf34bedf2bc0f3dc Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Fri, 23 Dec 2016 18:19:52 +0800
Subject: [PATCH 04/76] Update README.md

---
 README.md | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md
index 3905934a..add84f7c 100644
--- a/README.md
+++ b/README.md
@@ -90,21 +90,21 @@ compile 'com.github.binarywang:weixin-java-cp:2.4.0'
 
 ## PR方式贡献代码步骤
 * 在 GitHub 上 `fork` 到自己的仓库,如 `my_user/weixin-java-tools`,然后 `clone` 到本地,并设置用户信息。
-```
-$ git clone git@github.com:my_user/weixin-java-tools.git
-$ cd weixin-java-tools
-$ git config user.name "yourname"
-$ git config user.email "your email"
+```bash
+ $ git clone git@github.com:my_user/weixin-java-tools.git
+ $ cd weixin-java-tools
+ $ git config user.name "yourname"
+ $ git config user.email "your email"
 ```
 * 修改代码后提交,并推送到自己的仓库。
-```
+```bash
 $ #do some change on the content
 $ git commit -am "Fix issue #1: change something"
 $ git push
 ```
 * 在 GitHub 网站上提交 Pull Request。
 * 定期使用项目仓库内容更新自己仓库内容。
-```
+```bash
 $ git remote add upstream https://github.com/wechat-group/weixin-java-tools
 $ git fetch upstream
 $ git checkout develop

From f2858c4042e5c672de96881811cd89376a453179 Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Fri, 23 Dec 2016 18:14:11 +0800
Subject: [PATCH 05/76] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=91=E9=80=81?=
 =?UTF-8?q?=E7=BA=A2=E5=8C=85=E6=8E=A5=E5=8F=A3?=
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-java-osgi/pom.xml   | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/pom.xml b/pom.xml
index 5d10472b..56763023 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
   4.0.0
   com.github.binarywang
   weixin-java-parent
-  2.4.4-beta
+  2.4.5.BETA
   pom
   WeiXin Java Tools - Parent
   微信公众号、企业号上级POM
diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml
index 25265a91..60f734d9 100644
--- a/weixin-java-common/pom.xml
+++ b/weixin-java-common/pom.xml
@@ -6,7 +6,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.4.4-beta
+    2.4.5.BETA
   
 
   weixin-java-common
diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
index 2e8a5515..43e5d414 100644
--- a/weixin-java-cp/pom.xml
+++ b/weixin-java-cp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.4.4-beta
+        2.4.5.BETA
     
 
     weixin-java-cp
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index 5c817853..9952c4cb 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -6,7 +6,7 @@
     
         com.github.binarywang
         weixin-java-parent
-        2.4.4-beta
+        2.4.5.BETA
     
     weixin-java-mp
     WeiXin Java Tools - MP
diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml
index 0c7c1f6d..a0f8d7e8 100644
--- a/weixin-java-osgi/pom.xml
+++ b/weixin-java-osgi/pom.xml
@@ -6,7 +6,7 @@
   
     com.github.binarywang
     weixin-java-parent
-    2.4.4-beta
+    2.4.5.BETA
   
 
   weixin-java-osgi

From ec0d1740e35d8ae6df660280344cd431406ddda2 Mon Sep 17 00:00:00 2001
From: "408033187@qq.com" 
Date: Sun, 25 Dec 2016 17:56:59 +0800
Subject: [PATCH 06/76] =?UTF-8?q?=E5=9C=A8=E5=8E=9F=E6=9D=A5=E7=9A=84?=
 =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=B8=8A=E5=88=9B=E5=BB=BA=E6=9B=B4=E7=AE=80?=
 =?UTF-8?q?=E6=B4=81=E7=9A=84=E8=B0=83=E7=94=A8=E7=BA=A2=E5=8C=85=E6=8E=A5?=
 =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E8=AF=B7=E5=9C=A8=E8=BF=99=E4=B9=8B=E5=89=8D?=
 =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=85=8D=E7=BD=AE=E4=B8=AD=E7=9A=84?=
 =?UTF-8?q?SslContext=EF=BC=8C=E6=96=B0=E5=A2=9ESslContext=E7=9A=84get|set?=
 =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E6=96=B9=E4=BE=BFspring=E6=B3=A8?=
 =?UTF-8?q?=E5=85=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../weixin/mp/api/WxMpConfigStorage.java      | 13 ++++
 .../mp/api/WxMpInMemoryConfigStorage.java     | 43 +++++++++--
 .../chanjar/weixin/mp/api/WxMpPayService.java | 31 ++++++++
 .../mp/api/impl/WxMpPayServiceImpl.java       | 76 ++++++++++++++++++-
 .../weixin/mp/api/impl/WxMpServiceImpl.java   | 18 ++---
 5 files changed, 163 insertions(+), 18 deletions(-)

diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
index d93c3080..b9b11fd7 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
@@ -118,7 +118,20 @@ public interface WxMpConfigStorage {
 
   File getTmpDirFile();
 
+  @Deprecated
   SSLContext getSSLContext();
+  
+  SSLContext getSslContext();
+  
+  void setSslContext(SSLContext sslContext);
+  
+	/**
+	 * 在此之前,必须将partnerId进行赋值
+	 * 
+	 * @param filePath
+	 *          apiclient_cert.p12的文件的绝对路径
+	 */
+	void setSslContextFilePath(String filePath) throws Exception;
 
   /**
    * http client builder
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java
index 61b75fbb..9fec33f8 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java
@@ -1,14 +1,19 @@
 package me.chanjar.weixin.mp.api;
 
-import me.chanjar.weixin.common.bean.WxAccessToken;
-import me.chanjar.weixin.common.util.ToStringUtils;
-import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
-
-import javax.net.ssl.SSLContext;
 import java.io.File;
+import java.io.FileInputStream;
+import java.security.KeyStore;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import javax.net.ssl.SSLContext;
+
+import org.apache.http.ssl.SSLContexts;
+
+import me.chanjar.weixin.common.bean.WxAccessToken;
+import me.chanjar.weixin.common.util.ToStringUtils;
+import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
+
 /**
  * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
  * @author chanjarster
@@ -300,11 +305,33 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage {
   public SSLContext getSSLContext() {
     return this.sslContext;
   }
-
-  public void setSSLContext(SSLContext context) {
-    this.sslContext = context;
+  
+  @Override
+  public SSLContext getSslContext() {
+  	return this.sslContext;
   }
 
+	@Override
+	public void setSslContextFilePath(String filePath) throws Exception {
+		if (null == partnerId) {
+			throw new Exception("请先将partnerId进行赋值");
+		}
+			File file = new File(filePath);
+			if (!file.exists()) {
+				throw new RuntimeException(file.getPath() + ":文件不存在!在设置SSLContext的时候");
+			}
+			FileInputStream inputStream = new FileInputStream(file);
+			KeyStore keystore = KeyStore.getInstance("PKCS12");
+			char[] partnerId2charArray = partnerId.toCharArray();
+			keystore.load(inputStream, partnerId2charArray);
+			this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build();
+	}
+	
+	@Override
+	public void setSslContext(SSLContext context) {
+		this.sslContext = context;
+	}
+  
   @Override
   public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
     return this.apacheHttpClientBuilder;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java
index afe888f8..b4dd3b29 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java
@@ -197,8 +197,24 @@ public interface WxMpPayService {
    * @param request 请求对象
    * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3)
    */
+  @Deprecated
   WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile) throws WxErrorException;
 
+  /**
+   * 发送微信红包给个人用户
+   * 
+   * 文档详见:
+   * 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
+   *  接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack
+   * 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4
+   *  接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack
+   * 
+ * + * @param request 请求对象 + * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) + */ + WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxErrorException; + /** *
    *   查询红包记录
@@ -211,7 +227,22 @@ public interface WxMpPayService {
    * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890
    * @param keyFile   证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3)
    */
+  @Deprecated
   WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException;
+  
+  /**
+   * 
+   *   查询红包记录
+   *   用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
+   *   请求Url	https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
+   *   是否需要证书	是(证书及使用说明详见商户证书)
+   *   请求方式	POST
+   * 
+ * + * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 + * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) + */ + WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException; /** *
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java
index 9bd4dad2..8751fc6c 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java
@@ -160,6 +160,7 @@ public class WxMpPayServiceImpl implements WxMpPayService {
 
 
   @Override
+  @Deprecated
   public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile)
     throws WxErrorException {
     XStream xstream = XStreamInitializer.getInstance();
@@ -179,8 +180,30 @@ public class WxMpPayServiceImpl implements WxMpPayService {
     this.checkResult(result);
     return result;
   }
+  
+  @Override
+  public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request)
+  		throws WxErrorException {
+  	XStream xstream = XStreamInitializer.getInstance();
+  	xstream.processAnnotations(WxPaySendRedpackRequest.class);
+  	xstream.processAnnotations(WxPaySendRedpackResult.class);
+  	
+  	initRequest(request);
+  	request.setSign(this.createSign(request));
+  	
+  	String url = PAY_BASE_URL + "/mmpaymkttransfers/sendredpack";
+  	if (request.getAmtType() != null) {
+  		//裂变红包
+  		url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack";
+  	}
+  	String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request));
+  	WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream.fromXML(responseContent);
+  	this.checkResult(result);
+  	return result;
+  }
 
   @Override
+  @Deprecated
   public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException {
     XStream xstream = XStreamInitializer.getInstance();
     xstream.processAnnotations(WxPayRedpackQueryRequest.class);
@@ -198,6 +221,25 @@ public class WxMpPayServiceImpl implements WxMpPayService {
     this.checkResult(result);
     return result;
   }
+  
+  @Override
+  public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException {
+  	XStream xstream = XStreamInitializer.getInstance();
+  	xstream.processAnnotations(WxPayRedpackQueryRequest.class);
+  	xstream.processAnnotations(WxPayRedpackQueryResult.class);
+  	
+  	WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest();
+  	request.setMchBillNo(mchBillNo);
+  	request.setBillType("MCHT");
+  	initRequest(request);
+  	request.setSign(this.createSign(request));
+  	
+  	String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo";
+  	String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request));
+  	WxPayRedpackQueryResult result = (WxPayRedpackQueryResult) xstream.fromXML(responseContent);
+  	this.checkResult(result);
+  	return result;
+  }
 
   @Override
   public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException {
@@ -383,7 +425,8 @@ public class WxMpPayServiceImpl implements WxMpPayService {
       httpPost.releaseConnection();
     }
   }
-
+  
+  @Deprecated
   private String executeRequestWithKeyFile(String url, File keyFile, String requestStr, String mchId) throws WxErrorException {
     try (FileInputStream inputStream = new FileInputStream(keyFile)) {
       KeyStore keyStore = KeyStore.getInstance("PKCS12");
@@ -414,6 +457,37 @@ public class WxMpPayServiceImpl implements WxMpPayService {
     }
   }
   
+  private String executeRequestWithKeyFile(String url, String requestStr) throws WxErrorException {
+  	try {
+  		
+  		SSLContext sslcontext = getConfig().getSSLContext();
+  		if(null==sslcontext){
+  			throw new Exception("请将配置类(WxMpInMemoryConfigStorage)中的SSLContext初始化");
+  		}
+  		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null,
+  				new DefaultHostnameVerifier());
+  		
+  		HttpPost httpPost = new HttpPost(url);
+  		if (this.wxMpService.getHttpProxy() != null) {
+  			httpPost.setConfig(RequestConfig.custom().setProxy(this.wxMpService.getHttpProxy()).build());
+  		}
+  		
+  		try (CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build()) {
+  			httpPost.setEntity(new StringEntity(new String(requestStr.getBytes("UTF-8"), "ISO-8859-1")));
+  			try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
+  				String result = EntityUtils.toString(response.getEntity(), Consts.UTF_8);
+  				this.log.debug("\n[URL]:  {}\n[PARAMS]: {}\n[RESPONSE]: {}", url, requestStr, result);
+  				return result;
+  			}
+  		} finally {
+  			httpPost.releaseConnection();
+  		}
+  	} catch (Exception e) {
+  		this.log.error("\n[URL]:  {}\n[PARAMS]: {}\n[EXCEPTION]: {}", url, requestStr, e.getMessage());
+  		throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e);
+  	}
+  }
+  
   @Override
   public String createSign(Object xmlBean) {
     return createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey());
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 ccb0bd2e..0008e20d 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
@@ -20,8 +20,8 @@ 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.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;
@@ -33,7 +33,7 @@ import java.util.concurrent.locks.Lock;
 public class WxMpServiceImpl implements WxMpService {
 
   private static final JsonParser JSON_PARSER = new JsonParser();
-
+  
   protected final Logger log = LoggerFactory.getLogger(this.getClass());
 
   private WxMpConfigStorage configStorage;
@@ -459,12 +459,12 @@ public class WxMpServiceImpl implements WxMpService {
         .httpProxyUsername(this.configStorage.getHttpProxyUsername())
         .httpProxyPassword(this.configStorage.getHttpProxyPassword());
 
-    if (this.configStorage.getSSLContext() != null) {
-      SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
-          this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null,
-          new DefaultHostnameVerifier());
-      apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf);
-    }
+		// if (this.configStorage.getSSLContext() != null) {
+		// SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
+		// this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null,
+		// new DefaultHostnameVerifier());
+		// apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf);
+		// }
 
     if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
       this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());

From 6f07a337264da201a11cbb4d0f42f625c0aa8bfd Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Mon, 26 Dec 2016 15:12:35 +0800
Subject: [PATCH 07/76] Update README.md

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index add84f7c..3e34c597 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK
 
 ## 版本说明
 1. 本项目定为每两个月发布一次正式版,版本号格式为X.X.0(如2.1.0,2.2.0等),月底发布新版本,遇到重大问题需修复会及时提交新版本,欢迎大家随时提交Pull Request;
-1. BUG修复和新特性一般会先发布成小版本作为临时测试版本(如2.0.1-beta,2.0.2-beta等,即尾号不为0,并添加beta字样,以区别于正式版);
+1. BUG修复和新特性一般会先发布成小版本作为临时测试版本(如2.4.5.BETA,2.4.6.BETA等,即尾号不为0,并添加BETA字样,以区别于正式版);
 1. 目前最新版本号为 [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.binarywang/weixin-java-parent/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.binarywang/weixin-java-parent) ,也可以通过访问链接 [【公众号】](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.binarywang%22%20AND%20a%3A%22weixin-java-mp%22) 、[【企业号】](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.binarywang%22%20AND%20a%3A%22weixin-java-cp%22)
 分别查看所有最新的版本。 
 

From 38d817cab2d06f989a03554f38d113211da37b74 Mon Sep 17 00:00:00 2001
From: Binary Wang 
Date: Mon, 26 Dec 2016 16:50:57 +0800
Subject: [PATCH 08/76] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BB=A3=E7=A0=81?=
 =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=8C=E5=B9=B6=E7=A7=BB=E9=99=A4=E4=B8=8D?=
 =?UTF-8?q?=E5=BF=85=E8=A6=81=E7=9A=84=E5=A4=9A=E4=BD=99=E4=BB=A3=E7=A0=81?=
 =?UTF-8?q?=20#107?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../weixin/mp/api/WxMpConfigStorage.java      |  46 +++---
 .../mp/api/WxMpInMemoryConfigStorage.java     | 156 +++++++++---------
 .../chanjar/weixin/mp/api/WxMpPayService.java |  49 +-----
 .../mp/api/impl/WxMpPayServiceImpl.java       | 144 ++++------------
 .../weixin/mp/api/impl/WxMpServiceImpl.java   |  78 ++++-----
 .../mp/api/impl/WxMpPayServiceImplTest.java   |  24 ++-
 6 files changed, 178 insertions(+), 319 deletions(-)

diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
index b9b11fd7..7dc29d4d 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java
@@ -4,14 +4,13 @@ import me.chanjar.weixin.common.bean.WxAccessToken;
 import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
 
 import javax.net.ssl.SSLContext;
-
 import java.io.File;
 import java.util.concurrent.locks.Lock;
 
 /**
  * 微信客户端配置存储
- * @author chanjarster
  *
+ * @author chanjarster
  */
 public interface WxMpConfigStorage {
 
@@ -28,13 +27,15 @@ public interface WxMpConfigStorage {
 
   /**
    * 应该是线程安全的
+   *
    * @param accessToken 要更新的WxAccessToken对象
    */
   void updateAccessToken(WxAccessToken accessToken);
 
   /**
    * 应该是线程安全的
-   * @param accessToken 新的accessToken值
+   *
+   * @param accessToken      新的accessToken值
    * @param expiresInSeconds 过期时间,以秒为单位
    */
   void updateAccessToken(String accessToken, int expiresInSeconds);
@@ -52,7 +53,8 @@ public interface WxMpConfigStorage {
 
   /**
    * 应该是线程安全的
-   * @param jsapiTicket 新的jsapi ticket值
+   *
+   * @param jsapiTicket      新的jsapi ticket值
    * @param expiresInSeconds 过期时间,以秒为单位
    */
   void updateJsapiTicket(String jsapiTicket, int expiresInSeconds);
@@ -70,7 +72,8 @@ public interface WxMpConfigStorage {
 
   /**
    * 应该是线程安全的
-   * @param cardApiTicket 新的cardApi ticket值
+   *
+   * @param cardApiTicket    新的cardApi ticket值
    * @param expiresInSeconds 过期时间,以秒为单位
    */
   void updateCardApiTicket(String cardApiTicket, int expiresInSeconds);
@@ -82,21 +85,23 @@ public interface WxMpConfigStorage {
   String getPartnerId();
 
   String getPartnerKey();
-  
+
   /**
    * 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数。
-   * @since 2.5.0
+   *
    * @return
+   * @since 2.5.0
    */
   String getNotifyURL();
-  
+
   /**
    * 交易类型
    * 
    * JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付
    * 
- * @since 2.5.0 + * * @return + * @since 2.5.0 */ String getTradeType(); @@ -118,23 +123,20 @@ public interface WxMpConfigStorage { File getTmpDirFile(); - @Deprecated - SSLContext getSSLContext(); - SSLContext getSslContext(); - + void setSslContext(SSLContext sslContext); - - /** - * 在此之前,必须将partnerId进行赋值 - * - * @param filePath - * apiclient_cert.p12的文件的绝对路径 - */ - void setSslContextFilePath(String filePath) throws Exception; + + /** + * 在此之前,必须将partnerId进行赋值 + * + * @param filePath apiclient_cert.p12的文件的绝对路径 + */ + void setSslContextFilePath(String filePath) throws Exception; /** * http client builder + * * @return ApacheHttpClientBuilder */ ApacheHttpClientBuilder getApacheHttpClientBuilder(); @@ -143,5 +145,5 @@ public interface WxMpConfigStorage { * 是否自动刷新token */ boolean autoRefreshToken(); - + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java index 9fec33f8..5172a5d7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java @@ -1,23 +1,21 @@ package me.chanjar.weixin.mp.api; +import me.chanjar.weixin.common.bean.WxAccessToken; +import me.chanjar.weixin.common.util.ToStringUtils; +import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; +import org.apache.http.ssl.SSLContexts; + +import javax.net.ssl.SSLContext; import java.io.File; import java.io.FileInputStream; import java.security.KeyStore; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import javax.net.ssl.SSLContext; - -import org.apache.http.ssl.SSLContexts; - -import me.chanjar.weixin.common.bean.WxAccessToken; -import me.chanjar.weixin.common.util.ToStringUtils; -import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; - /** * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化 - * @author chanjarster * + * @author chanjarster */ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { @@ -63,6 +61,10 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { return this.accessToken; } + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + @Override public Lock getAccessTokenLock() { return this.accessTokenLock; @@ -94,15 +96,15 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { return this.jsapiTicket; } + public void setJsapiTicket(String jsapiTicket) { + this.jsapiTicket = jsapiTicket; + } + @Override public Lock getJsapiTicketLock() { return this.jsapiTicketLock; } - public void setJsapiTicket(String jsapiTicket) { - this.jsapiTicket = jsapiTicket; - } - public long getJsapiTicketExpiresTime() { return this.jsapiTicketExpiresTime; } @@ -163,31 +165,35 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { return this.appId; } + public void setAppId(String appId) { + this.appId = appId; + } + @Override public String getSecret() { return this.secret; } + public void setSecret(String secret) { + this.secret = secret; + } + @Override public String getToken() { return this.token; } + public void setToken(String token) { + this.token = token; + } + @Override public long getExpiresTime() { return this.expiresTime; } - public void setAppId(String appId) { - this.appId = appId; - } - - public void setSecret(String secret) { - this.secret = secret; - } - - public void setToken(String token) { - this.token = token; + public void setExpiresTime(long expiresTime) { + this.expiresTime = expiresTime; } @Override @@ -199,14 +205,6 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { this.aesKey = aesKey; } - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - public void setExpiresTime(long expiresTime) { - this.expiresTime = expiresTime; - } - @Override public String getOauth2redirectUri() { return this.oauth2redirectUri; @@ -259,40 +257,40 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { @Override public String getPartnerId() { - return this.partnerId; + return this.partnerId; } public void setPartnerId(String partnerId) { - this.partnerId = partnerId; + this.partnerId = partnerId; } @Override public String getPartnerKey() { - return this.partnerKey; + return this.partnerKey; } public void setPartnerKey(String partnerKey) { - this.partnerKey = partnerKey; + this.partnerKey = partnerKey; + } + + + public String getNotifyURL() { + return notifyURL; } - - - public String getNotifyURL() { - return notifyURL; - } - public void setNotifyURL(String notifyURL) { - this.notifyURL = notifyURL; - } + public void setNotifyURL(String notifyURL) { + this.notifyURL = notifyURL; + } - public String getTradeType() { - return tradeType; - } + public String getTradeType() { + return tradeType; + } - public void setTradeType(String tradeType) { - this.tradeType = tradeType; - } + public void setTradeType(String tradeType) { + this.tradeType = tradeType; + } - @Override + @Override public File getTmpDirFile() { return this.tmpDirFile; } @@ -302,47 +300,43 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { } @Override - public SSLContext getSSLContext() { + public SSLContext getSslContext() { return this.sslContext; } - + @Override - public SSLContext getSslContext() { - return this.sslContext; - } - - @Override - public void setSslContextFilePath(String filePath) throws Exception { - if (null == partnerId) { - throw new Exception("请先将partnerId进行赋值"); - } - File file = new File(filePath); - if (!file.exists()) { - throw new RuntimeException(file.getPath() + ":文件不存在!在设置SSLContext的时候"); - } - FileInputStream inputStream = new FileInputStream(file); - KeyStore keystore = KeyStore.getInstance("PKCS12"); - char[] partnerId2charArray = partnerId.toCharArray(); - keystore.load(inputStream, partnerId2charArray); - this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build(); - } - - @Override - public void setSslContext(SSLContext context) { - this.sslContext = context; - } - + public void setSslContext(SSLContext context) { + this.sslContext = context; + } + @Override - public ApacheHttpClientBuilder getApacheHttpClientBuilder() { - return this.apacheHttpClientBuilder; + public void setSslContextFilePath(String filePath) throws Exception { + if (null == partnerId) { + throw new Exception("请先将partnerId进行赋值"); + } + + File file = new File(filePath); + if (!file.exists()) { + throw new RuntimeException(file.getPath() + ":文件不存在!在设置SSLContext的时候"); + } + FileInputStream inputStream = new FileInputStream(file); + KeyStore keystore = KeyStore.getInstance("PKCS12"); + char[] partnerId2charArray = partnerId.toCharArray(); + keystore.load(inputStream, partnerId2charArray); + this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build(); } @Override - public boolean autoRefreshToken() { - return true; + public ApacheHttpClientBuilder getApacheHttpClientBuilder() { + return this.apacheHttpClientBuilder; } public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) { this.apacheHttpClientBuilder = apacheHttpClientBuilder; } + + @Override + public boolean autoRefreshToken() { + return true; + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java index b4dd3b29..79787744 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java @@ -7,7 +7,6 @@ import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; import me.chanjar.weixin.mp.bean.pay.result.*; -import java.io.File; import java.util.Map; /** @@ -76,10 +75,9 @@ public interface WxMpPayService { *
* * @param request 请求对象 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) * @return 退款操作结果 */ - WxPayRefundResult refund(WxPayRefundRequest request, File keyFile) throws WxErrorException; + WxPayRefundResult refund(WxPayRefundRequest request) throws WxErrorException; /** *
@@ -128,7 +126,7 @@ public interface WxMpPayService {
   /**
    * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3)
    *
-   * @param prams   参数信息,默认使用配置中的PartnerKey进行签名
+   * @param prams 参数信息,默认使用配置中的PartnerKey进行签名
    * @return 签名字符串
    * @see #createSign(Map, String)
    */
@@ -176,7 +174,7 @@ public interface WxMpPayService {
   /**
    * 校验签名是否正确
    *
-   * @param params   需要校验的参数Map
+   * @param params  需要校验的参数Map
    * @param signKey 校验的签名Key
    * @return true - 签名校验成功,false - 签名校验失败
    * @see #checkSign(Map, String)
@@ -195,41 +193,9 @@ public interface WxMpPayService {
    * 
* * @param request 请求对象 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) - */ - @Deprecated - WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile) throws WxErrorException; - - /** - * 发送微信红包给个人用户 - *
-   * 文档详见:
-   * 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
-   *  接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack
-   * 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4
-   *  接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack
-   * 
- * - * @param request 请求对象 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxErrorException; - - /** - *
-   *   查询红包记录
-   *   用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
-   *   请求Url	https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
-   *   是否需要证书	是(证书及使用说明详见商户证书)
-   *   请求方式	POST
-   * 
- * - * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) - */ - @Deprecated - WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException; - + /** *
    *   查询红包记录
@@ -240,7 +206,6 @@ public interface WxMpPayService {
    * 
* * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException; @@ -255,9 +220,8 @@ public interface WxMpPayService { *
* * @param request 请求对象 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ - WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException; + WxEntPayResult entPay(WxEntPayRequest request) throws WxErrorException; /** *
@@ -268,8 +232,7 @@ public interface WxMpPayService {
    * 
* * @param partnerTradeNo 商户订单号 - * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) */ - WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException; + WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorException; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java index 8751fc6c..8ad6ed35 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java @@ -23,16 +23,12 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.net.ssl.SSLContext; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.security.KeyStore; import java.util.*; /** @@ -44,7 +40,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { private static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com"; private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP"}; - private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS","REFUND_SOURCE_UNSETTLED_FUNDS"}; + private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS", "REFUND_SOURCE_UNSETTLED_FUNDS"}; private final Logger log = LoggerFactory.getLogger(this.getClass()); private WxMpService wxMpService; @@ -57,20 +53,20 @@ public class WxMpPayServiceImpl implements WxMpPayService { } @Override - public WxPayRefundResult refund(WxPayRefundRequest request, File keyFile) throws WxErrorException { + public WxPayRefundResult refund(WxPayRefundRequest request) throws WxErrorException { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPayRefundRequest.class); xstream.processAnnotations(WxPayRefundResult.class); - + initRequest(request); - if(StringUtils.isBlank(request.getOpUserId())){ + if (StringUtils.isBlank(request.getOpUserId())) { request.setOpUserId(getConfig().getPartnerId()); } checkParameters(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/secapi/pay/refund"; - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); + String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); WxPayRefundResult result = (WxPayRefundResult) xstream.fromXML(responseContent); this.checkResult(result); return result; @@ -158,10 +154,8 @@ public class WxMpPayServiceImpl implements WxMpPayService { } } - @Override - @Deprecated - public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile) + public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxErrorException { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPaySendRedpackRequest.class); @@ -175,36 +169,14 @@ public class WxMpPayServiceImpl implements WxMpPayService { //裂变红包 url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack"; } - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); + String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream.fromXML(responseContent); this.checkResult(result); return result; } - - @Override - public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) - throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPaySendRedpackRequest.class); - xstream.processAnnotations(WxPaySendRedpackResult.class); - - initRequest(request); - request.setSign(this.createSign(request)); - - String url = PAY_BASE_URL + "/mmpaymkttransfers/sendredpack"; - if (request.getAmtType() != null) { - //裂变红包 - url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack"; - } - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream.fromXML(responseContent); - this.checkResult(result); - return result; - } @Override - @Deprecated - public WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException { + public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPayRedpackQueryRequest.class); xstream.processAnnotations(WxPayRedpackQueryResult.class); @@ -216,30 +188,11 @@ public class WxMpPayServiceImpl implements WxMpPayService { request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo"; - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); + String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); WxPayRedpackQueryResult result = (WxPayRedpackQueryResult) xstream.fromXML(responseContent); this.checkResult(result); return result; } - - @Override - public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayRedpackQueryRequest.class); - xstream.processAnnotations(WxPayRedpackQueryResult.class); - - WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest(); - request.setMchBillNo(mchBillNo); - request.setBillType("MCHT"); - initRequest(request); - request.setSign(this.createSign(request)); - - String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo"; - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxPayRedpackQueryResult result = (WxPayRedpackQueryResult) xstream.fromXML(responseContent); - this.checkResult(result); - return result; - } @Override public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException { @@ -296,17 +249,17 @@ public class WxMpPayServiceImpl implements WxMpPayService { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxPayUnifiedOrderRequest.class); xstream.processAnnotations(WxPayUnifiedOrderResult.class); - + initRequest(request); - if(StringUtils.isBlank(request.getNotifyURL())){ + if (StringUtils.isBlank(request.getNotifyURL())) { request.setNotifyURL(getConfig().getNotifyURL()); } - if(StringUtils.isBlank(request.getTradeType())){ + if (StringUtils.isBlank(request.getTradeType())) { request.setTradeType(getConfig().getTradeType()); } checkParameters(request);//校验参数 request.setSign(this.createSign(request)); - + String url = PAY_BASE_URL + "/pay/unifiedorder"; String xmlParam = xstream.toXML(request); log.debug("微信统一下单接口,URL:{},参数:{}", url, xmlParam); @@ -317,15 +270,15 @@ public class WxMpPayServiceImpl implements WxMpPayService { this.checkResult(result); return result; } - - private void initRequest(WxPayBaseRequest request){ - if(StringUtils.isBlank(request.getAppid())){ + + private void initRequest(WxPayBaseRequest request) { + if (StringUtils.isBlank(request.getAppid())) { request.setAppid(getConfig().getAppId()); } - if(StringUtils.isBlank(request.getMchId())){ + if (StringUtils.isBlank(request.getMchId())) { request.setMchId(getConfig().getPartnerId()); } - if(StringUtils.isBlank(request.getNonceStr())){ + if (StringUtils.isBlank(request.getNonceStr())) { request.setNonceStr(String.valueOf(System.currentTimeMillis())); } } @@ -370,25 +323,25 @@ public class WxMpPayServiceImpl implements WxMpPayService { } @Override - public WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException { + public WxEntPayResult entPay(WxEntPayRequest request) throws WxErrorException { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxEntPayRequest.class); xstream.processAnnotations(WxEntPayResult.class); - + initRequest(request); BeanUtils.checkRequiredFields(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/promotion/transfers"; - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); + String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); WxEntPayResult result = (WxEntPayResult) xstream.fromXML(responseContent); this.checkResult(result); return result; } @Override - public WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException { + public WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorException { XStream xstream = XStreamInitializer.getInstance(); xstream.processAnnotations(WxEntPayQueryRequest.class); xstream.processAnnotations(WxEntPayQueryResult.class); @@ -398,7 +351,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/gettransferinfo"; - String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId()); + String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); WxEntPayQueryResult result = (WxEntPayQueryResult) xstream.fromXML(responseContent); this.checkResult(result); return result; @@ -425,15 +378,15 @@ public class WxMpPayServiceImpl implements WxMpPayService { httpPost.releaseConnection(); } } - - @Deprecated - private String executeRequestWithKeyFile(String url, File keyFile, String requestStr, String mchId) throws WxErrorException { - try (FileInputStream inputStream = new FileInputStream(keyFile)) { - KeyStore keyStore = KeyStore.getInstance("PKCS12"); - keyStore.load(inputStream, mchId.toCharArray()); - - SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, mchId.toCharArray()).build(); - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null, + + private String executeRequestWithKeyFile(String url, String requestStr) throws WxErrorException { + try { + SSLContext sslContext = getConfig().getSslContext(); + if (null == sslContext) { + throw new Exception("请将配置类(即WxMpConfigStorage的实现类)中的SSLContext初始化"); + } + + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[]{"TLSv1"}, null, new DefaultHostnameVerifier()); HttpPost httpPost = new HttpPost(url); @@ -456,38 +409,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e); } } - - private String executeRequestWithKeyFile(String url, String requestStr) throws WxErrorException { - try { - - SSLContext sslcontext = getConfig().getSSLContext(); - if(null==sslcontext){ - throw new Exception("请将配置类(WxMpInMemoryConfigStorage)中的SSLContext初始化"); - } - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null, - new DefaultHostnameVerifier()); - - HttpPost httpPost = new HttpPost(url); - if (this.wxMpService.getHttpProxy() != null) { - httpPost.setConfig(RequestConfig.custom().setProxy(this.wxMpService.getHttpProxy()).build()); - } - - try (CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build()) { - httpPost.setEntity(new StringEntity(new String(requestStr.getBytes("UTF-8"), "ISO-8859-1"))); - try (CloseableHttpResponse response = httpclient.execute(httpPost)) { - String result = EntityUtils.toString(response.getEntity(), Consts.UTF_8); - this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", url, requestStr, result); - return result; - } - } finally { - httpPost.releaseConnection(); - } - } catch (Exception e) { - this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", url, requestStr, e.getMessage()); - throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e); - } - } - + @Override public String createSign(Object xmlBean) { return createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); 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 0008e20d..d2aa2a2c 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 @@ -20,8 +20,6 @@ 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; @@ -30,55 +28,39 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.concurrent.locks.Lock; +//import org.apache.http.conn.ssl.DefaultHostnameVerifier; +//import org.apache.http.conn.ssl.SSLConnectionSocketFactory; + public class WxMpServiceImpl implements WxMpService { private static final JsonParser JSON_PARSER = new JsonParser(); - - protected final Logger log = LoggerFactory.getLogger(this.getClass()); + protected final Logger log = LoggerFactory.getLogger(this.getClass()); + protected WxSessionManager sessionManager = new StandardSessionManager(); private WxMpConfigStorage configStorage; - private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); - private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this); - private WxMpMenuService menuService = new WxMpMenuServiceImpl(this); - private WxMpUserService userService = new WxMpUserServiceImpl(this); - private WxMpUserTagService tagService = new WxMpUserTagServiceImpl(this); - private WxMpQrcodeService qrCodeService = new WxMpQrcodeServiceImpl(this); - private WxMpCardService cardService = new WxMpCardServiceImpl(this); - private WxMpPayService payService = new WxMpPayServiceImpl(this); - private WxMpStoreService storeService = new WxMpStoreServiceImpl(this); - private WxMpDataCubeService dataCubeService = new WxMpDataCubeServiceImpl(this); - private WxMpUserBlacklistService blackListService = new WxMpUserBlacklistServiceImpl(this); - private WxMpTemplateMsgService templateMsgService = new WxMpTemplateMsgServiceImpl(this); - private WxMpDeviceService deviceService = new WxMpDeviceServiceImpl(this); - private CloseableHttpClient httpClient; - private HttpHost httpProxy; - private int retrySleepMillis = 1000; - private int maxRetryTimes = 5; - protected WxSessionManager sessionManager = new StandardSessionManager(); - @Override public boolean checkSignature(String timestamp, String nonce, String signature) { try { return SHA1.gen(this.configStorage.getToken(), timestamp, nonce) - .equals(signature); + .equals(signature); } catch (Exception e) { return false; } @@ -101,8 +83,8 @@ public class WxMpServiceImpl implements WxMpService { if (this.configStorage.isAccessTokenExpired()) { String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" + - "&appid=" + this.configStorage.getAppId() + "&secret=" - + this.configStorage.getSecret(); + "&appid=" + this.configStorage.getAppId() + "&secret=" + + this.configStorage.getSecret(); try { HttpGet httpGet = new HttpGet(url); if (this.httpProxy != null) { @@ -117,8 +99,8 @@ public class WxMpServiceImpl implements WxMpService { } WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); this.configStorage.updateAccessToken(accessToken.getAccessToken(), - accessToken.getExpiresIn()); - }finally { + accessToken.getExpiresIn()); + } finally { httpGet.releaseConnection(); } } catch (IOException e) { @@ -167,7 +149,7 @@ public class WxMpServiceImpl implements WxMpService { String noncestr = RandomUtils.getRandomStr(); String jsapiTicket = getJsapiTicket(false); String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket, - "noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url); + "noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url); WxJsapiSignature jsapiSignature = new WxJsapiSignature(); jsapiSignature.setAppid(this.configStorage.getAppId()); jsapiSignature.setTimestamp(timestamp); @@ -247,7 +229,7 @@ public class WxMpServiceImpl implements WxMpService { @Override public String buildQrConnectUrl(String redirectURI, String scope, - String state) { + String state) { StringBuilder url = new StringBuilder(); url.append("https://open.weixin.qq.com/connect/qrconnect?"); url.append("appid=").append(this.configStorage.getAppId()); @@ -366,7 +348,7 @@ public class WxMpServiceImpl implements WxMpService { do { try { T result = executeInternal(executor, uri, data); - this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}",uri, data, result); + this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data, result); return result; } catch (WxErrorException e) { if (retryTimes + 1 > this.maxRetryTimes) { @@ -416,7 +398,7 @@ public class WxMpServiceImpl implements WxMpService { if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) { // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token this.configStorage.expireAccessToken(); - if(this.configStorage.autoRefreshToken()){ + if (this.configStorage.autoRefreshToken()) { return this.execute(executor, uri, data); } } @@ -441,30 +423,24 @@ public class WxMpServiceImpl implements WxMpService { return this.httpClient; } - @Override - public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) { - this.configStorage = wxConfigProvider; - this.initHttpClient(); - } - private void initHttpClient() { ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage - .getApacheHttpClientBuilder(); + .getApacheHttpClientBuilder(); if (null == apacheHttpClientBuilder) { apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get(); } apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost()) - .httpProxyPort(this.configStorage.getHttpProxyPort()) - .httpProxyUsername(this.configStorage.getHttpProxyUsername()) - .httpProxyPassword(this.configStorage.getHttpProxyPassword()); + .httpProxyPort(this.configStorage.getHttpProxyPort()) + .httpProxyUsername(this.configStorage.getHttpProxyUsername()) + .httpProxyPassword(this.configStorage.getHttpProxyPassword()); - // if (this.configStorage.getSSLContext() != null) { - // SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - // this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null, - // new DefaultHostnameVerifier()); - // apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf); - // } + // if (this.configStorage.getSSLContext() != null) { + // SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + // this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null, + // new DefaultHostnameVerifier()); + // apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf); + // } if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) { this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort()); @@ -478,6 +454,12 @@ public class WxMpServiceImpl implements WxMpService { return this.configStorage; } + @Override + public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) { + this.configStorage = wxConfigProvider; + this.initHttpClient(); + } + @Override public void setRetrySleepMillis(int retrySleepMillis) { this.retrySleepMillis = retrySleepMillis; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 7b2a9dea..31fc0c06 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -34,7 +34,7 @@ public class WxMpPayServiceImplTest { } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest, File)} . + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest)} . */ @Test public void testRefund() throws Exception { @@ -43,8 +43,7 @@ public class WxMpPayServiceImplTest { request.setOutTradeNo("1111"); request.setTotalFee(1222); request.setRefundFee(111); - File keyFile = new File("E:\\dlt.p12"); - WxPayRefundResult result = this.wxService.getPayService().refund(request, keyFile); + WxPayRefundResult result = this.wxService.getPayService().refund(request); System.err.println(result); } @@ -72,7 +71,7 @@ public class WxMpPayServiceImplTest { } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#sendRedpack(WxPaySendRedpackRequest, File)} . + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#sendRedpack(WxPaySendRedpackRequest)} . */ @Test public void testSendRedpack() throws Exception { @@ -82,18 +81,17 @@ public class WxMpPayServiceImplTest { request.setMchBillNo("aaaa"); request .setReOpenid(((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); - File keyFile = new File("E:\\dlt.p12"); - WxPaySendRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request, keyFile); + WxPaySendRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request); System.err.println(redpackResult); } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryRedpack(String, File)}. + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryRedpack(String)}. */ @Test public void testQueryRedpack() throws Exception { File keyFile = new File("E:\\dlt.p12"); - WxPayRedpackQueryResult redpackResult = this.wxService.getPayService().queryRedpack("aaaa", keyFile); + WxPayRedpackQueryResult redpackResult = this.wxService.getPayService().queryRedpack("aaaa"); System.err.println(redpackResult); } @@ -128,21 +126,19 @@ public class WxMpPayServiceImplTest { } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#entPay(WxEntPayRequest, File)}. + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#entPay(WxEntPayRequest)}. */ @Test public final void testEntPay() throws WxErrorException { - File keyFile = new File("E:\\dlt.p12"); WxEntPayRequest request = new WxEntPayRequest(); - System.err.println(this.wxService.getPayService().entPay(request, keyFile)); + System.err.println(this.wxService.getPayService().entPay(request)); } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryEntPay(String, File)}. + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryEntPay(String)}. */ @Test public final void testQueryEntPay() throws WxErrorException { - File keyFile = new File("E:\\dlt.p12"); - System.err.println(this.wxService.getPayService().queryEntPay("11212121", keyFile)); + System.err.println(this.wxService.getPayService().queryEntPay("11212121")); } } From 76f4e0b12094a7ab27bff2e6cb44593343c7fd5e Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 26 Dec 2016 17:01:10 +0800 Subject: [PATCH 09/76] release 2.4.6.BETA --- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- weixin-java-osgi/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 56763023..24e46e39 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.4.5.BETA + 2.4.6.BETA pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 60f734d9..5b55b6af 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.5.BETA + 2.4.6.BETA weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 43e5d414..3b8072c6 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.5.BETA + 2.4.6.BETA weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 9952c4cb..9db06d7a 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.5.BETA + 2.4.6.BETA weixin-java-mp WeiXin Java Tools - MP diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml index a0f8d7e8..8667d330 100644 --- a/weixin-java-osgi/pom.xml +++ b/weixin-java-osgi/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.5.BETA + 2.4.6.BETA weixin-java-osgi From 87770f4b3f97a8588767f36c407a3272eee73b65 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 26 Dec 2016 17:42:26 +0800 Subject: [PATCH 10/76] fix some javadoc warnings --- .../weixin/mp/api/WxMpConfigStorage.java | 2 - .../mp/bean/pay/request/WxPayBaseRequest.java | 15 +- .../mp/bean/pay/result/WxPayBaseResult.java | 14 +- .../pay/result/WxPayOrderNotifyResult.java | 784 +++++++++--------- 4 files changed, 394 insertions(+), 421 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java index 7dc29d4d..cff903bf 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java @@ -89,7 +89,6 @@ public interface WxMpConfigStorage { /** * 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数。 * - * @return * @since 2.5.0 */ String getNotifyURL(); @@ -100,7 +99,6 @@ public interface WxMpConfigStorage { * JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付 *
* - * @return * @since 2.5.0 */ String getTradeType(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java index d6926d0e..3bfe556f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java @@ -1,10 +1,10 @@ package me.chanjar.weixin.mp.bean.pay.request; -import java.math.BigDecimal; - import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.util.ToStringUtils; +import java.math.BigDecimal; + /** *
  * Created by Binary Wang on 2016-10-24.
@@ -75,7 +75,7 @@ public abstract class WxPayBaseRequest {
 
   /**
    * 如果配置中已经设置,可以不设置值
-   * @param appid
+   * @param appid 微信公众号appid
    */
   public void setAppid(String appid) {
     this.appid = appid;
@@ -87,7 +87,7 @@ public abstract class WxPayBaseRequest {
 
   /**
    * 如果配置中已经设置,可以不设置值
-   * @param mchId
+   * @param mchId 微信商户号
    */
   public void setMchId(String mchId) {
     this.mchId = mchId;
@@ -99,7 +99,7 @@ public abstract class WxPayBaseRequest {
 
   /**
    * 默认采用时间戳为随机字符串,可以不设置
-   * @param nonceStr
+   * @param nonceStr 随机字符串
    */
   public void setNonceStr(String nonceStr) {
     this.nonceStr = nonceStr;
@@ -112,12 +112,11 @@ public abstract class WxPayBaseRequest {
   public void setSign(String sign) {
     this.sign = sign;
   }
-  
+
   /**
    * 将单位为元转换为单位为分
    *
-   * @param yuan
-   * @return
+   * @param yuan 将要转换的元的数值字符串
    */
   public static Integer yuanToFee(String yuan) {
     return  new BigDecimal(yuan).setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue();
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java
index b719e333..cafd8a56 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java
@@ -1,13 +1,12 @@
 package me.chanjar.weixin.mp.bean.pay.result;
 
-import java.math.BigDecimal;
-import java.util.Map;
-
 import com.thoughtworks.xstream.annotations.XStreamAlias;
-
 import me.chanjar.weixin.common.util.BeanUtils;
 import me.chanjar.weixin.common.util.ToStringUtils;
 
+import java.math.BigDecimal;
+import java.util.Map;
+
 /**
  * 
  * 微信支付结果共用属性类
@@ -146,16 +145,15 @@ public abstract class WxPayBaseResult {
   public void setSign(String sign) {
     this.sign = sign;
   }
-  
+
   /**
    * 将单位分转换成单位圆
-   * @param fee
-   * @return
+   * @param fee 将要被转换为元的分的数值
    */
   public static String feeToYuan(Integer fee) {
     return new BigDecimal(Double.valueOf(fee) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString();
   }
-  
+
   public Map toMap(){
   	return BeanUtils.xmlBean2Map(this);
   }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java
index 3c782477..a5770873 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java
@@ -1,403 +1,381 @@
-package me.chanjar.weixin.mp.bean.pay.result;
-
-import java.io.Serializable;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
-import com.thoughtworks.xstream.annotations.XStreamAlias;
-
-import me.chanjar.weixin.common.util.BeanUtils;
-import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyCoupon;
-
-/**
- * 支付结果通用通知 ,文档见:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
- * @author aimilin6688
- * @since 2.5.0
- */
-@XStreamAlias("xml")
-public class WxPayOrderNotifyResult  extends WxPayBaseResult implements Serializable {
-
-	/**
-	 * @fields serialVersionUID 
-	 */
-	private static final long serialVersionUID = 5389718115223345496L;
-	
-	
-	/**
-	 * 
-	 * 设备号
-	 * device_info	
-	 * 否	
-	 * String(32)	
-	 * 013467007045764	
-	 * 微信支付分配的终端设备号,
-	 * 
- * @fields deviceInfo - */ - @XStreamAlias("device_info") - private String deviceInfo; - - /** - *
-	 * 用户标识	
-	 * openid	
-	 * 是	
-	 * String(128)	
-	 * wxd930ea5d5a258f4f	
-	 * 用户在商户appid下的唯一标识
-	 * 
- * @fields openid - */ - @XStreamAlias("openid") - private String openid; - - /** - *
-	 * 是否关注公众账号	
-	 * is_subscribe	
-	 * 否	
-	 * String(1)	
-	 * Y	
-	 * 用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
-	 * 
- * @fields isSubscribe - */ - @XStreamAlias("is_subscribe") - private String isSubscribe; - - - /** - *
-	 * 交易类型	
-	 * trade_type	
-	 * 是	
-	 * String(16)	
-	 * JSAPI	JSAPI、NATIVE、APP
-	 * 
- * @fields tradeType - */ - @XStreamAlias("trade_type") - private String tradeType; - - - /** - *
-	 * 付款银行	
-	 * bank_type	
-	 * 是	
-	 * String(16)	
-	 * CMC	
-	 * 银行类型,采用字符串类型的银行标识,银行类型见银行列表
-	 * 
- * @fields bankType - */ - @XStreamAlias("bank_type") - private String bankType; - - - /** - *
-	 * 订单金额	
-	 * total_fee	
-	 * 是	
-	 * Int	
-	 * 100	
-	 * 订单总金额,单位为分
-	 * 
- * @fields totalFee - */ - @XStreamAlias("total_fee") - private Integer totalFee; - /** - *
-	 * 应结订单金额	
-	 * settlement_total_fee	
-	 * 否	
-	 * Int	
-	 * 100	
-	 * 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
-	 * 
- * @fields settlementTotalFee - */ - @XStreamAlias("settlement_total_fee") - private Integer settlementTotalFee; - /** - *
-	 * 货币种类	
-	 * fee_type	
-	 * 否	
-	 * String(8)	
-	 * CNY	
-	 * 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
-	 * 
- * @fields feeType - */ - @XStreamAlias("fee_type") - private String feeType; - /** - *
-	 * 现金支付金额	
-	 * cash_fee	
-	 * 是	
-	 * Int	
-	 * 100	
-	 * 现金支付金额订单现金支付金额,详见支付金额
-	 * 
- * @fields cashFee - */ - @XStreamAlias("cash_fee") - private Integer cashFee; - /** - *
-	 * 现金支付货币类型	
-	 * cash_fee_type	
-	 * 否	
-	 * String(16)	
-	 * CNY	
-	 * 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
-	 * 
- * @fields cashFeeType - */ - @XStreamAlias("cash_fee_type") - private String cashFeeType; - /** - *
-	 * 总代金券金额	
-	 * coupon_fee	
-	 * 否	
-	 * Int	
-	 * 10	
-	 * 代金券金额<=订单金额,订单金额-代金券金额=现金支付金额,详见支付金额
-	 * 
- * @fields couponFee - */ - @XStreamAlias("coupon_fee") - private Integer couponFee; - - /** - *
-   * 代金券使用数量
-   * coupon_count
-   * 否
-   * Int
-   * 1
-   * 代金券使用数量
-   */
-	@XStreamAlias("coupon_count")
-	private Integer couponCount;
-	
-	private List couponList;
-	
-	
-	
-	/**
-	 * 
-	 * 微信支付订单号	
-	 * transaction_id	
-	 * 是	
-	 * String(32)	
-	 * 1217752501201407033233368018	
-	 * 微信支付订单号
-	 * 
- * @fields transactionId - */ - @XStreamAlias("transaction_id") - private String transactionId; - - /** - *
-	 * 商户订单号	
-	 * out_trade_no	
-	 * 是	
-	 * String(32)	
-	 * 1212321211201407033568112322	
-	 * 商户系统的订单号,与请求一致。
-	 * 
- * @fields outTradeNo - */ - @XStreamAlias("out_trade_no") - private String outTradeNo; - /** - *
-	 * 商家数据包	
-	 * attach	
-	 * 否	
-	 * String(128)	
-	 * 123456	
-	 * 商家数据包,原样返回
-	 * 
- * @fields - */ - @XStreamAlias("attach") - private String attach; - /** - *
-	 * 支付完成时间	
-	 * time_end	
-	 * 是	
-	 * String(14)	
-	 * 20141030133525	
-	 * 支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
-	 * 
- * @fields timeEnd - */ - @XStreamAlias("time_end") - private String timeEnd; - - - public Integer getCouponCount() { - return couponCount; - } - - public void setCouponCount(Integer couponCount) { - this.couponCount = couponCount; - } - - public List getCouponList() { - return couponList; - } - - public void setCouponList(List couponList) { - this.couponList = couponList; - } - - public String getDeviceInfo() { - return deviceInfo; - } - - public void setDeviceInfo(String deviceInfo) { - this.deviceInfo = deviceInfo; - } - - public String getOpenid() { - return openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public String getIsSubscribe() { - return isSubscribe; - } - - public void setIsSubscribe(String isSubscribe) { - this.isSubscribe = isSubscribe; - } - - public String getTradeType() { - return tradeType; - } - - public void setTradeType(String tradeType) { - this.tradeType = tradeType; - } - - public String getBankType() { - return bankType; - } - - public void setBankType(String bankType) { - this.bankType = bankType; - } - - public Integer getTotalFee() { - return totalFee; - } - - public void setTotalFee(Integer totalFee) { - this.totalFee = totalFee; - } - - public Integer getSettlementTotalFee() { - return settlementTotalFee; - } - - public void setSettlementTotalFee(Integer settlementTotalFee) { - this.settlementTotalFee = settlementTotalFee; - } - - public String getFeeType() { - return feeType; - } - - public void setFeeType(String feeType) { - this.feeType = feeType; - } - - public Integer getCashFee() { - return cashFee; - } - - public void setCashFee(Integer cashFee) { - this.cashFee = cashFee; - } - - public String getCashFeeType() { - return cashFeeType; - } - - public void setCashFeeType(String cashFeeType) { - this.cashFeeType = cashFeeType; - } - - public Integer getCouponFee() { - return couponFee; - } - - public void setCouponFee(Integer couponFee) { - this.couponFee = couponFee; - } - - public String getTransactionId() { - return transactionId; - } - - public void setTransactionId(String transactionId) { - this.transactionId = transactionId; - } - - public String getOutTradeNo() { - return outTradeNo; - } - - public void setOutTradeNo(String outTradeNo) { - this.outTradeNo = outTradeNo; - } - - public String getAttach() { - return attach; - } - - public void setAttach(String attach) { - this.attach = attach; - } - - public String getTimeEnd() { - return timeEnd; - } - - public void setTimeEnd(String timeEnd) { - this.timeEnd = timeEnd; - } - - @Override - public Map toMap(){ - Map resultMap = BeanUtils.xmlBean2Map(this); - if(this.getCouponCount() != null && this.getCouponCount() > 0){ - for (int i = 0; i < this.getCouponCount(); i++) { - WxPayOrderNotifyCoupon coupon = couponList.get(i); - resultMap.putAll(coupon.toMap(i)); - } - } - return resultMap; - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE); - } -} +package me.chanjar.weixin.mp.bean.pay.result; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import me.chanjar.weixin.common.util.BeanUtils; +import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyCoupon; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * 支付结果通用通知 ,文档见:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 + * @author aimilin6688 + * @since 2.5.0 + */ +@XStreamAlias("xml") +public class WxPayOrderNotifyResult extends WxPayBaseResult implements Serializable { + + private static final long serialVersionUID = 5389718115223345496L; + + + /** + *
+	 * 设备号
+	 * device_info
+	 * 否
+	 * String(32)
+	 * 013467007045764
+	 * 微信支付分配的终端设备号,
+	 * 
+ */ + @XStreamAlias("device_info") + private String deviceInfo; + + /** + *
+	 * 用户标识
+	 * openid
+	 * 是
+	 * String(128)
+	 * wxd930ea5d5a258f4f
+	 * 用户在商户appid下的唯一标识
+	 * 
+ */ + @XStreamAlias("openid") + private String openid; + + /** + *
+	 * 是否关注公众账号
+	 * is_subscribe
+	 * 否
+	 * String(1)
+	 * Y
+	 * 用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
+	 * 
+ */ + @XStreamAlias("is_subscribe") + private String isSubscribe; + + + /** + *
+	 * 交易类型
+	 * trade_type
+	 * 是
+	 * String(16)
+	 * JSAPI	JSAPI、NATIVE、APP
+	 * 
+ */ + @XStreamAlias("trade_type") + private String tradeType; + + + /** + *
+	 * 付款银行
+	 * bank_type
+	 * 是
+	 * String(16)
+	 * CMC
+	 * 银行类型,采用字符串类型的银行标识,银行类型见银行列表
+	 * 
+ */ + @XStreamAlias("bank_type") + private String bankType; + + + /** + *
+	 * 订单金额
+	 * total_fee
+	 * 是
+	 * Int
+	 * 100
+	 * 订单总金额,单位为分
+	 * 
+ */ + @XStreamAlias("total_fee") + private Integer totalFee; + /** + *
+	 * 应结订单金额
+	 * settlement_total_fee
+	 * 否
+	 * Int
+	 * 100
+	 * 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
+	 * 
+ */ + @XStreamAlias("settlement_total_fee") + private Integer settlementTotalFee; + /** + *
+	 * 货币种类
+	 * fee_type
+	 * 否
+	 * String(8)
+	 * CNY
+	 * 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+	 * 
+ */ + @XStreamAlias("fee_type") + private String feeType; + /** + *
+	 * 现金支付金额
+	 * cash_fee
+	 * 是
+	 * Int
+	 * 100
+	 * 现金支付金额订单现金支付金额,详见支付金额
+	 * 
+ */ + @XStreamAlias("cash_fee") + private Integer cashFee; + /** + *
+	 * 现金支付货币类型
+	 * cash_fee_type
+	 * 否
+	 * String(16)
+	 * CNY
+	 * 货币类型,符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+	 * 
+ */ + @XStreamAlias("cash_fee_type") + private String cashFeeType; + /** + *
+	 * 总代金券金额
+	 * coupon_fee
+	 * 否
+	 * Int
+	 * 10
+	 * 代金券金额<=订单金额,订单金额-代金券金额=现金支付金额,详见支付金额
+	 * 
+ */ + @XStreamAlias("coupon_fee") + private Integer couponFee; + + /** + *
+   * 代金券使用数量
+   * coupon_count
+   * 否
+   * Int
+   * 1
+   * 代金券使用数量
+   * 
+ */ + @XStreamAlias("coupon_count") + private Integer couponCount; + + private List couponList; + + /** + *
+	 * 微信支付订单号
+	 * transaction_id
+	 * 是
+	 * String(32)
+	 * 1217752501201407033233368018
+	 * 微信支付订单号
+	 * 
+ */ + @XStreamAlias("transaction_id") + private String transactionId; + + /** + *
+	 * 商户订单号
+	 * out_trade_no
+	 * 是
+	 * String(32)
+	 * 1212321211201407033568112322
+	 * 商户系统的订单号,与请求一致。
+	 * 
+ */ + @XStreamAlias("out_trade_no") + private String outTradeNo; + /** + *
+	 * 商家数据包
+	 * attach
+	 * 否
+	 * String(128)
+	 * 123456
+	 * 商家数据包,原样返回
+	 * 
+ */ + @XStreamAlias("attach") + private String attach; + /** + *
+	 * 支付完成时间
+	 * time_end
+	 * 是
+	 * String(14)
+	 * 20141030133525
+	 * 支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
+	 * 
+ */ + @XStreamAlias("time_end") + private String timeEnd; + + public Integer getCouponCount() { + return couponCount; + } + + public void setCouponCount(Integer couponCount) { + this.couponCount = couponCount; + } + + public List getCouponList() { + return couponList; + } + + public void setCouponList(List couponList) { + this.couponList = couponList; + } + + public String getDeviceInfo() { + return deviceInfo; + } + + public void setDeviceInfo(String deviceInfo) { + this.deviceInfo = deviceInfo; + } + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + public String getIsSubscribe() { + return isSubscribe; + } + + public void setIsSubscribe(String isSubscribe) { + this.isSubscribe = isSubscribe; + } + + public String getTradeType() { + return tradeType; + } + + public void setTradeType(String tradeType) { + this.tradeType = tradeType; + } + + public String getBankType() { + return bankType; + } + + public void setBankType(String bankType) { + this.bankType = bankType; + } + + public Integer getTotalFee() { + return totalFee; + } + + public void setTotalFee(Integer totalFee) { + this.totalFee = totalFee; + } + + public Integer getSettlementTotalFee() { + return settlementTotalFee; + } + + public void setSettlementTotalFee(Integer settlementTotalFee) { + this.settlementTotalFee = settlementTotalFee; + } + + public String getFeeType() { + return feeType; + } + + public void setFeeType(String feeType) { + this.feeType = feeType; + } + + public Integer getCashFee() { + return cashFee; + } + + public void setCashFee(Integer cashFee) { + this.cashFee = cashFee; + } + + public String getCashFeeType() { + return cashFeeType; + } + + public void setCashFeeType(String cashFeeType) { + this.cashFeeType = cashFeeType; + } + + public Integer getCouponFee() { + return couponFee; + } + + public void setCouponFee(Integer couponFee) { + this.couponFee = couponFee; + } + + public String getTransactionId() { + return transactionId; + } + + public void setTransactionId(String transactionId) { + this.transactionId = transactionId; + } + + public String getOutTradeNo() { + return outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getAttach() { + return attach; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public String getTimeEnd() { + return timeEnd; + } + + public void setTimeEnd(String timeEnd) { + this.timeEnd = timeEnd; + } + + @Override + public Map toMap(){ + Map resultMap = BeanUtils.xmlBean2Map(this); + if(this.getCouponCount() != null && this.getCouponCount() > 0){ + for (int i = 0; i < this.getCouponCount(); i++) { + WxPayOrderNotifyCoupon coupon = couponList.get(i); + resultMap.putAll(coupon.toMap(i)); + } + } + return resultMap; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE); + } +} From 18f945b98289771f1cbb03db5c0b78d4c44f2548 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 26 Dec 2016 17:59:03 +0800 Subject: [PATCH 11/76] Update README.md --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3e34c597..e9f489de 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK ### 注意: 1. ***本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。*** 1. ***自2.0.0版本以来,公众号的接口调整比较大,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。*** -1. 本SDK要求的最低JDK版本是7,为满足少量还在使用JDK6的用户的需求,特意抽出独立的代码分支项目,请参考 https://github.com/binarywang/weixin-java-tools-for-jdk6 ,其他更早的JDK版本则需要自己改造实现; 1. 最新更新:2016-11-30 发布2.4.0正式版! =========== @@ -21,6 +20,7 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK 1. 详细开发文档请看 [Wiki](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。 1. 微信公众号官方文档入口地址:http://mp.weixin.qq.com/wiki (注意,从网上搜到的文档有的虽然地址前面跟这个一样,但明显左侧菜单不一致,是旧的文档,注意不要看错文档)。 1. 各个模块的Javadoc可以在线查看:[weixin-java-mp](https://binarywang.github.io/weixin-java-mp-javadoc/)、[weixin-java-common](https://binarywang.github.io/weixin-java-common-javadoc/)、[weixin-java-cp](https://binarywang.github.io/weixin-java-cp-javadoc/) +1. 本SDK要求的最低JDK版本是7,为满足少量还在使用JDK6的用户的需求,特意抽出独立的代码分支项目,请参考 https://github.com/binarywang/weixin-java-tools-for-jdk6 ,其他更早的JDK版本则需要自己改造实现。 =========== @@ -74,16 +74,15 @@ compile 'com.github.binarywang:weixin-java-cp:2.4.0' =========== ## 可参考的Demo项目 #### 目前都是公众号的,风格不同,欢迎提供更多的demo供新手参考: -1. https://github.com/wechat-group/weixin-mp-demo -1. https://github.com/wechat-group/weixin-mp-multi-demo (支持多公众号) +1. https://github.com/wechat-group/weixin-java-mp-demo +1. https://github.com/wechat-group/weixin-java-mp-multi-demo (支持多公众号) 1. https://github.com/wechat-group/weixin-java-tools-springmvc -1. https://github.com/wechat-group/weixin-mp-demo-springboot +1. https://github.com/wechat-group/weixin-java-mp-demo-springboot =========== ## 关于代码贡献 -1. 非常欢迎和感谢对本项目发起Pull Request的同学,本项目代码风格为使用2个空格代表一个Tab,因此在提交代码时请注意一下,否则很容易在IDE格式化代码后与原代码产生大量diff,这样会给其他人阅读代码带来极大的困扰。 -1. 为了便于设置,本项目引入editorconfig插件,请使用eclipse的同学在贡献代码前安装相关插件,IntelliJ IDEA则自带支持,无需额外安装插件。 +1. 非常欢迎和感谢对本项目发起Pull Request的同学,本项目代码风格为使用2个空格代表一个Tab,因此在提交代码时请注意一下,否则很容易在IDE格式化代码后与原代码产生大量diff,这样会给其他人阅读代码带来极大的困扰。为了便于设置,本项目引入editorconfig插件,请使用eclipse的同学在贡献代码前安装相关插件,IntelliJ IDEA新版本自带支持,如果没有可自行安装插件。 1. 本项目可以采用两种方式接受代码贡献: * 第一种就是基于[Git Flow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)开发流程,因此在发起Pull Request的时候请选择develop分支,详细步骤参考后文。 * 另外一种贡献代码的方式就是加入SDK Developers开发组,前提是对自己的代码足够自信就可以申请加入,加入之后可以随时直接提交代码,但要注意对所做的修改或新增的代码进行单元测试,保证提交代码没有明显问题,具体加入方式,请咨询QQ群管理员[![点击这里给我发消息](http://wpa.qq.com/pa?p=2:1211415707:51)](http://wpa.qq.com/msgrd?v=3&uin=1211415707&site=qq&menu=yes)。 From cb6712065dca1b8817584a5f797732bd04acf14f Mon Sep 17 00:00:00 2001 From: Zhao Jingchen Date: Mon, 26 Dec 2016 19:27:59 +0800 Subject: [PATCH 12/76] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=8E=88=E6=9D=83=E6=8E=A5=E5=8F=A3=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E6=AE=B5=E7=BC=BA=E5=A4=B1=20=E5=8F=82?= =?UTF-8?q?=E8=A7=81=20http://iot.weixin.qq.com/wiki/new/index.html=3Fpage?= =?UTF-8?q?=3D3-4-5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/bean/device/WxDeviceAuthorize.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java index a37a8a42..0318754e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/WxDeviceAuthorize.java @@ -14,6 +14,8 @@ public class WxDeviceAuthorize extends AbstractDeviceBean { private String deviceNum; @SerializedName("op_type") private String opType; + @SerializedName("product_id") + private String productId; @SerializedName("device_list") private List deviceList = new LinkedList<>(); @@ -33,6 +35,14 @@ public class WxDeviceAuthorize extends AbstractDeviceBean { this.opType = opType; } + public String getProductId() { + return productId; + } + + public void setProductId(String productId) { + this.productId = productId; + } + public List getDeviceList() { return deviceList; } From e7624926a436ba91fafbfc2c5927fdf91acd74e2 Mon Sep 17 00:00:00 2001 From: gaigeshen Date: Wed, 28 Dec 2016 15:50:08 +0800 Subject: [PATCH 13/76] =?UTF-8?q?=E7=BC=BA=E5=B0=91XStream=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E5=AF=BC=E8=87=B4=E8=BD=AC=E5=8C=96Xml=E5=88=B0?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java | 1 + 1 file changed, 1 insertion(+) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java index faf2df67..8a2e37fa 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java @@ -15,6 +15,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; * @author binarywang(Binary Wang) *
*/ +@XStreamAlias("xml") public class WxPayRedpackQueryResult extends WxPayBaseResult { /** From 013da38f00757ff901f0d7214ae1f00c93b7b2a6 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 29 Dec 2016 19:00:32 +0800 Subject: [PATCH 14/76] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=AD=E5=A2=9E=E5=8A=A0=E8=AF=81=E4=B9=A6=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=9A=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/ApiTestModule.java | 5 ++-- .../src/test/resources/test-config.sample.xml | 27 ++++++++++--------- 2 files changed, 17 insertions(+), 15 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 2b749b9f..13491d20 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 @@ -15,10 +15,11 @@ public class ApiTestModule implements Module { @Override public void configure(Binder binder) { try (InputStream is1 = ClassLoader - .getSystemResourceAsStream("test-config.xml")) { + .getSystemResourceAsStream("test-config.xml")) { WxXmlMpInMemoryConfigStorage config = this - .fromXml(WxXmlMpInMemoryConfigStorage.class, is1); + .fromXml(WxXmlMpInMemoryConfigStorage.class, is1); config.setAccessTokenLock(new ReentrantLock()); + config.setSslContextFilePath(config.getKeyPath()); WxMpService wxService = new WxMpServiceImpl(); wxService.setWxMpConfigStorage(config); 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 2bbc8d8e..3df1de9d 100644 --- a/weixin-java-mp/src/test/resources/test-config.sample.xml +++ b/weixin-java-mp/src/test/resources/test-config.sample.xml @@ -1,15 +1,16 @@ - 公众号appID - 公众号appsecret - 公众号Token - 公众号EncodingAESKey - 可以不填写 - 可以不填写 - 某个加你公众号的用户的openId - 微信商户平台ID - 商户平台设置的API密钥 - 模版消息的模版ID - 网页授权获取用户信息回调地址 - 网页应用授权登陆回调地址 - 完整客服账号,格式为:账号前缀@公众号微信号 + 公众号appID + 公众号appsecret + 公众号Token + 公众号EncodingAESKey + 可以不填写 + 可以不填写 + 某个加你公众号的用户的openId + 微信商户平台ID + 商户平台设置的API密钥 + 商户平台的证书文件地址 + 模版消息的模版ID + 网页授权获取用户信息回调地址 + 网页应用授权登陆回调地址 + 完整客服账号,格式为:账号前缀@公众号微信号 From a638189ec823321049b83e7c9be8501fbb9c5d87 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 29 Dec 2016 19:02:20 +0800 Subject: [PATCH 15/76] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=AD=E5=A2=9E=E5=8A=A0=E8=AF=81=E4=B9=A6=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=9A=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxXmlMpInMemoryConfigStorage.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java index 75494efe..1ab04cf1 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java @@ -14,6 +14,16 @@ public class WxXmlMpInMemoryConfigStorage private String qrconnectRedirectUrl; private String templateId; + public String getKeyPath() { + return keyPath; + } + + public void setKeyPath(String keyPath) { + this.keyPath = keyPath; + } + + private String keyPath; + public String getOpenid() { return this.openid; } From 22723f9f2bc7f51d2950719e6cc4e177d00ecbcb Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 29 Dec 2016 19:05:21 +0800 Subject: [PATCH 16/76] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=80=80=E6=AC=BE=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=B9=B6=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E9=83=A8=E5=88=86=E6=94=AF=E4=BB=98=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0=EF=BC=8C=E7=AE=80=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weixin-java-mp/pom.xml | 140 +++++++++--------- .../mp/api/WxMpInMemoryConfigStorage.java | 21 ++- .../mp/api/impl/WxMpPayServiceImpl.java | 119 +++++---------- .../mp/bean/pay/request/WxPayBaseRequest.java | 30 ++-- .../bean/pay/request/WxPayRefundRequest.java | 4 +- .../mp/bean/pay/result/WxPayBaseResult.java | 107 ++++++++++--- .../pay/result/WxPayOrderNotifyResult.java | 17 ++- .../pay/result/WxPayRefundQueryResult.java | 71 +++++++-- .../mp/api/impl/WxMpPayServiceImplTest.java | 3 - .../result/WxPayRefundQueryResultTest.java | 49 ++++++ 10 files changed, 351 insertions(+), 210 deletions(-) create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 9db06d7a..abde0215 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -1,73 +1,79 @@ - 4.0.0 - - com.github.binarywang - weixin-java-parent - 2.4.6.BETA - - weixin-java-mp - WeiXin Java Tools - MP - 微信公众号Java SDK + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"> + 4.0.0 + + com.github.binarywang + weixin-java-parent + 2.4.6.BETA + + weixin-java-mp + WeiXin Java Tools - MP + 微信公众号Java SDK - - - com.github.binarywang - weixin-java-common - ${project.version} - - - junit - junit - test - - - org.testng - testng - test - - - org.mockito - mockito-all - test - - - com.google.inject - guice - test - - - org.eclipse.jetty - jetty-server - test - - - org.eclipse.jetty - jetty-servlet - test - - - joda-time - joda-time - 2.9.4 - test - - + + + com.github.binarywang + weixin-java-common + ${project.version} + + + junit + junit + test + + + org.testng + testng + test + + + org.mockito + mockito-all + test + + + com.google.inject + guice + test + + + org.eclipse.jetty + jetty-server + test + + + org.eclipse.jetty + jetty-servlet + test + + + joda-time + joda-time + 2.9.4 + test + + + io.rest-assured + xml-path + 3.0.1 + - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/resources/testng.xml - - - - - + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/resources/testng.xml + + + + + diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java index 5172a5d7..29fbed63 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java @@ -310,20 +310,25 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { } @Override - public void setSslContextFilePath(String filePath) throws Exception { + public void setSslContextFilePath(String filePath) { if (null == partnerId) { - throw new Exception("请先将partnerId进行赋值"); + throw new IllegalArgumentException("请设置partnerId的值"); } File file = new File(filePath); if (!file.exists()) { - throw new RuntimeException(file.getPath() + ":文件不存在!在设置SSLContext的时候"); + throw new RuntimeException("证书文件:【" + file.getPath() + "】不存在!"); + } + + try { + FileInputStream inputStream = new FileInputStream(file); + KeyStore keystore = KeyStore.getInstance("PKCS12"); + char[] partnerId2charArray = partnerId.toCharArray(); + keystore.load(inputStream, partnerId2charArray); + this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build(); + } catch (Exception e) { + throw new RuntimeException("证书文件有问题,请核实!", e); } - FileInputStream inputStream = new FileInputStream(file); - KeyStore keystore = KeyStore.getInstance("PKCS12"); - char[] partnerId2charArray = partnerId.toCharArray(); - keystore.load(inputStream, partnerId2charArray); - this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build(); } @Override diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java index 8ad6ed35..6ab639f1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java @@ -1,14 +1,11 @@ package me.chanjar.weixin.mp.api.impl; -import com.thoughtworks.xstream.XStream; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.BeanUtils; -import me.chanjar.weixin.common.util.xml.XStreamInitializer; import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.mp.api.WxMpPayService; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyResultConverter; import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; import org.apache.commons.codec.digest.DigestUtils; @@ -54,20 +51,16 @@ public class WxMpPayServiceImpl implements WxMpPayService { @Override public WxPayRefundResult refund(WxPayRefundRequest request) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayRefundRequest.class); - xstream.processAnnotations(WxPayRefundResult.class); - - initRequest(request); + this.initRequest(request); if (StringUtils.isBlank(request.getOpUserId())) { - request.setOpUserId(getConfig().getPartnerId()); + request.setOpUserId(this.getConfig().getPartnerId()); } - checkParameters(request); + this.checkParameters(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/secapi/pay/refund"; - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxPayRefundResult result = (WxPayRefundResult) xstream.fromXML(responseContent); + String responseContent = this.executeWithKey(url, request.toXML()); + WxPayRefundResult result = WxPayRefundResult.fromXML(responseContent, WxPayRefundResult.class); this.checkResult(result); return result; } @@ -79,12 +72,8 @@ public class WxMpPayServiceImpl implements WxMpPayService { throw new IllegalArgumentException("transaction_id , out_trade_no,out_refund_no, refund_id 必须四选一"); } - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayRefundQueryRequest.class); - xstream.processAnnotations(WxPayRefundQueryResult.class); - WxPayRefundQueryRequest request = new WxPayRefundQueryRequest(); - initRequest(request); + this.initRequest(request); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); request.setTransactionId(StringUtils.trimToNull(transactionId)); request.setOutRefundNo(StringUtils.trimToNull(outRefundNo)); @@ -92,8 +81,8 @@ public class WxMpPayServiceImpl implements WxMpPayService { request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/refundquery"; - String responseContent = this.executeRequest(url, xstream.toXML(request)); - WxPayRefundQueryResult result = (WxPayRefundQueryResult) xstream.fromXML(responseContent); + String responseContent = this.executeRequest(url, request.toXML()); + WxPayRefundQueryResult result = WxPayRefundQueryResult.fromXML(responseContent, WxPayRefundQueryResult.class); result.composeRefundRecords(responseContent); this.checkResult(result); return result; @@ -102,8 +91,9 @@ public class WxMpPayServiceImpl implements WxMpPayService { private void checkResult(WxPayBaseResult result) throws WxErrorException { //校验返回结果签名 - if (!checkSign(result.toMap())) { - log.debug("校验结果签名失败,参数:{}", result.toMap()); + Map map = result.toMap(); + if (!this.checkSign(map)) { + log.debug("校验结果签名失败,参数:{}", map); throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("参数格式校验错误!").build()); } @@ -115,7 +105,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { + result.getReturnMsg() + ", 结果代码: " + result.getResultCode() + ", 错误代码: " + result.getErrCode() + ", 错误详情: " + result.getErrCodeDes()) .build(); - log.error("结果业务代码异常,参数:{},详细:{}", result.toMap(), error); + log.error("结果业务代码异常,参数:{},详细:{}", map, error); throw new WxErrorException(error); } } @@ -138,10 +128,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { public WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErrorException { try { log.trace("微信支付回调参数详细:{}", xmlData); - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayOrderNotifyResult.class); - xstream.registerConverter(new WxPayOrderNotifyResultConverter(xstream.getMapper(), xstream.getReflectionProvider())); - WxPayOrderNotifyResult result = (WxPayOrderNotifyResult) xstream.fromXML(xmlData); + WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData); log.debug("微信支付回调结果对象:{}", result); this.checkResult(result); return result; @@ -157,11 +144,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { @Override public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPaySendRedpackRequest.class); - xstream.processAnnotations(WxPaySendRedpackResult.class); - - initRequest(request); + this.initRequest(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/sendredpack"; @@ -169,18 +152,14 @@ public class WxMpPayServiceImpl implements WxMpPayService { //裂变红包 url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack"; } - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream.fromXML(responseContent); + String responseContent = this.executeWithKey(url, request.toXML()); + WxPaySendRedpackResult result = WxPaySendRedpackResult.fromXML(responseContent, WxPaySendRedpackResult.class); this.checkResult(result); return result; } @Override public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayRedpackQueryRequest.class); - xstream.processAnnotations(WxPayRedpackQueryResult.class); - WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest(); request.setMchBillNo(mchBillNo); request.setBillType("MCHT"); @@ -188,8 +167,8 @@ public class WxMpPayServiceImpl implements WxMpPayService { request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo"; - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxPayRedpackQueryResult result = (WxPayRedpackQueryResult) xstream.fromXML(responseContent); + String responseContent = this.executeWithKey(url, request.toXML()); + WxPayRedpackQueryResult result = WxPayRedpackQueryResult.fromXML(responseContent, WxPayRedpackQueryResult.class); this.checkResult(result); return result; } @@ -201,10 +180,6 @@ public class WxMpPayServiceImpl implements WxMpPayService { throw new IllegalArgumentException("transaction_id 和 out_trade_no 不能同时存在或同时为空,必须二选一"); } - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayOrderQueryRequest.class); - xstream.processAnnotations(WxPayOrderQueryResult.class); - WxPayOrderQueryRequest request = new WxPayOrderQueryRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); request.setTransactionId(StringUtils.trimToNull(transactionId)); @@ -212,8 +187,8 @@ public class WxMpPayServiceImpl implements WxMpPayService { request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/orderquery"; - String responseContent = this.executeRequest(url, xstream.toXML(request)); - WxPayOrderQueryResult result = (WxPayOrderQueryResult) xstream.fromXML(responseContent); + String responseContent = this.executeRequest(url, request.toXML()); + WxPayOrderQueryResult result = WxPayOrderQueryResult.fromXML(responseContent, WxPayOrderQueryResult.class); result.composeCoupons(responseContent); this.checkResult(result); return result; @@ -225,18 +200,14 @@ public class WxMpPayServiceImpl implements WxMpPayService { throw new IllegalArgumentException("out_trade_no 不能为空"); } - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayOrderCloseRequest.class); - xstream.processAnnotations(WxPayOrderCloseResult.class); - WxPayOrderCloseRequest request = new WxPayOrderCloseRequest(); request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); initRequest(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/closeorder"; - String responseContent = this.executeRequest(url, xstream.toXML(request)); - WxPayOrderCloseResult result = (WxPayOrderCloseResult) xstream.fromXML(responseContent); + String responseContent = this.executeRequest(url, request.toXML()); + WxPayOrderCloseResult result = WxPayOrderCloseResult.fromXML(responseContent, WxPayOrderCloseResult.class); this.checkResult(result); return result; @@ -246,11 +217,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxPayUnifiedOrderRequest.class); - xstream.processAnnotations(WxPayUnifiedOrderResult.class); - - initRequest(request); + this.initRequest(request); if (StringUtils.isBlank(request.getNotifyURL())) { request.setNotifyURL(getConfig().getNotifyURL()); } @@ -261,12 +228,12 @@ public class WxMpPayServiceImpl implements WxMpPayService { request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/pay/unifiedorder"; - String xmlParam = xstream.toXML(request); + String xmlParam = request.toXML(); log.debug("微信统一下单接口,URL:{},参数:{}", url, xmlParam); String responseContent = this.executeRequest(url, xmlParam); log.debug("微信统一下单接口,URL:{},结果:{}", url, responseContent); - WxPayUnifiedOrderResult result = (WxPayUnifiedOrderResult) xstream.fromXML(responseContent); + WxPayUnifiedOrderResult result = WxPayUnifiedOrderResult.fromXML(responseContent, WxPayUnifiedOrderResult.class); this.checkResult(result); return result; } @@ -324,35 +291,27 @@ public class WxMpPayServiceImpl implements WxMpPayService { @Override public WxEntPayResult entPay(WxEntPayRequest request) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxEntPayRequest.class); - xstream.processAnnotations(WxEntPayResult.class); - - initRequest(request); + this.initRequest(request); BeanUtils.checkRequiredFields(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/promotion/transfers"; - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxEntPayResult result = (WxEntPayResult) xstream.fromXML(responseContent); + String responseContent = this.executeWithKey(url, request.toXML()); + WxEntPayResult result = WxEntPayResult.fromXML(responseContent, WxEntPayResult.class); this.checkResult(result); return result; } @Override public WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorException { - XStream xstream = XStreamInitializer.getInstance(); - xstream.processAnnotations(WxEntPayQueryRequest.class); - xstream.processAnnotations(WxEntPayQueryResult.class); - WxEntPayQueryRequest request = new WxEntPayQueryRequest(); - initRequest(request); + this.initRequest(request); request.setSign(this.createSign(request)); String url = PAY_BASE_URL + "/mmpaymkttransfers/gettransferinfo"; - String responseContent = this.executeRequestWithKeyFile(url, xstream.toXML(request)); - WxEntPayQueryResult result = (WxEntPayQueryResult) xstream.fromXML(responseContent); + String responseContent = this.executeWithKey(url, request.toXML()); + WxEntPayQueryResult result = WxEntPayQueryResult.fromXML(responseContent, WxEntPayQueryResult.class); this.checkResult(result); return result; } @@ -379,11 +338,11 @@ public class WxMpPayServiceImpl implements WxMpPayService { } } - private String executeRequestWithKeyFile(String url, String requestStr) throws WxErrorException { + private String executeWithKey(String url, String requestStr) throws WxErrorException { try { SSLContext sslContext = getConfig().getSslContext(); if (null == sslContext) { - throw new Exception("请将配置类(即WxMpConfigStorage的实现类)中的SSLContext初始化"); + throw new IllegalArgumentException("请先初始化配置类(即WxMpConfigStorage的实现类)中的SSLContext!"); } SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[]{"TLSv1"}, null, @@ -412,17 +371,17 @@ public class WxMpPayServiceImpl implements WxMpPayService { @Override public String createSign(Object xmlBean) { - return createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); + return this.createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); } @Override public String createSign(Object xmlBean, String signKey) { - return createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); + return this.createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); } @Override public String createSign(Map params) { - return createSign(params, getConfig().getPartnerKey()); + return this.createSign(params, this.getConfig().getPartnerKey()); } @Override @@ -443,17 +402,17 @@ public class WxMpPayServiceImpl implements WxMpPayService { @Override public boolean checkSign(Object xmlBean) { - return checkSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); + return this.checkSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); } @Override public boolean checkSign(Object xmlBean, String signKey) { - return checkSign(BeanUtils.xmlBean2Map(xmlBean), signKey); + return this.checkSign(BeanUtils.xmlBean2Map(xmlBean), signKey); } @Override public boolean checkSign(Map params) { - return checkSign(params, getConfig().getPartnerKey()); + return this.checkSign(params, getConfig().getPartnerKey()); } @Override diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java index 3bfe556f..c13f1b8f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java @@ -1,7 +1,9 @@ package me.chanjar.weixin.mp.bean.pay.request; +import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.util.ToStringUtils; +import me.chanjar.weixin.common.util.xml.XStreamInitializer; import java.math.BigDecimal; @@ -17,6 +19,7 @@ import java.math.BigDecimal; *
  • 示例值 *
  • 描述 *
  • + * * @author binarywang(Binary Wang) */ public abstract class WxPayBaseRequest { @@ -69,12 +72,22 @@ public abstract class WxPayBaseRequest { @XStreamAlias("sign") protected String sign; + /** + * 将单位为元转换为单位为分 + * + * @param yuan 将要转换的元的数值字符串 + */ + public static Integer yuanToFee(String yuan) { + return new BigDecimal(yuan).setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue(); + } + public String getAppid() { return this.appid; } /** * 如果配置中已经设置,可以不设置值 + * * @param appid 微信公众号appid */ public void setAppid(String appid) { @@ -87,6 +100,7 @@ public abstract class WxPayBaseRequest { /** * 如果配置中已经设置,可以不设置值 + * * @param mchId 微信商户号 */ public void setMchId(String mchId) { @@ -99,6 +113,7 @@ public abstract class WxPayBaseRequest { /** * 默认采用时间戳为随机字符串,可以不设置 + * * @param nonceStr 随机字符串 */ public void setNonceStr(String nonceStr) { @@ -113,17 +128,14 @@ public abstract class WxPayBaseRequest { this.sign = sign; } - /** - * 将单位为元转换为单位为分 - * - * @param yuan 将要转换的元的数值字符串 - */ - public static Integer yuanToFee(String yuan) { - return new BigDecimal(yuan).setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue(); - } - @Override public String toString() { return ToStringUtils.toSimpleString(this); } + + public String toXML() { + XStream xstream = XStreamInitializer.getInstance(); + xstream.processAnnotations(this.getClass()); + return xstream.toXML(this); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java index 66ba5d34..22bc6ae2 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java @@ -1,7 +1,6 @@ package me.chanjar.weixin.mp.bean.pay.request; import com.thoughtworks.xstream.annotations.XStreamAlias; - import me.chanjar.weixin.common.annotation.Required; /** @@ -144,8 +143,6 @@ public class WxPayRefundRequest extends WxPayBaseRequest { @XStreamAlias("refund_account") private String refundAccount; - - public String getDeviceInfo() { return this.deviceInfo; } @@ -217,4 +214,5 @@ public class WxPayRefundRequest extends WxPayBaseRequest { public void setRefundAccount(String refundAccount) { this.refundAccount = refundAccount; } + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index cafd8a56..b06f3cca 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -1,10 +1,19 @@ package me.chanjar.weixin.mp.bean.pay.result; +import com.google.common.collect.Maps; +import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; -import me.chanjar.weixin.common.util.BeanUtils; +import io.restassured.internal.path.xml.NodeChildrenImpl; +import io.restassured.path.xml.XmlPath; +import io.restassured.path.xml.element.Node; +import io.restassured.path.xml.element.NodeChildren; import me.chanjar.weixin.common.util.ToStringUtils; +import me.chanjar.weixin.common.util.xml.XStreamInitializer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.math.BigDecimal; +import java.util.Iterator; import java.util.Map; /** @@ -15,65 +24,90 @@ import java.util.Map; *
    */ public abstract class WxPayBaseResult { - @Override - public String toString() { - return ToStringUtils.toSimpleString(this); - } - /** * 返回状态码 */ @XStreamAlias("return_code") protected String returnCode; - /** * 返回信息 */ @XStreamAlias("return_msg") protected String returnMsg; - + private String xmlString; /** * 业务结果 */ @XStreamAlias("result_code") private String resultCode; - /** * 错误代码 */ @XStreamAlias("err_code") private String errCode; - /** * 错误代码描述 */ @XStreamAlias("err_code_des") private String errCodeDes; - /** * 公众账号ID */ @XStreamAlias("appid") private String appid; - /** * 商户号 */ @XStreamAlias("mch_id") private String mchId; - /** * 随机字符串 */ @XStreamAlias("nonce_str") private String nonceStr; - /** * 签名 */ @XStreamAlias("sign") private String sign; + /** + * 将单位分转换成单位圆 + * + * @param fee 将要被转换为元的分的数值 + */ + public static String feeToYuan(Integer fee) { + return new BigDecimal(Double.valueOf(fee) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); + } + + /** + * 从xml字符串创建bean对象 + */ + public static T fromXML(String xmlString, Class clz) { + XStream xstream = XStreamInitializer.getInstance(); + xstream.processAnnotations(clz); + T result = (T) xstream.fromXML(xmlString); + result.setXmlString(xmlString); + return result; + } + + public String getXmlString() { + return this.xmlString; + } + + public void setXmlString(String xmlString) { + this.xmlString = xmlString; + } + + protected Logger getLogger() { + return LoggerFactory.getLogger(this.getClass()); + } + + @Override + public String toString() { + return ToStringUtils.toSimpleString(this); + } + public String getReturnCode() { return this.returnCode; } @@ -147,14 +181,43 @@ public abstract class WxPayBaseResult { } /** - * 将单位分转换成单位圆 - * @param fee 将要被转换为元的分的数值 + * 将bean通过保存的xml字符串转换成map */ - public static String feeToYuan(Integer fee) { - return new BigDecimal(Double.valueOf(fee) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); - } - - public Map toMap(){ - return BeanUtils.xmlBean2Map(this); + public Map toMap() { + Map result = Maps.newHashMap(); + XmlPath xmlPath = new XmlPath(this.xmlString); + NodeChildren nodeChildren = xmlPath.getNodeChildren("xml"); + Iterator iterator = nodeChildren.nodeIterator(); + while (iterator.hasNext()) { + Node node = iterator.next(); + result.put(node.name(), node.value()); + } + return result; + } + + private String getXmlValueIfExists(XmlPath xmlPath, String path) { + if (xmlPath.get(path) instanceof NodeChildrenImpl) { + if (((NodeChildrenImpl) xmlPath.get(path)).size() == 0) { + return null; + } + } + + return xmlPath.getString(path); + } + + protected T getXmlValueIfExists(XmlPath xmlPath, String path, Class clz) { + String value = this.getXmlValueIfExists(xmlPath, path); + if (value == null) { + return null; + } + + switch (clz.getSimpleName()) { + case "String": + return (T) value; + case "Integer": + return (T) Integer.valueOf(value); + } + + throw new UnsupportedOperationException("暂时不支持此种类型的数据"); } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java index a5770873..1cf783a8 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderNotifyResult.java @@ -1,10 +1,12 @@ package me.chanjar.weixin.mp.bean.pay.result; +import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.util.BeanUtils; +import me.chanjar.weixin.common.util.ToStringUtils; +import me.chanjar.weixin.common.util.xml.XStreamInitializer; import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyCoupon; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; +import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyResultConverter; import java.io.Serializable; import java.util.List; @@ -376,6 +378,15 @@ public class WxPayOrderNotifyResult extends WxPayBaseResult implements Serializ @Override public String toString() { - return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE); + return ToStringUtils.toSimpleString(this); } + + public static WxPayOrderNotifyResult fromXML(String xmlString) { + XStream xstream = XStreamInitializer.getInstance(); + xstream.processAnnotations(WxPayOrderNotifyResult.class); + xstream.registerConverter(new WxPayOrderNotifyResultConverter(xstream.getMapper(), xstream.getReflectionProvider())); + WxPayOrderNotifyResult result = (WxPayOrderNotifyResult) xstream.fromXML(xmlString); + result.setXmlString(xmlString); + return result; + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java index 43028846..146c35df 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java @@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.bean.pay.result; import com.google.common.collect.Lists; import com.thoughtworks.xstream.annotations.XStreamAlias; +import io.restassured.path.xml.XmlPath; import java.util.List; @@ -186,7 +187,38 @@ public class WxPayRefundQueryResult extends WxPayBaseResult { public void composeRefundRecords(String xmlString) { if (this.refundCount != null && this.refundCount > 0) { this.refundRecords = Lists.newArrayList(); - //TODO 暂时待实现 + XmlPath xmlPath = new XmlPath(xmlString); + + for (int i = 0; i < this.refundCount; i++) { + RefundRecord refundRecord = new RefundRecord(); + this.refundRecords.add(refundRecord); + + refundRecord.setOutRefundNo(this.getXmlValueIfExists(xmlPath, "xml.out_refund_no_" + i, String.class)); + refundRecord.setRefundId(this.getXmlValueIfExists(xmlPath, "xml.refund_id_" + i, String.class)); + refundRecord.setRefundChannel(this.getXmlValueIfExists(xmlPath, "xml.refund_channel_" + i, String.class)); + refundRecord.setRefundFee(this.getXmlValueIfExists(xmlPath, "xml.refund_fee_" + i, Integer.class)); + refundRecord.setSettlementRefundFee(this.getXmlValueIfExists(xmlPath, "xml.settlement_refund_fee_" + i, Integer.class)); + refundRecord.setCouponType(this.getXmlValueIfExists(xmlPath, "xml.coupon_type_" + i, String.class)); + refundRecord.setCouponRefundFee(this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_fee_" + i, Integer.class)); + refundRecord.setCouponRefundCount(this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_count_" + i, Integer.class)); + refundRecord.setRefundStatus(this.getXmlValueIfExists(xmlPath, "xml.refund_status_" + i, String.class)); + refundRecord.setRefundRecvAccout(this.getXmlValueIfExists(xmlPath, "xml.refund_recv_accout_" + i, String.class)); + + if (refundRecord.getCouponRefundCount() == null || refundRecord.getCouponRefundCount() == 0) { + continue; + } + + List coupons = Lists.newArrayList(); + for (int j = 0; j < refundRecord.getCouponRefundCount(); j++) { + coupons.add( + new RefundRecord.RefundCoupon( + this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_id_" + i + "_" + j, String.class), + this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_fee_" + i + "_" + j, Integer.class) + ) + ); + } + } + } } @@ -241,7 +273,7 @@ public class WxPayRefundQueryResult extends WxPayBaseResult { * */ @XStreamAlias("refund_fee") - private String refundFee; + private Integer refundFee; /** *
    @@ -254,7 +286,7 @@ public class WxPayRefundQueryResult extends WxPayBaseResult {
          * 
    */ @XStreamAlias("settlement_refund_fee") - private String settlementRefundFee; + private Integer settlementRefundFee; /** *
    @@ -293,7 +325,7 @@ public class WxPayRefundQueryResult extends WxPayBaseResult {
          * 
    */ @XStreamAlias("coupon_refund_fee") - private String couponRefundFee; + private Integer couponRefundFee; /** *
    @@ -306,7 +338,7 @@ public class WxPayRefundQueryResult extends WxPayBaseResult {
          * 
    */ @XStreamAlias("coupon_refund_count") - private String couponRefundCount; + private Integer couponRefundCount; private List refundCoupons; @@ -364,19 +396,19 @@ public class WxPayRefundQueryResult extends WxPayBaseResult { this.refundChannel = refundChannel; } - public String getRefundFee() { + public Integer getRefundFee() { return refundFee; } - public void setRefundFee(String refundFee) { + public void setRefundFee(Integer refundFee) { this.refundFee = refundFee; } - public String getSettlementRefundFee() { + public Integer getSettlementRefundFee() { return settlementRefundFee; } - public void setSettlementRefundFee(String settlementRefundFee) { + public void setSettlementRefundFee(Integer settlementRefundFee) { this.settlementRefundFee = settlementRefundFee; } @@ -396,19 +428,19 @@ public class WxPayRefundQueryResult extends WxPayBaseResult { this.couponType = couponType; } - public String getCouponRefundFee() { + public Integer getCouponRefundFee() { return couponRefundFee; } - public void setCouponRefundFee(String couponRefundFee) { + public void setCouponRefundFee(Integer couponRefundFee) { this.couponRefundFee = couponRefundFee; } - public String getCouponRefundCount() { + public Integer getCouponRefundCount() { return couponRefundCount; } - public void setCouponRefundCount(String couponRefundCount) { + public void setCouponRefundCount(Integer couponRefundCount) { this.couponRefundCount = couponRefundCount; } @@ -446,6 +478,8 @@ public class WxPayRefundQueryResult extends WxPayBaseResult { * 100 * 退款代金券批次ID ,$n为下标,$m为下标,从0开始编号 * + * + * @deprecated 貌似是被去掉了,但不知是何时! */ @XStreamAlias("coupon_refund_batch_id") private String couponRefundBatchId; @@ -474,9 +508,15 @@ public class WxPayRefundQueryResult extends WxPayBaseResult { * */ @XStreamAlias("coupon_refund_fee") - private String couponRefundFee; + private Integer couponRefundFee; - public RefundCoupon(String couponRefundBatchId, String couponRefundId, String couponRefundFee) { + public RefundCoupon(String couponRefundId, Integer couponRefundFee) { + this.couponRefundId = couponRefundId; + this.couponRefundFee = couponRefundFee; + } + + @Deprecated + public RefundCoupon(String couponRefundBatchId, String couponRefundId, Integer couponRefundFee) { this.couponRefundBatchId = couponRefundBatchId; this.couponRefundId = couponRefundId; this.couponRefundFee = couponRefundFee; @@ -484,5 +524,6 @@ public class WxPayRefundQueryResult extends WxPayBaseResult { } } + } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 31fc0c06..418b710b 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -13,8 +13,6 @@ import me.chanjar.weixin.mp.bean.pay.result.*; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import java.io.File; - /** * 测试支付相关接口 * Created by Binary Wang on 2016/7/28. @@ -90,7 +88,6 @@ public class WxMpPayServiceImplTest { */ @Test public void testQueryRedpack() throws Exception { - File keyFile = new File("E:\\dlt.p12"); WxPayRedpackQueryResult redpackResult = this.wxService.getPayService().queryRedpack("aaaa"); System.err.println(redpackResult); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java new file mode 100644 index 00000000..9427bd01 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java @@ -0,0 +1,49 @@ +package me.chanjar.weixin.mp.bean.pay.result; + + +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + *
    + * Created by Binary Wang on 2016-12-29.
    + * @author binarywang(Binary Wang)
    + * 
    + */ +public class WxPayRefundQueryResultTest { + @Test + public void composeRefundRecords() throws Exception { + /* + 该xml字符串来自于官方文档示例 + */ + String xmlString = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 1\n" + + " 1\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + WxPayRefundQueryResult result = new WxPayRefundQueryResult(); + result.setRefundCount(1); + result.composeRefundRecords(xmlString); + + Assert.assertNotNull(result.getRefundRecords()); + Assert.assertEquals(result.getRefundRecords().size(), 1); + Assert.assertEquals(result.getRefundRecords().get(0).getRefundId(), "2008450740201411110000174436"); + Assert.assertEquals(result.getRefundRecords().get(0).getRefundFee().intValue(), 1); + Assert.assertEquals(result.getRefundRecords().get(0).getOutRefundNo(), "1415701182"); + Assert.assertEquals(result.getRefundRecords().get(0).getRefundStatus(), "PROCESSING"); + + } + +} From 96d4597e0fb3f0c06d485a3b9536480854fdf025 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 29 Dec 2016 19:54:45 +0800 Subject: [PATCH 17/76] release 2.4.7.BETA --- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- weixin-java-osgi/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 24e46e39..a8f2f424 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.4.6.BETA + 2.4.7.BETA pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 5b55b6af..8f78458d 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.6.BETA + 2.4.7.BETA weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 3b8072c6..2adec10e 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.6.BETA + 2.4.7.BETA weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index abde0215..335fe3a3 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.6.BETA + 2.4.7.BETA weixin-java-mp WeiXin Java Tools - MP diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml index 8667d330..ee96e71f 100644 --- a/weixin-java-osgi/pom.xml +++ b/weixin-java-osgi/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.6.BETA + 2.4.7.BETA weixin-java-osgi From 0350182db137c540528fe2b8be430a854fe06599 Mon Sep 17 00:00:00 2001 From: cty Date: Wed, 7 Dec 2016 11:43:17 +0800 Subject: [PATCH 18/76] =?UTF-8?q?oauth2=E8=AE=A4=E8=AF=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=80=BC=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?openid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a2bd3659..8d0c47da 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 @@ -491,7 +491,7 @@ public class WxCpServiceImpl implements WxCpService { String responseText = get(url, null); JsonElement je = new JsonParser().parse(responseText); JsonObject jo = je.getAsJsonObject(); - return new String[]{GsonHelper.getString(jo, "UserId"), GsonHelper.getString(jo, "DeviceId")}; + return new String[]{GsonHelper.getString(jo, "UserId"), GsonHelper.getString(jo, "DeviceId"), GsonHelper.getString(jo, "OpenId")}; } @Override From a1a5d7ceada42ebe434f7ac4493cf24b252bb885 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 30 Dec 2016 23:18:47 +0800 Subject: [PATCH 19/76] Update README.md --- README.md | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/README.md b/README.md index e9f489de..d0d93026 100644 --- a/README.md +++ b/README.md @@ -78,35 +78,3 @@ compile 'com.github.binarywang:weixin-java-cp:2.4.0' 1. https://github.com/wechat-group/weixin-java-mp-multi-demo (支持多公众号) 1. https://github.com/wechat-group/weixin-java-tools-springmvc 1. https://github.com/wechat-group/weixin-java-mp-demo-springboot - - -=========== -## 关于代码贡献 -1. 非常欢迎和感谢对本项目发起Pull Request的同学,本项目代码风格为使用2个空格代表一个Tab,因此在提交代码时请注意一下,否则很容易在IDE格式化代码后与原代码产生大量diff,这样会给其他人阅读代码带来极大的困扰。为了便于设置,本项目引入editorconfig插件,请使用eclipse的同学在贡献代码前安装相关插件,IntelliJ IDEA新版本自带支持,如果没有可自行安装插件。 -1. 本项目可以采用两种方式接受代码贡献: - * 第一种就是基于[Git Flow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)开发流程,因此在发起Pull Request的时候请选择develop分支,详细步骤参考后文。 - * 另外一种贡献代码的方式就是加入SDK Developers开发组,前提是对自己的代码足够自信就可以申请加入,加入之后可以随时直接提交代码,但要注意对所做的修改或新增的代码进行单元测试,保证提交代码没有明显问题,具体加入方式,请咨询QQ群管理员[![点击这里给我发消息](http://wpa.qq.com/pa?p=2:1211415707:51)](http://wpa.qq.com/msgrd?v=3&uin=1211415707&site=qq&menu=yes)。 - -## PR方式贡献代码步骤 -* 在 GitHub 上 `fork` 到自己的仓库,如 `my_user/weixin-java-tools`,然后 `clone` 到本地,并设置用户信息。 -```bash - $ git clone git@github.com:my_user/weixin-java-tools.git - $ cd weixin-java-tools - $ git config user.name "yourname" - $ git config user.email "your email" -``` -* 修改代码后提交,并推送到自己的仓库。 -```bash -$ #do some change on the content -$ git commit -am "Fix issue #1: change something" -$ git push -``` -* 在 GitHub 网站上提交 Pull Request。 -* 定期使用项目仓库内容更新自己仓库内容。 -```bash -$ git remote add upstream https://github.com/wechat-group/weixin-java-tools -$ git fetch upstream -$ git checkout develop -$ git rebase upstream/develop -$ git push -f origin develop -``` From 937d03e4e527ded0bcf91e4ebbeff006a7cc260c Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 30 Dec 2016 23:24:36 +0800 Subject: [PATCH 20/76] Create CONTRIBUTION.md --- CONTRIBUTION.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 CONTRIBUTION.md diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md new file mode 100644 index 00000000..991f5b3e --- /dev/null +++ b/CONTRIBUTION.md @@ -0,0 +1,30 @@ +# 关于代码贡献 +1. 非常欢迎和感谢对本项目发起Pull Request的同学,本项目代码风格为使用2个空格代表一个Tab,因此在提交代码时请注意一下,否则很容易在IDE格式化代码后与原代码产生大量diff,这样会给其他人阅读代码带来极大的困扰。为了便于设置,本项目引入editorconfig插件,请使用eclipse的同学在贡献代码前安装相关插件,IntelliJ IDEA新版本自带支持,如果没有可自行安装插件。 +1. 本项目可以采用两种方式接受代码贡献: + * 第一种就是基于[Git Flow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)开发流程,因此在发起Pull Request的时候请选择develop分支,详细步骤参考后文。 + * 另外一种贡献代码的方式就是加入SDK Developers开发组,前提是对自己的代码足够自信就可以申请加入,加入之后可以随时直接提交代码,但要注意对所做的修改或新增的代码进行单元测试,保证提交代码没有明显问题,具体加入方式,请咨询QQ群管理员[![点击这里给我发消息](http://wpa.qq.com/pa?p=2:1211415707:51)](http://wpa.qq.com/msgrd?v=3&uin=1211415707&site=qq&menu=yes)。 + + +### PR方式贡献代码步骤 +* 在 GitHub 上 `fork` 到自己的仓库,如 `my_user/weixin-java-tools`,然后 `clone` 到本地,并设置用户信息。 +```bash + $ git clone git@github.com:my_user/weixin-java-tools.git + $ cd weixin-java-tools + $ git config user.name "yourname" + $ git config user.email "your email" +``` +* 修改代码后提交,并推送到自己的仓库。 +```bash +$ #do some change on the content +$ git commit -am "Fix issue #1: change something" +$ git push +``` +* 在 GitHub 网站上提交 Pull Request。 +* 定期使用项目仓库内容更新自己仓库内容。 +```bash +$ git remote add upstream https://github.com/wechat-group/weixin-java-tools +$ git fetch upstream +$ git checkout develop +$ git rebase upstream/develop +$ git push -f origin develop +``` From 06a2db97a9583bc0c1a9d405a577cb77bcec192c Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 30 Dec 2016 23:31:23 +0800 Subject: [PATCH 21/76] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d0d93026..ad2d23ca 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK 1. 微信公众号官方文档入口地址:http://mp.weixin.qq.com/wiki (注意,从网上搜到的文档有的虽然地址前面跟这个一样,但明显左侧菜单不一致,是旧的文档,注意不要看错文档)。 1. 各个模块的Javadoc可以在线查看:[weixin-java-mp](https://binarywang.github.io/weixin-java-mp-javadoc/)、[weixin-java-common](https://binarywang.github.io/weixin-java-common-javadoc/)、[weixin-java-cp](https://binarywang.github.io/weixin-java-cp-javadoc/) 1. 本SDK要求的最低JDK版本是7,为满足少量还在使用JDK6的用户的需求,特意抽出独立的代码分支项目,请参考 https://github.com/binarywang/weixin-java-tools-for-jdk6 ,其他更早的JDK版本则需要自己改造实现。 +1. 如果想贡献代码,请阅读[贡献代码指南](CONTRIBUTION.md)。 =========== From 0342514560b20fbd4acd399359cdea5ae2db3e9f Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 30 Dec 2016 23:39:55 +0800 Subject: [PATCH 22/76] Update README.md --- README.md | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index ad2d23ca..3500d7ee 100644 --- a/README.md +++ b/README.md @@ -3,34 +3,51 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.binarywang/weixin-java-parent/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.binarywang/weixin-java-parent) [![Build Status](https://travis-ci.org/Wechat-Group/weixin-java-tools.svg?branch=develop)](https://travis-ci.org/Wechat-Group/weixin-java-tools) -### 注意: -1. ***本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。*** -1. ***自2.0.0版本以来,公众号的接口调整比较大,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。*** +### 注意事项: +1. 声明: ***本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。*** 1. 最新更新:2016-11-30 发布2.4.0正式版! +1. 自2.0.0版本以来,公众号的接口调整比较大,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。 +1. 详细开发文档请看 [Wiki](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。 +1. 微信公众号官方文档入口地址:http://mp.weixin.qq.com/wiki (注意,从网上搜到的文档有的虽然地址前面跟这个一样,但明显左侧菜单不一致,是旧的文档,注意不要看错文档)。 +1. 各个模块的Javadoc可以在线查看:[weixin-java-mp](https://binarywang.github.io/weixin-java-mp-javadoc/)、[weixin-java-common](https://binarywang.github.io/weixin-java-common-javadoc/)、[weixin-java-cp](https://binarywang.github.io/weixin-java-cp-javadoc/) +1. 本SDK要求的最低JDK版本是7,为满足少量还在使用JDK6的用户的需求,特意抽出独立的代码分支项目,请参考 https://github.com/binarywang/weixin-java-tools-for-jdk6 ,其他更早的JDK版本则需要自己改造实现。 +1. 有新功能需求,发现BUG,或者由于微信官方接口调整导致的代码问题,可以直接在[Issues](https://github.com/Wechat-Group/weixin-java-tools/issues)页提出issue,便于讨论追踪问题; +1. 如果想贡献代码,请阅读[贡献代码指南](CONTRIBUTION.md)。 =========== -## 开发交流方式及注意事项: +## SDK使用交流方式说明: 1. QQ群:343954419(推荐点击按钮入群: [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=731dc3e7ea31ebe25376cc1a791445468612c63fd0e9e05399b088ec81fd9e15) 或 [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://jq.qq.com/?_wv=1027&k=40lRskK),如果无反应,可以自行搜索群号进行添加 ) 1. 由于群容量有限,即将爆满,故开启付费入群模式以保证只有真实交流需求的人进入,并为保证群的活跃度,将不定期清理长时间不活跃的同学; 1. 微信群: 因微信群已达到100人限制,故如有想加入微信群的,请入QQ群后联系管理员,提供微信号以便邀请加入; 1. 新手提问前,请先阅读此文章:http://t.cn/RV93MRB 1. 寻求帮助时需贴代码或大长串异常信息的,请利用http://paste.ubuntu.com -1. 有功能需求或由于微信官方接口调整导致的代码问题,可以直接提出issue,便于讨论追踪问题; -1. 详细开发文档请看 [Wiki](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。 -1. 微信公众号官方文档入口地址:http://mp.weixin.qq.com/wiki (注意,从网上搜到的文档有的虽然地址前面跟这个一样,但明显左侧菜单不一致,是旧的文档,注意不要看错文档)。 -1. 各个模块的Javadoc可以在线查看:[weixin-java-mp](https://binarywang.github.io/weixin-java-mp-javadoc/)、[weixin-java-common](https://binarywang.github.io/weixin-java-common-javadoc/)、[weixin-java-cp](https://binarywang.github.io/weixin-java-cp-javadoc/) -1. 本SDK要求的最低JDK版本是7,为满足少量还在使用JDK6的用户的需求,特意抽出独立的代码分支项目,请参考 https://github.com/binarywang/weixin-java-tools-for-jdk6 ,其他更早的JDK版本则需要自己改造实现。 -1. 如果想贡献代码,请阅读[贡献代码指南](CONTRIBUTION.md)。 =========== ## 版本说明 -1. 本项目定为每两个月发布一次正式版,版本号格式为X.X.0(如2.1.0,2.2.0等),月底发布新版本,遇到重大问题需修复会及时提交新版本,欢迎大家随时提交Pull Request; +1. 本项目定为大约每两个月发布一次正式版,版本号格式为X.X.0(如2.1.0,2.2.0等),遇到重大问题需修复会及时提交新版本,欢迎大家随时提交Pull Request; 1. BUG修复和新特性一般会先发布成小版本作为临时测试版本(如2.4.5.BETA,2.4.6.BETA等,即尾号不为0,并添加BETA字样,以区别于正式版); 1. 目前最新版本号为 [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.binarywang/weixin-java-parent/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.binarywang/weixin-java-parent) ,也可以通过访问链接 [【公众号】](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.binarywang%22%20AND%20a%3A%22weixin-java-mp%22) 、[【企业号】](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.binarywang%22%20AND%20a%3A%22weixin-java-cp%22) 分别查看所有最新的版本。 +=========== + +#### 本项目主要存放在github上,地址为 : +* https://github.com/wechat-group/weixin-java-tools +* ===========但同时会在其他几个网站同步更新,地址分别是: +* https://bitbucket.org/binarywang/weixin-java-tools +* http://git.oschina.net/binary/weixin-java-tools +* https://git.coding.net/binarywang/weixin-java-tools.git + +=========== +## 可参考的Demo项目 +#### 目前都是公众号的,风格不同,欢迎提供更多的demo供新手参考: +1. https://github.com/wechat-group/weixin-java-mp-demo +1. https://github.com/wechat-group/weixin-java-mp-multi-demo (支持多公众号) +1. https://github.com/wechat-group/weixin-java-tools-springmvc +1. https://github.com/wechat-group/weixin-java-mp-demo-springboot + ## Maven & Gradle 最新正式版本 * 公众号(订阅号、服务号): @@ -63,19 +80,3 @@ gradle: compile 'com.github.binarywang:weixin-java-cp:2.4.0' ``` -=========== - -#### 本项目主要存放在github上,地址为 : -* https://github.com/wechat-group/weixin-java-tools -* ===========但同时会在其他几个网站同步更新,地址分别是: -* https://bitbucket.org/binarywang/weixin-java-tools -* http://git.oschina.net/binary/weixin-java-tools -* https://git.coding.net/binarywang/weixin-java-tools.git - -=========== -## 可参考的Demo项目 -#### 目前都是公众号的,风格不同,欢迎提供更多的demo供新手参考: -1. https://github.com/wechat-group/weixin-java-mp-demo -1. https://github.com/wechat-group/weixin-java-mp-multi-demo (支持多公众号) -1. https://github.com/wechat-group/weixin-java-tools-springmvc -1. https://github.com/wechat-group/weixin-java-mp-demo-springboot From 0d618242999cff5792e421a9ac45a259a737b038 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 30 Dec 2016 23:47:46 +0800 Subject: [PATCH 23/76] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3500d7ee..77d4a2f8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK ### 注意事项: 1. 声明: ***本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。*** -1. 最新更新:2016-11-30 发布2.4.0正式版! +1. 最新更新:**2016-11-30 发布[【2.4.0正式版】](https://github.com/Wechat-Group/weixin-java-tools/releases)**! 1. 自2.0.0版本以来,公众号的接口调整比较大,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。 1. 详细开发文档请看 [Wiki](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。 1. 微信公众号官方文档入口地址:http://mp.weixin.qq.com/wiki (注意,从网上搜到的文档有的虽然地址前面跟这个一样,但明显左侧菜单不一致,是旧的文档,注意不要看错文档)。 From 876aa88f14032bf128e0a01f8740a0682986a94d Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 30 Dec 2016 23:51:35 +0800 Subject: [PATCH 24/76] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 77d4a2f8..ea6d1605 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,12 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK 1. 声明: ***本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。*** 1. 最新更新:**2016-11-30 发布[【2.4.0正式版】](https://github.com/Wechat-Group/weixin-java-tools/releases)**! 1. 自2.0.0版本以来,公众号的接口调整比较大,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。 -1. 详细开发文档请看 [Wiki](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。 +1. 详细开发文档请看 [【Wiki】](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。 1. 微信公众号官方文档入口地址:http://mp.weixin.qq.com/wiki (注意,从网上搜到的文档有的虽然地址前面跟这个一样,但明显左侧菜单不一致,是旧的文档,注意不要看错文档)。 1. 各个模块的Javadoc可以在线查看:[weixin-java-mp](https://binarywang.github.io/weixin-java-mp-javadoc/)、[weixin-java-common](https://binarywang.github.io/weixin-java-common-javadoc/)、[weixin-java-cp](https://binarywang.github.io/weixin-java-cp-javadoc/) -1. 本SDK要求的最低JDK版本是7,为满足少量还在使用JDK6的用户的需求,特意抽出独立的代码分支项目,请参考 https://github.com/binarywang/weixin-java-tools-for-jdk6 ,其他更早的JDK版本则需要自己改造实现。 -1. 有新功能需求,发现BUG,或者由于微信官方接口调整导致的代码问题,可以直接在[Issues](https://github.com/Wechat-Group/weixin-java-tools/issues)页提出issue,便于讨论追踪问题; -1. 如果想贡献代码,请阅读[贡献代码指南](CONTRIBUTION.md)。 +1. 本SDK要求的最低JDK版本是7,为满足少量还在使用JDK6的用户的需求,特意抽出独立的代码分支项目,请参考[【此项目】]( https://github.com/binarywang/weixin-java-tools-for-jdk6) ,其他更早的JDK版本则需要自己改造实现。 +1. 有新功能需求,发现BUG,或者由于微信官方接口调整导致的代码问题,可以直接在[【Issues】](https://github.com/Wechat-Group/weixin-java-tools/issues)页提出issue,便于讨论追踪问题; +1. 如果想贡献代码,请阅读[【代码贡献指南】](CONTRIBUTION.md)。 =========== From d9cbf4cb497b03193b67a309f3952219b0fde37c Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sat, 31 Dec 2016 00:03:48 +0800 Subject: [PATCH 25/76] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ea6d1605..c36e4dbd 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,10 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK 1. 声明: ***本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。*** 1. 最新更新:**2016-11-30 发布[【2.4.0正式版】](https://github.com/Wechat-Group/weixin-java-tools/releases)**! 1. 自2.0.0版本以来,公众号的接口调整比较大,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。 -1. 详细开发文档请看 [【Wiki】](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。 -1. 微信公众号官方文档入口地址:http://mp.weixin.qq.com/wiki (注意,从网上搜到的文档有的虽然地址前面跟这个一样,但明显左侧菜单不一致,是旧的文档,注意不要看错文档)。 +1. SDK详细开发文档请查阅 [【Wiki】](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。 1. 各个模块的Javadoc可以在线查看:[weixin-java-mp](https://binarywang.github.io/weixin-java-mp-javadoc/)、[weixin-java-common](https://binarywang.github.io/weixin-java-common-javadoc/)、[weixin-java-cp](https://binarywang.github.io/weixin-java-cp-javadoc/) 1. 本SDK要求的最低JDK版本是7,为满足少量还在使用JDK6的用户的需求,特意抽出独立的代码分支项目,请参考[【此项目】]( https://github.com/binarywang/weixin-java-tools-for-jdk6) ,其他更早的JDK版本则需要自己改造实现。 -1. 有新功能需求,发现BUG,或者由于微信官方接口调整导致的代码问题,可以直接在[【Issues】](https://github.com/Wechat-Group/weixin-java-tools/issues)页提出issue,便于讨论追踪问题; +1. 如有新功能需求,发现BUG,或者由于微信官方接口调整导致的代码问题,可以直接在[【Issues】](https://github.com/Wechat-Group/weixin-java-tools/issues)页提出issue,便于讨论追踪问题; 1. 如果想贡献代码,请阅读[【代码贡献指南】](CONTRIBUTION.md)。 =========== From a8dad91b145d63142c63ce41742fe49d9546fa17 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 3 Jan 2017 10:56:10 +0800 Subject: [PATCH 26/76] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c36e4dbd..b5bc29b3 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK 1. 最新更新:**2016-11-30 发布[【2.4.0正式版】](https://github.com/Wechat-Group/weixin-java-tools/releases)**! 1. 自2.0.0版本以来,公众号的接口调整比较大,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。 1. SDK详细开发文档请查阅 [【Wiki】](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。 -1. 各个模块的Javadoc可以在线查看:[weixin-java-mp](https://binarywang.github.io/weixin-java-mp-javadoc/)、[weixin-java-common](https://binarywang.github.io/weixin-java-common-javadoc/)、[weixin-java-cp](https://binarywang.github.io/weixin-java-cp-javadoc/) +1. 各个模块的Javadoc可以在线查看(有可能是最新的测试版本的,请注意观察版本号):[weixin-java-mp](https://binarywang.github.io/weixin-java-mp-javadoc/)、[weixin-java-common](https://binarywang.github.io/weixin-java-common-javadoc/)、[weixin-java-cp](https://binarywang.github.io/weixin-java-cp-javadoc/) 1. 本SDK要求的最低JDK版本是7,为满足少量还在使用JDK6的用户的需求,特意抽出独立的代码分支项目,请参考[【此项目】]( https://github.com/binarywang/weixin-java-tools-for-jdk6) ,其他更早的JDK版本则需要自己改造实现。 1. 如有新功能需求,发现BUG,或者由于微信官方接口调整导致的代码问题,可以直接在[【Issues】](https://github.com/Wechat-Group/weixin-java-tools/issues)页提出issue,便于讨论追踪问题; 1. 如果想贡献代码,请阅读[【代码贡献指南】](CONTRIBUTION.md)。 From 2e3a33a74e55ef87c3ca4cf0fdac2f5119e1cd63 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 3 Jan 2017 11:02:53 +0800 Subject: [PATCH 27/76] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=90=8D=EF=BC=8C=E4=BF=9D=E6=8C=81=E8=B7=9Fset=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/impl/WxMpServiceImpl.java | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) 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 d2aa2a2c..2d250035 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 @@ -37,7 +37,7 @@ public class WxMpServiceImpl implements WxMpService { protected final Logger log = LoggerFactory.getLogger(this.getClass()); protected WxSessionManager sessionManager = new StandardSessionManager(); - private WxMpConfigStorage configStorage; + private WxMpConfigStorage wxMpConfigStorage; private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this); private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this); private WxMpMenuService menuService = new WxMpMenuServiceImpl(this); @@ -59,7 +59,7 @@ public class WxMpServiceImpl implements WxMpService { @Override public boolean checkSignature(String timestamp, String nonce, String signature) { try { - return SHA1.gen(this.configStorage.getToken(), timestamp, nonce) + return SHA1.gen(this.wxMpConfigStorage.getToken(), timestamp, nonce) .equals(signature); } catch (Exception e) { return false; @@ -73,18 +73,18 @@ public class WxMpServiceImpl implements WxMpService { @Override public String getAccessToken(boolean forceRefresh) throws WxErrorException { - Lock lock = this.configStorage.getAccessTokenLock(); + Lock lock = this.wxMpConfigStorage.getAccessTokenLock(); try { lock.lock(); if (forceRefresh) { - this.configStorage.expireAccessToken(); + this.wxMpConfigStorage.expireAccessToken(); } - if (this.configStorage.isAccessTokenExpired()) { + if (this.wxMpConfigStorage.isAccessTokenExpired()) { String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" + - "&appid=" + this.configStorage.getAppId() + "&secret=" - + this.configStorage.getSecret(); + "&appid=" + this.wxMpConfigStorage.getAppId() + "&secret=" + + this.wxMpConfigStorage.getSecret(); try { HttpGet httpGet = new HttpGet(url); if (this.httpProxy != null) { @@ -98,7 +98,7 @@ public class WxMpServiceImpl implements WxMpService { throw new WxErrorException(error); } WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); - this.configStorage.updateAccessToken(accessToken.getAccessToken(), + this.wxMpConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn()); } finally { httpGet.releaseConnection(); @@ -110,7 +110,7 @@ public class WxMpServiceImpl implements WxMpService { } finally { lock.unlock(); } - return this.configStorage.getAccessToken(); + return this.wxMpConfigStorage.getAccessToken(); } @Override @@ -120,27 +120,27 @@ public class WxMpServiceImpl implements WxMpService { @Override public String getJsapiTicket(boolean forceRefresh) throws WxErrorException { - Lock lock = this.configStorage.getJsapiTicketLock(); + Lock lock = this.wxMpConfigStorage.getJsapiTicketLock(); try { lock.lock(); if (forceRefresh) { - this.configStorage.expireJsapiTicket(); + this.wxMpConfigStorage.expireJsapiTicket(); } - if (this.configStorage.isJsapiTicketExpired()) { + if (this.wxMpConfigStorage.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.configStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds); + this.wxMpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds); } } finally { lock.unlock(); } - return this.configStorage.getJsapiTicket(); + return this.wxMpConfigStorage.getJsapiTicket(); } @Override @@ -151,7 +151,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.configStorage.getAppId()); + jsapiSignature.setAppid(this.wxMpConfigStorage.getAppId()); jsapiSignature.setTimestamp(timestamp); jsapiSignature.setNoncestr(noncestr); jsapiSignature.setUrl(url); @@ -216,7 +216,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.configStorage.getAppId()); + 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); @@ -232,7 +232,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.configStorage.getAppId()); + 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); @@ -258,8 +258,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.configStorage.getAppId()); - url.append("&secret=").append(this.configStorage.getSecret()); + url.append("appid=").append(this.wxMpConfigStorage.getAppId()); + url.append("&secret=").append(this.wxMpConfigStorage.getSecret()); url.append("&code=").append(code); url.append("&grant_type=authorization_code"); @@ -270,7 +270,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.configStorage.getAppId()); + url.append("appid=").append(this.wxMpConfigStorage.getAppId()); url.append("&grant_type=refresh_token"); url.append("&refresh_token=").append(refreshToken); @@ -397,8 +397,8 @@ public class WxMpServiceImpl implements WxMpService { */ if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) { // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token - this.configStorage.expireAccessToken(); - if (this.configStorage.autoRefreshToken()) { + this.wxMpConfigStorage.expireAccessToken(); + if (this.wxMpConfigStorage.autoRefreshToken()) { return this.execute(executor, uri, data); } } @@ -424,26 +424,26 @@ public class WxMpServiceImpl implements WxMpService { } private void initHttpClient() { - ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage + ApacheHttpClientBuilder apacheHttpClientBuilder = this.wxMpConfigStorage .getApacheHttpClientBuilder(); if (null == apacheHttpClientBuilder) { apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get(); } - apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost()) - .httpProxyPort(this.configStorage.getHttpProxyPort()) - .httpProxyUsername(this.configStorage.getHttpProxyUsername()) - .httpProxyPassword(this.configStorage.getHttpProxyPassword()); + apacheHttpClientBuilder.httpProxyHost(this.wxMpConfigStorage.getHttpProxyHost()) + .httpProxyPort(this.wxMpConfigStorage.getHttpProxyPort()) + .httpProxyUsername(this.wxMpConfigStorage.getHttpProxyUsername()) + .httpProxyPassword(this.wxMpConfigStorage.getHttpProxyPassword()); - // if (this.configStorage.getSSLContext() != null) { + // if (this.wxMpConfigStorage.getSSLContext() != null) { // SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - // this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null, + // this.wxMpConfigStorage.getSSLContext(), new String[] { "TLSv1" }, null, // new DefaultHostnameVerifier()); // apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf); // } - if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) { - this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort()); + if (this.wxMpConfigStorage.getHttpProxyHost() != null && this.wxMpConfigStorage.getHttpProxyPort() > 0) { + this.httpProxy = new HttpHost(this.wxMpConfigStorage.getHttpProxyHost(), this.wxMpConfigStorage.getHttpProxyPort()); } this.httpClient = apacheHttpClientBuilder.build(); @@ -451,12 +451,12 @@ public class WxMpServiceImpl implements WxMpService { @Override public WxMpConfigStorage getWxMpConfigStorage() { - return this.configStorage; + return this.wxMpConfigStorage; } @Override public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) { - this.configStorage = wxConfigProvider; + this.wxMpConfigStorage = wxConfigProvider; this.initHttpClient(); } From 4af30e2b78df59408d9722541f8aedcd6932ca02 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 3 Jan 2017 15:38:48 +0800 Subject: [PATCH 28/76] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b5bc29b3..93ab9278 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK ### 注意事项: 1. 声明: ***本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。*** 1. 最新更新:**2016-11-30 发布[【2.4.0正式版】](https://github.com/Wechat-Group/weixin-java-tools/releases)**! +1. 开源中国网站的本项目首页链接地址:https://www.oschina.net/p/weixin-java-tools-new 1. 自2.0.0版本以来,公众号的接口调整比较大,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。 1. SDK详细开发文档请查阅 [【Wiki】](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。 1. 各个模块的Javadoc可以在线查看(有可能是最新的测试版本的,请注意观察版本号):[weixin-java-mp](https://binarywang.github.io/weixin-java-mp-javadoc/)、[weixin-java-common](https://binarywang.github.io/weixin-java-common-javadoc/)、[weixin-java-cp](https://binarywang.github.io/weixin-java-cp-javadoc/) From 0775802853892ad92337a8416fa3cad2c97324c2 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 3 Jan 2017 15:50:09 +0800 Subject: [PATCH 29/76] Update CONTRIBUTION.md --- CONTRIBUTION.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md index 991f5b3e..e03fe201 100644 --- a/CONTRIBUTION.md +++ b/CONTRIBUTION.md @@ -7,6 +7,7 @@ ### PR方式贡献代码步骤 * 在 GitHub 上 `fork` 到自己的仓库,如 `my_user/weixin-java-tools`,然后 `clone` 到本地,并设置用户信息。 + ```bash $ git clone git@github.com:my_user/weixin-java-tools.git $ cd weixin-java-tools @@ -14,6 +15,7 @@ $ git config user.email "your email" ``` * 修改代码后提交,并推送到自己的仓库。 + ```bash $ #do some change on the content $ git commit -am "Fix issue #1: change something" @@ -21,6 +23,7 @@ $ git push ``` * 在 GitHub 网站上提交 Pull Request。 * 定期使用项目仓库内容更新自己仓库内容。 + ```bash $ git remote add upstream https://github.com/wechat-group/weixin-java-tools $ git fetch upstream From 42e4b804fd5c386b4d280652cba65e6e74066321 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 3 Jan 2017 16:00:50 +0800 Subject: [PATCH 30/76] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 93ab9278..c54d0585 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK 1. 自2.0.0版本以来,公众号的接口调整比较大,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。 1. SDK详细开发文档请查阅 [【Wiki】](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。 1. 各个模块的Javadoc可以在线查看(有可能是最新的测试版本的,请注意观察版本号):[weixin-java-mp](https://binarywang.github.io/weixin-java-mp-javadoc/)、[weixin-java-common](https://binarywang.github.io/weixin-java-common-javadoc/)、[weixin-java-cp](https://binarywang.github.io/weixin-java-cp-javadoc/) -1. 本SDK要求的最低JDK版本是7,为满足少量还在使用JDK6的用户的需求,特意抽出独立的代码分支项目,请参考[【此项目】]( https://github.com/binarywang/weixin-java-tools-for-jdk6) ,其他更早的JDK版本则需要自己改造实现。 +1. 本SDK要求的最低JDK版本是7,还在使用JDK6的用户请参考[【此项目】]( https://github.com/binarywang/weixin-java-tools-for-jdk6) ,而其他更早的JDK版本则需要自己改造实现。 1. 如有新功能需求,发现BUG,或者由于微信官方接口调整导致的代码问题,可以直接在[【Issues】](https://github.com/Wechat-Group/weixin-java-tools/issues)页提出issue,便于讨论追踪问题; 1. 如果想贡献代码,请阅读[【代码贡献指南】](CONTRIBUTION.md)。 From 6a0554d2e1a934c0d4bfb1d226f7cb97008524d0 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 3 Jan 2017 16:01:25 +0800 Subject: [PATCH 31/76] Update CONTRIBUTION.md --- CONTRIBUTION.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md index e03fe201..cbcbb7db 100644 --- a/CONTRIBUTION.md +++ b/CONTRIBUTION.md @@ -1,4 +1,4 @@ -# 关于代码贡献 +# 代码贡献指南 1. 非常欢迎和感谢对本项目发起Pull Request的同学,本项目代码风格为使用2个空格代表一个Tab,因此在提交代码时请注意一下,否则很容易在IDE格式化代码后与原代码产生大量diff,这样会给其他人阅读代码带来极大的困扰。为了便于设置,本项目引入editorconfig插件,请使用eclipse的同学在贡献代码前安装相关插件,IntelliJ IDEA新版本自带支持,如果没有可自行安装插件。 1. 本项目可以采用两种方式接受代码贡献: * 第一种就是基于[Git Flow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)开发流程,因此在发起Pull Request的时候请选择develop分支,详细步骤参考后文。 @@ -9,10 +9,10 @@ * 在 GitHub 上 `fork` 到自己的仓库,如 `my_user/weixin-java-tools`,然后 `clone` 到本地,并设置用户信息。 ```bash - $ git clone git@github.com:my_user/weixin-java-tools.git - $ cd weixin-java-tools - $ git config user.name "yourname" - $ git config user.email "your email" +$ git clone git@github.com:my_user/weixin-java-tools.git +$ cd weixin-java-tools +$ git config user.name "yourname" +$ git config user.email "your email" ``` * 修改代码后提交,并推送到自己的仓库。 From f466a1d0f8f1b45a87ce25163bb4959c86a2cc8d Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 3 Jan 2017 16:03:09 +0800 Subject: [PATCH 32/76] Update README.md --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c54d0585..0cde9ac6 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,8 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK =========== -#### 本项目主要存放在github上,地址为 : -* https://github.com/wechat-group/weixin-java-tools -* ===========但同时会在其他几个网站同步更新,地址分别是: +#### 本项目主要存放在github上,地址为 : https://github.com/wechat-group/weixin-java-tools +但同时会在其他几个网站同步更新,地址分别是: * https://bitbucket.org/binarywang/weixin-java-tools * http://git.oschina.net/binary/weixin-java-tools * https://git.coding.net/binarywang/weixin-java-tools.git @@ -43,10 +42,10 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK =========== ## 可参考的Demo项目 #### 目前都是公众号的,风格不同,欢迎提供更多的demo供新手参考: -1. https://github.com/wechat-group/weixin-java-mp-demo -1. https://github.com/wechat-group/weixin-java-mp-multi-demo (支持多公众号) -1. https://github.com/wechat-group/weixin-java-tools-springmvc -1. https://github.com/wechat-group/weixin-java-mp-demo-springboot +* https://github.com/wechat-group/weixin-java-mp-demo +* https://github.com/wechat-group/weixin-java-mp-multi-demo (支持多公众号) +* https://github.com/wechat-group/weixin-java-tools-springmvc +* https://github.com/wechat-group/weixin-java-mp-demo-springboot ## Maven & Gradle 最新正式版本 From 67e773bb7979fbc042bac829a025ba47b4a2c90a Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 3 Jan 2017 17:24:20 +0800 Subject: [PATCH 33/76] Update README.md --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0cde9ac6..c933b0eb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Weixin Java Tools 微信公众号/企业号开发Java SDK +Weixin Java Tools —— 微信公众号&企业号开发 Java SDK ===================================== [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.binarywang/weixin-java-parent/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.binarywang/weixin-java-parent) [![Build Status](https://travis-ci.org/Wechat-Group/weixin-java-tools.svg?branch=develop)](https://travis-ci.org/Wechat-Group/weixin-java-tools) @@ -32,12 +32,11 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK 分别查看所有最新的版本。 =========== - -#### 本项目主要存放在github上,地址为 : https://github.com/wechat-group/weixin-java-tools -但同时会在其他几个网站同步更新,地址分别是: -* https://bitbucket.org/binarywang/weixin-java-tools -* http://git.oschina.net/binary/weixin-java-tools -* https://git.coding.net/binarywang/weixin-java-tools.git +#### 本项目在几个著名的代码托管网站同步更新,地址分别是: +* 码云:http://git.oschina.net/binary/weixin-java-tools +* GitHub: https://github.com/wechat-group/weixin-java-tools +* Bitbucket:https://bitbucket.org/binarywang/weixin-java-tools +* Coding: https://git.coding.net/binarywang/weixin-java-tools.git =========== ## 可参考的Demo项目 From c47b8eceba4824581c6ad8a76a585e5fb226d9b2 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Wed, 4 Jan 2017 19:23:03 +0800 Subject: [PATCH 34/76] =?UTF-8?q?=E4=BF=AE=E5=A4=8DtoMap=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=9A=84bug=EF=BC=8C=E5=B9=B6=E5=8A=A0=E5=85=A5=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/bean/pay/result/WxPayBaseResult.java | 18 +++++-- .../bean/pay/result/WxPayBaseResultTest.java | 49 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index b06f3cca..bbb0fe27 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -4,9 +4,10 @@ import com.google.common.collect.Maps; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import io.restassured.internal.path.xml.NodeChildrenImpl; +import io.restassured.internal.path.xml.NodeImpl; import io.restassured.path.xml.XmlPath; import io.restassured.path.xml.element.Node; -import io.restassured.path.xml.element.NodeChildren; +import io.restassured.path.xml.exception.XmlPathException; import me.chanjar.weixin.common.util.ToStringUtils; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import org.slf4j.Logger; @@ -186,12 +187,23 @@ public abstract class WxPayBaseResult { public Map toMap() { Map result = Maps.newHashMap(); XmlPath xmlPath = new XmlPath(this.xmlString); - NodeChildren nodeChildren = xmlPath.getNodeChildren("xml"); - Iterator iterator = nodeChildren.nodeIterator(); + NodeImpl rootNode = null; + try { + rootNode = xmlPath.get("xml"); + } catch (XmlPathException e) { + throw new RuntimeException("xml数据有问题,请核实!"); + } + + if (rootNode == null) { + throw new RuntimeException("xml数据有问题,请核实!"); + } + + Iterator iterator = rootNode.children().nodeIterator(); while (iterator.hasNext()) { Node node = iterator.next(); result.put(node.name(), node.value()); } + return result; } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java new file mode 100644 index 00000000..0b1e7ac9 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java @@ -0,0 +1,49 @@ +package me.chanjar.weixin.mp.bean.pay.result; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.Map; + +/** + *
    + * Created by Binary Wang on 2017-01-04.
    + * @author binarywang(Binary Wang)
    + * 
    + */ +public class WxPayBaseResultTest { + @Test + public void testToMap() throws Exception { + WxPayOrderQueryResult result = new WxPayOrderQueryResult(); + result.setXmlString("\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""); + Map map = result.toMap(); + System.out.println(map); + + Assert.assertEquals("SUCCESS", map.get("return_code")); + Assert.assertEquals("订单额外描述", map.get("attach")); + + result.setXmlString(""); + System.out.println(result.toMap()); + } + +} From cbf78114f724327795562dc2afff4d11d5c00e5f Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 5 Jan 2017 12:28:58 +0800 Subject: [PATCH 35/76] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=9C=E5=AF=B9=E8=B1=A1=E4=B8=AD?= =?UTF-8?q?coupon=E7=9A=84=E7=BB=84=E8=A3=85=E9=80=BB=E8=BE=91=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E5=B9=B6=E5=8A=A0=E5=85=A5=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/result/WxPayOrderQueryResult.java | 157 +++++++++--------- .../pay/result/WxPayOrderQueryResultTest.java | 65 ++++++++ 2 files changed, 146 insertions(+), 76 deletions(-) create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java index 373497f3..150cac38 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java @@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.bean.pay.result; import com.google.common.collect.Lists; import com.thoughtworks.xstream.annotations.XStreamAlias; +import io.restassured.path.xml.XmlPath; import java.util.List; @@ -17,6 +18,7 @@ import java.util.List; *
  • 示例值 *
  • 描述 * + * * @author binarywang(Binary Wang) */ @XStreamAlias("xml") @@ -179,75 +181,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult { private Integer couponCount; private List coupons; - - public static class Coupon { - /** - *
    代金券类型
    -     * coupon_type_$n
    -     * 否
    -     * String
    -     * CASH
    -     * 
  • CASH--充值代金券 - *
  • NO_CASH---非充值代金券 - * 订单使用代金券时有返回(取值:CASH、NO_CASH)。$n为下标,从0开始编号,举例:coupon_type_$0 - *
  • - */ - private String couponType; - - /** - *
    代金券ID
    -     * coupon_id_$n
    -     * 否
    -     * String(20)
    -     * 10000
    -     * 代金券ID, $n为下标,从0开始编号
    -     * 
    - */ - private String couponId; - - /** - *
    单个代金券支付金额
    -     * coupon_fee_$n
    -     * 否
    -     * Int
    -     * 100
    -     * 单个代金券支付金额, $n为下标,从0开始编号
    -     * 
    - */ - private Integer couponFee; - - public Coupon(String couponType, String couponId, Integer couponFee) { - this.couponType = couponType; - this.couponId = couponId; - this.couponFee = couponFee; - } - - public String getCouponType() { - return this.couponType; - } - - public void setCouponType(String couponType) { - this.couponType = couponType; - } - - public String getCouponId() { - return this.couponId; - } - - public void setCouponId(String couponId) { - this.couponId = couponId; - } - - public Integer getCouponFee() { - return this.couponFee; - } - - public void setCouponFee(Integer couponFee) { - this.couponFee = couponFee; - } - - } - /** *
    微信支付订单号
        * transaction_id
    @@ -259,7 +192,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
        */
       @XStreamAlias("transaction_id")
       private String transactionId;
    -
       /**
        * 
    商户订单号
        * out_trade_no
    @@ -271,7 +203,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
        */
       @XStreamAlias("out_trade_no")
       private String outTradeNo;
    -
       /**
        * 
    附加数据
        * attach
    @@ -283,7 +214,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
        */
       @XStreamAlias("attach")
       private String attach;
    -
       /**
        * 
    支付完成时间
        * time_end
    @@ -295,7 +225,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
        */
       @XStreamAlias("time_end")
       private String timeEnd;
    -
       /**
        * 
    交易状态描述
        * trade_state_desc
    @@ -460,10 +389,86 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
         this.tradeStateDesc = tradeStateDesc;
       }
     
    -  public void composeCoupons(String xmlString){
    -    if(this.couponCount != null && this.couponCount > 0 ){
    +  /**
    +   * 通过xml组装coupons属性内容
    +   */
    +  public void composeCoupons() {
    +    if (this.couponCount != null && this.couponCount > 0) {
           this.coupons = Lists.newArrayList();
    -      //TODO 暂时待实现
    +      XmlPath xmlPath = new XmlPath(this.getXmlString());
    +      for (int i = 0; i < this.couponCount; i++){
    +        this.coupons.add(new Coupon(this.getXmlValueIfExists(xmlPath, "xml.coupon_type_" + i, String.class),
    +          this.getXmlValueIfExists(xmlPath, "xml.coupon_id_" + i, String.class),
    +          this.getXmlValueIfExists(xmlPath, "xml.coupon_fee_" + i, Integer.class)));
    +      }
    +    }
    +  }
    +
    +  public static class Coupon {
    +    /**
    +     * 
    代金券类型
    +     * coupon_type_$n
    +     * 否
    +     * String
    +     * CASH
    +     * 
  • CASH--充值代金券 + *
  • NO_CASH---非充值代金券 + * 订单使用代金券时有返回(取值:CASH、NO_CASH)。$n为下标,从0开始编号,举例:coupon_type_$0 + *
  • + */ + private String couponType; + + /** + *
    代金券ID
    +     * coupon_id_$n
    +     * 否
    +     * String(20)
    +     * 10000
    +     * 代金券ID, $n为下标,从0开始编号
    +     * 
    + */ + private String couponId; + + /** + *
    单个代金券支付金额
    +     * coupon_fee_$n
    +     * 否
    +     * Int
    +     * 100
    +     * 单个代金券支付金额, $n为下标,从0开始编号
    +     * 
    + */ + private Integer couponFee; + + public Coupon(String couponType, String couponId, Integer couponFee) { + this.couponType = couponType; + this.couponId = couponId; + this.couponFee = couponFee; + } + + public String getCouponType() { + return this.couponType; + } + + public void setCouponType(String couponType) { + this.couponType = couponType; } + + public String getCouponId() { + return this.couponId; + } + + public void setCouponId(String couponId) { + this.couponId = couponId; + } + + public Integer getCouponFee() { + return this.couponFee; + } + + public void setCouponFee(Integer couponFee) { + this.couponFee = couponFee; + } + } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java new file mode 100644 index 00000000..1582ea17 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java @@ -0,0 +1,65 @@ +package me.chanjar.weixin.mp.bean.pay.result; + +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + *
    + * Created by Binary Wang on 2017-01-04.
    + * @author binarywang(Binary Wang)
    + * 
    + */ +public class WxPayOrderQueryResultTest { + @Test + public void testComposeCoupons() throws Exception { + /** + * xml样例字符串来自于官方文档,并稍加改造加入了coupon相关的数据便于测试 + */ + String xmlString = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 2\n" + + " \n" + + " 10000\n" + + " 100\n" + + " \n" + + " 10001\n" + + " 200\n" + + ""; + + WxPayOrderQueryResult orderQueryResult = WxPayOrderQueryResult.fromXML(xmlString, WxPayOrderQueryResult.class); + orderQueryResult.composeCoupons(); + + Assert.assertEquals(orderQueryResult.getCouponCount().intValue(), 2); + Assert.assertNotNull(orderQueryResult.getCoupons()); + Assert.assertEquals(orderQueryResult.getCoupons().size(), 2); + + Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponFee().intValue(), 100); + Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponFee().intValue(), 200); + + Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponType(), "CASH"); + Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponType(), "NO_CASH"); + + Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponId(), "10000"); + Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponId(), "10001"); + + } + +} From 55d66ac7c9c40dd8acbdff423e3ee4ba2517c97d Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 5 Jan 2017 12:29:26 +0800 Subject: [PATCH 36/76] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=94=AF=E4=BB=98=E7=9B=B8=E5=85=B3=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java | 4 ++-- .../mp/bean/pay/result/WxPayRedpackQueryResult.java | 10 +++++----- .../mp/bean/pay/result/WxPayRefundQueryResult.java | 7 +++++-- .../mp/bean/pay/result/WxPayRefundQueryResultTest.java | 5 ++--- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java index 6ab639f1..8103993c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java @@ -83,7 +83,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { String url = PAY_BASE_URL + "/pay/refundquery"; String responseContent = this.executeRequest(url, request.toXML()); WxPayRefundQueryResult result = WxPayRefundQueryResult.fromXML(responseContent, WxPayRefundQueryResult.class); - result.composeRefundRecords(responseContent); + result.composeRefundRecords(); this.checkResult(result); return result; } @@ -189,7 +189,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { String url = PAY_BASE_URL + "/pay/orderquery"; String responseContent = this.executeRequest(url, request.toXML()); WxPayOrderQueryResult result = WxPayOrderQueryResult.fromXML(responseContent, WxPayOrderQueryResult.class); - result.composeCoupons(responseContent); + result.composeCoupons(); this.checkResult(result); return result; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java index 8a2e37fa..6febaa37 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRedpackQueryResult.java @@ -52,11 +52,11 @@ public class WxPayRedpackQueryResult extends WxPayBaseResult { * RECEIVED * string(16) * SENDING:发放中, - * SENT:已发放待领取, - * FAILED:发放失败, - * RECEIVED:已领取, - * RFUND_ING:退款中, - * REFUND:已退款 + * SENT:已发放待领取, + * FAILED:发放失败, + * RECEIVED:已领取, + * RFUND_ING:退款中, + * REFUND:已退款 *
    */ @XStreamAlias("status") diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java index 146c35df..a75946a3 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java @@ -184,10 +184,13 @@ public class WxPayRefundQueryResult extends WxPayBaseResult { this.refundRecords = refundRecords; } - public void composeRefundRecords(String xmlString) { + /** + * 组装生成退款记录属性的内容 + */ + public void composeRefundRecords() { if (this.refundCount != null && this.refundCount > 0) { this.refundRecords = Lists.newArrayList(); - XmlPath xmlPath = new XmlPath(xmlString); + XmlPath xmlPath = new XmlPath(this.getXmlString()); for (int i = 0; i < this.refundCount; i++) { RefundRecord refundRecord = new RefundRecord(); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java index 9427bd01..34672417 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java @@ -33,9 +33,8 @@ public class WxPayRefundQueryResultTest { " \n" + ""; - WxPayRefundQueryResult result = new WxPayRefundQueryResult(); - result.setRefundCount(1); - result.composeRefundRecords(xmlString); + WxPayRefundQueryResult result = WxPayRefundQueryResult.fromXML(xmlString, WxPayRefundQueryResult.class); + result.composeRefundRecords(); Assert.assertNotNull(result.getRefundRecords()); Assert.assertEquals(result.getRefundRecords().size(), 1); From 2d072e909f2d8a6ba937526d8205b72eceae054a Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 5 Jan 2017 14:07:28 +0800 Subject: [PATCH 37/76] =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/bean/pay/result/WxPayBaseResult.java | 6 ++--- .../pay/result/WxPayOrderQueryResult.java | 6 ++--- .../pay/result/WxPayRefundQueryResult.java | 24 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index bbb0fe27..4dd133ab 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -207,7 +207,7 @@ public abstract class WxPayBaseResult { return result; } - private String getXmlValueIfExists(XmlPath xmlPath, String path) { + private String getXmlValue(XmlPath xmlPath, String path) { if (xmlPath.get(path) instanceof NodeChildrenImpl) { if (((NodeChildrenImpl) xmlPath.get(path)).size() == 0) { return null; @@ -217,8 +217,8 @@ public abstract class WxPayBaseResult { return xmlPath.getString(path); } - protected T getXmlValueIfExists(XmlPath xmlPath, String path, Class clz) { - String value = this.getXmlValueIfExists(xmlPath, path); + protected T getXmlValue(XmlPath xmlPath, String path, Class clz) { + String value = this.getXmlValue(xmlPath, path); if (value == null) { return null; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java index 150cac38..8cdf4e6d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java @@ -397,9 +397,9 @@ public class WxPayOrderQueryResult extends WxPayBaseResult { this.coupons = Lists.newArrayList(); XmlPath xmlPath = new XmlPath(this.getXmlString()); for (int i = 0; i < this.couponCount; i++){ - this.coupons.add(new Coupon(this.getXmlValueIfExists(xmlPath, "xml.coupon_type_" + i, String.class), - this.getXmlValueIfExists(xmlPath, "xml.coupon_id_" + i, String.class), - this.getXmlValueIfExists(xmlPath, "xml.coupon_fee_" + i, Integer.class))); + this.coupons.add(new Coupon(this.getXmlValue(xmlPath, "xml.coupon_type_" + i, String.class), + this.getXmlValue(xmlPath, "xml.coupon_id_" + i, String.class), + this.getXmlValue(xmlPath, "xml.coupon_fee_" + i, Integer.class))); } } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java index a75946a3..1e569ac1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResult.java @@ -196,16 +196,16 @@ public class WxPayRefundQueryResult extends WxPayBaseResult { RefundRecord refundRecord = new RefundRecord(); this.refundRecords.add(refundRecord); - refundRecord.setOutRefundNo(this.getXmlValueIfExists(xmlPath, "xml.out_refund_no_" + i, String.class)); - refundRecord.setRefundId(this.getXmlValueIfExists(xmlPath, "xml.refund_id_" + i, String.class)); - refundRecord.setRefundChannel(this.getXmlValueIfExists(xmlPath, "xml.refund_channel_" + i, String.class)); - refundRecord.setRefundFee(this.getXmlValueIfExists(xmlPath, "xml.refund_fee_" + i, Integer.class)); - refundRecord.setSettlementRefundFee(this.getXmlValueIfExists(xmlPath, "xml.settlement_refund_fee_" + i, Integer.class)); - refundRecord.setCouponType(this.getXmlValueIfExists(xmlPath, "xml.coupon_type_" + i, String.class)); - refundRecord.setCouponRefundFee(this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_fee_" + i, Integer.class)); - refundRecord.setCouponRefundCount(this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_count_" + i, Integer.class)); - refundRecord.setRefundStatus(this.getXmlValueIfExists(xmlPath, "xml.refund_status_" + i, String.class)); - refundRecord.setRefundRecvAccout(this.getXmlValueIfExists(xmlPath, "xml.refund_recv_accout_" + i, String.class)); + refundRecord.setOutRefundNo(this.getXmlValue(xmlPath, "xml.out_refund_no_" + i, String.class)); + refundRecord.setRefundId(this.getXmlValue(xmlPath, "xml.refund_id_" + i, String.class)); + refundRecord.setRefundChannel(this.getXmlValue(xmlPath, "xml.refund_channel_" + i, String.class)); + refundRecord.setRefundFee(this.getXmlValue(xmlPath, "xml.refund_fee_" + i, Integer.class)); + refundRecord.setSettlementRefundFee(this.getXmlValue(xmlPath, "xml.settlement_refund_fee_" + i, Integer.class)); + refundRecord.setCouponType(this.getXmlValue(xmlPath, "xml.coupon_type_" + i, String.class)); + refundRecord.setCouponRefundFee(this.getXmlValue(xmlPath, "xml.coupon_refund_fee_" + i, Integer.class)); + refundRecord.setCouponRefundCount(this.getXmlValue(xmlPath, "xml.coupon_refund_count_" + i, Integer.class)); + refundRecord.setRefundStatus(this.getXmlValue(xmlPath, "xml.refund_status_" + i, String.class)); + refundRecord.setRefundRecvAccout(this.getXmlValue(xmlPath, "xml.refund_recv_accout_" + i, String.class)); if (refundRecord.getCouponRefundCount() == null || refundRecord.getCouponRefundCount() == 0) { continue; @@ -215,8 +215,8 @@ public class WxPayRefundQueryResult extends WxPayBaseResult { for (int j = 0; j < refundRecord.getCouponRefundCount(); j++) { coupons.add( new RefundRecord.RefundCoupon( - this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_id_" + i + "_" + j, String.class), - this.getXmlValueIfExists(xmlPath, "xml.coupon_refund_fee_" + i + "_" + j, Integer.class) + this.getXmlValue(xmlPath, "xml.coupon_refund_id_" + i + "_" + j, String.class), + this.getXmlValue(xmlPath, "xml.coupon_refund_fee_" + i + "_" + j, Integer.class) ) ); } From c142daa734ad9dee6b017469a38ab6a31c259e8f Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 6 Jan 2017 11:40:46 +0800 Subject: [PATCH 38/76] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=AB=E7=A0=81?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E7=94=9F=E6=88=90=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=E5=8F=8A=E5=85=B6=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=8C#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weixin-java-mp/pom.xml | 6 +- .../chanjar/weixin/mp/api/WxMpPayService.java | 29 ++++++++++ .../mp/api/impl/WxMpPayServiceImpl.java | 38 +++++++++++++ .../chanjar/weixin/mp/api/ApiTestModule.java | 1 - .../mp/api/impl/WxMpPayServiceImplTest.java | 55 +++++++++++++++---- 5 files changed, 115 insertions(+), 14 deletions(-) diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 335fe3a3..759ee7ff 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -59,7 +59,11 @@ xml-path 3.0.1 - + + com.github.binarywang + qrcode-utils + 1.0 + diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java index 79787744..d0b21109 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java @@ -7,6 +7,7 @@ import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; import me.chanjar.weixin.mp.bean.pay.result.*; +import java.io.File; import java.util.Map; /** @@ -235,4 +236,32 @@ public interface WxMpPayService { */ WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorException; + /** + *
    +   * 扫码支付模式一生成二维码的方法
    +   * 二维码中的内容为链接,形式为:
    +   * weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX
    +   * 其中XXXXX为商户需要填写的内容,商户将该链接生成二维码,如需要打印发布二维码,需要采用此格式。商户可调用第三方库生成二维码图片。
    +   * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4
    +   * 
    + * @param productId 产品Id + * @param sideLength 要生成的二维码的边长,如果为空,则取默认值400 + * @param logoFile 商户logo图片的文件对象,可以为空 + * @return 生成的二维码的字节数组 + */ + byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength); + + /** + *
    +   * 扫码支付模式二生成二维码的方法
    +   * 对应链接格式:weixin://wxpay/bizpayurl?sr=XXXXX。请商户调用第三方库将code_url生成二维码图片。
    +   * 该模式链接较短,生成的二维码打印到结账小票上的识别率较高。
    +   * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5
    +   * 
    + * @param codeUrl 微信返回的交易会话的二维码链接 + * @param logoFile 商户logo图片的文件对象,可以为空 + * @param sideLength 要生成的二维码的边长,如果为空,则取默认值400 + * @return 生成的二维码的字节数组 + */ + byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java index 8103993c..33bf6cdf 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.api.impl; +import com.github.binarywang.utils.qrcode.QrcodeUtils; +import com.google.common.collect.Maps; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.BeanUtils; @@ -25,6 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.net.ssl.SSLContext; +import java.io.File; import java.io.IOException; import java.util.*; @@ -316,6 +319,41 @@ public class WxMpPayServiceImpl implements WxMpPayService { return result; } + @Override + public byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength) { + //weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX + StringBuilder codeUrl = new StringBuilder("weixin://wxpay/bizpayurl?"); + Map params = Maps.newHashMap(); + params.put("appid", this.getConfig().getAppId()); + params.put("mch_id", this.getConfig().getPartnerId()); + params.put("product_id", productId); + params.put("time_stamp", String.valueOf(System.currentTimeMillis())); + params.put("nonce_str", String.valueOf(System.currentTimeMillis())); + + String sign = this.createSign(params); + params.put("sign", sign); + + for (String key : params.keySet()) { + codeUrl.append(key + "=" + params.get(key) + "&"); + } + + String content = codeUrl.toString().substring(0, codeUrl.length() - 1); + if (sideLength == null || sideLength < 1) { + return QrcodeUtils.createQrcode(content, logoFile); + } + + return QrcodeUtils.createQrcode(content, sideLength, logoFile); + } + + @Override + public byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength) { + if (sideLength == null || sideLength < 1) { + return QrcodeUtils.createQrcode(codeUrl, logoFile); + } + + return QrcodeUtils.createQrcode(codeUrl, sideLength, logoFile); + } + private String executeRequest(String url, String requestStr) throws WxErrorException { HttpPost httpPost = new HttpPost(url); if (this.wxMpService.getHttpProxy() != null) { 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 13491d20..c506df0f 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 @@ -19,7 +19,6 @@ public class ApiTestModule implements Module { WxXmlMpInMemoryConfigStorage config = this .fromXml(WxXmlMpInMemoryConfigStorage.class, is1); config.setAccessTokenLock(new ReentrantLock()); - config.setSslContextFilePath(config.getKeyPath()); WxMpService wxService = new WxMpServiceImpl(); wxService.setWxMpConfigStorage(config); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 418b710b..248fc7dd 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.api.impl; +import com.github.binarywang.utils.qrcode.QrcodeUtils; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.ApiTestModule; @@ -10,9 +11,13 @@ import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest; import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; import me.chanjar.weixin.mp.bean.pay.result.*; +import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; +import java.nio.file.Files; +import java.nio.file.Path; + /** * 测试支付相关接口 * Created by Binary Wang on 2016/7/28. @@ -22,7 +27,6 @@ import org.testng.annotations.Test; @Test @Guice(modules = ApiTestModule.class) public class WxMpPayServiceImplTest { - @Inject protected WxMpService wxService; @@ -32,9 +36,17 @@ public class WxMpPayServiceImplTest { } /** - * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest)} . + * 需要证书的接口需要先执行该方法 */ @Test + public void setSSLKey(){ + WxXmlMpInMemoryConfigStorage config = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); + config.setSslContextFilePath(config.getKeyPath()); + } + /** + * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest)} . + */ + @Test(dependsOnMethods = {"setSSLKey"}) public void testRefund() throws Exception { WxPayRefundRequest request = new WxPayRefundRequest(); request.setOutRefundNo("aaa"); @@ -45,7 +57,6 @@ public class WxMpPayServiceImplTest { System.err.println(result); } - /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refundQuery(String, String, String, String)} . */ @@ -63,15 +74,10 @@ public class WxMpPayServiceImplTest { System.err.println(result); } - @Test - public void testCheckJSSDKCallbackDataSignature() throws Exception { - - } - /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#sendRedpack(WxPaySendRedpackRequest)} . */ - @Test + @Test(dependsOnMethods = {"setSSLKey"}) public void testSendRedpack() throws Exception { WxPaySendRedpackRequest request = new WxPaySendRedpackRequest(); request.setActName("abc"); @@ -86,7 +92,7 @@ public class WxMpPayServiceImplTest { /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryRedpack(String)}. */ - @Test + @Test(dependsOnMethods = {"setSSLKey"}) public void testQueryRedpack() throws Exception { WxPayRedpackQueryResult redpackResult = this.wxService.getPayService().queryRedpack("aaaa"); System.err.println(redpackResult); @@ -125,7 +131,7 @@ public class WxMpPayServiceImplTest { /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#entPay(WxEntPayRequest)}. */ - @Test + @Test(dependsOnMethods = {"setSSLKey"}) public final void testEntPay() throws WxErrorException { WxEntPayRequest request = new WxEntPayRequest(); System.err.println(this.wxService.getPayService().entPay(request)); @@ -134,8 +140,33 @@ public class WxMpPayServiceImplTest { /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryEntPay(String)}. */ - @Test + @Test(dependsOnMethods = {"setSSLKey"}) public final void testQueryEntPay() throws WxErrorException { System.err.println(this.wxService.getPayService().queryEntPay("11212121")); } + + @Test + public void testCreateScanPayQrcodeMode1() throws Exception { + String productId = "abc"; + byte[] bytes = this.wxService.getPayService().createScanPayQrcodeMode1(productId, null, null); + Path qrcodeFilePath = Files.createTempFile("qrcode_", ".jpg"); + Files.write(qrcodeFilePath, bytes); + String qrcodeContent = QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()); + System.out.println(qrcodeContent); + + Assert.assertTrue(qrcodeContent.startsWith("weixin://wxpay/bizpayurl?")); + Assert.assertTrue(qrcodeContent.contains("product_id=" + productId)); + } + + @Test + public void testCreateScanPayQrcodeMode2() throws Exception { + String qrcodeContent = "abc"; + byte[] bytes = this.wxService.getPayService().createScanPayQrcodeMode2(qrcodeContent, null, null); + Path qrcodeFilePath = Files.createTempFile("qrcode_", ".jpg"); + Files.write(qrcodeFilePath, bytes); + + Assert.assertEquals(QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()), qrcodeContent); + } + + } From c02b2e2cac15ec98417a7fc4689f9bd36018ecc3 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 6 Jan 2017 12:14:10 +0800 Subject: [PATCH 39/76] release 2.4.8.BETA --- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- weixin-java-osgi/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index a8f2f424..c1bf3143 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.4.7.BETA + 2.4.8.BETA pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 8f78458d..26fdff4a 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.7.BETA + 2.4.8.BETA weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 2adec10e..9b5f3877 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.7.BETA + 2.4.8.BETA weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 759ee7ff..197e54c2 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.7.BETA + 2.4.8.BETA weixin-java-mp WeiXin Java Tools - MP diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml index ee96e71f..5d749f8f 100644 --- a/weixin-java-osgi/pom.xml +++ b/weixin-java-osgi/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.7.BETA + 2.4.8.BETA weixin-java-osgi From 81159c241999aa273c29b0fd501457da348bda81 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Fri, 6 Jan 2017 16:59:06 +0800 Subject: [PATCH 40/76] =?UTF-8?q?=E5=B0=86=E5=8F=91=E5=B8=83=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E9=85=8D=E7=BD=AE=E6=94=B9=E4=B8=BA=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=90=8E=E8=87=AA=E5=8A=A8=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c1bf3143..2092494c 100644 --- a/pom.xml +++ b/pom.xml @@ -307,7 +307,7 @@ ossrh https://oss.sonatype.org/ - false + true From 13136589db95bed580c6db5d55fbd250755f4744 Mon Sep 17 00:00:00 2001 From: jkli Date: Sat, 7 Jan 2017 16:29:29 +0800 Subject: [PATCH 41/76] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E7=A1=AC=E4=BB=B6=E8=AE=BE=E5=A4=87=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E7=9A=84OpenID=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 参考 http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-1 --- .../weixin/mp/bean/message/WxMpXmlMessage.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java index 36b4c104..0f1a3ffe 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java @@ -281,6 +281,12 @@ public class WxMpXmlMessage implements Serializable { @XStreamConverter(value = XStreamCDataConverter.class) private String deviceId; + /** + * 微信用户账号的OpenID + */ + @XStreamAlias("OpenID") + @XStreamConverter(value = XStreamCDataConverter.class) + private String openId; @XStreamAlias("HardWare") private HardWare hardWare = new HardWare(); @@ -375,6 +381,14 @@ public class WxMpXmlMessage implements Serializable { this.deviceId = deviceId; } + public String getOpenId() { + return openId; + } + + public void setOpenId(String openId) { + this.openId = openId; + } + public Long getExpiredTime() { return this.expiredTime; } From fa7360d0ca076882ae5d869ea92990923bee561d Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 8 Jan 2017 23:27:30 +0800 Subject: [PATCH 42/76] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E4=BA=A4=E6=98=93=E4=BF=9D=E9=9A=9C=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20#56?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/WxMpPayService.java | 19 +- .../mp/api/impl/WxMpPayServiceImpl.java | 13 +- .../bean/pay/request/WxPayReportRequest.java | 273 ++++++++++++++++++ .../mp/bean/pay/result/WxPayBaseResult.java | 3 +- .../mp/api/impl/WxMpPayServiceImplTest.java | 17 +- 5 files changed, 314 insertions(+), 11 deletions(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayReportRequest.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java index d0b21109..a6dd6654 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java @@ -1,10 +1,7 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; +import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; import java.io.File; @@ -182,7 +179,6 @@ public interface WxMpPayService { */ boolean checkSign(Map params, String signKey); - /** * 发送微信红包给个人用户 *
    @@ -264,4 +260,17 @@ public interface WxMpPayService {
        * @return 生成的二维码的字节数组
        */
       byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength);
    +
    +  /**
    +   * 
    +   * 交易保障
    +   * 应用场景:
    +   *  商户在调用微信支付提供的相关接口时,会得到微信支付返回的相关信息以及获得整个接口的响应时间。
    +   *  为提高整体的服务水平,协助商户一起提高服务质量,微信支付提供了相关接口调用耗时和返回信息的主动上报接口,
    +   *  微信支付可以根据商户侧上报的数据进一步优化网络部署,完善服务监控,和商户更好的协作为用户提供更好的业务体验。
    +   * 接口地址: https://api.mch.weixin.qq.com/payitil/report
    +   * 是否需要证书:不需要
    +   * 
    + */ + void report(WxPayReportRequest request) throws WxErrorException; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java index 33bf6cdf..a9ef983b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java @@ -95,7 +95,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { private void checkResult(WxPayBaseResult result) throws WxErrorException { //校验返回结果签名 Map map = result.toMap(); - if (!this.checkSign(map)) { + if (result.getSign() != null &&!this.checkSign(map)) { log.debug("校验结果签名失败,参数:{}", map); throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("参数格式校验错误!").build()); } @@ -354,6 +354,17 @@ public class WxMpPayServiceImpl implements WxMpPayService { return QrcodeUtils.createQrcode(codeUrl, sideLength, logoFile); } + public void report(WxPayReportRequest request) throws WxErrorException { + BeanUtils.checkRequiredFields(request); + this.initRequest(request); + request.setSign(this.createSign(request)); + + String url = PAY_BASE_URL + "/payitil/report"; + String responseContent = this.wxMpService.post(url, request.toXML()); + WxPayBaseResult result = WxPayBaseResult.fromXML(responseContent, WxPayBaseResult.class); + this.checkResult(result); + } + private String executeRequest(String url, String requestStr) throws WxErrorException { HttpPost httpPost = new HttpPost(url); if (this.wxMpService.getHttpProxy() != null) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayReportRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayReportRequest.java new file mode 100644 index 00000000..44b047f8 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayReportRequest.java @@ -0,0 +1,273 @@ +package me.chanjar.weixin.mp.bean.pay.request; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import me.chanjar.weixin.common.annotation.Required; + +/** + *
    + * 微信支付-交易保障请求参数
    + * 注释中各行每个字段描述对应如下:
    + * 
  • 字段名 + *
  • 变量名 + *
  • 是否必填 + *
  • 类型 + *
  • 示例值 + *
  • 描述 + *
  • + * + * @author binarywang(Binary Wang) + */ +@XStreamAlias("xml") +public class WxPayReportRequest extends WxPayBaseRequest { + /** + *
    +   * 设备号
    +   * device_info
    +   * 否
    +   * String(32)
    +   * 013467007045764
    +   * 商户自定义的终端设备号,如门店编号、设备的ID等
    +   * 
    + */ + @XStreamAlias("device_info") + private String deviceInfo; + + /** + *
    +   * 签名类型
    +   * sign_type
    +   * 否
    +   * String(32)
    +   * HMAC-SHA256
    +   * 签名类型,目前支持HMAC-SHA256和MD5,默认为MD5
    +   * 
    + */ + @XStreamAlias("sign_type") + private String signType; + + /** + *
    +   * 接口URL
    +   * interface_url
    +   * 是
    +   * String(127)
    +   * https://api.mch.weixin.qq.com/pay/unifiedorder
    +   * 报对应的接口的完整URL,类似:https://api.mch.weixin.qq.com/pay/unifiedorder,
    +   * 对于刷卡支付,为更好的和商户共同分析一次业务行为的整体耗时情况,
    +   * 对于两种接入模式,请都在门店侧对一次刷卡支付进行一次单独的整体上报,
    +   * 上报URL指定为:https://api.mch.weixin.qq.com/pay/micropay/total,关于两种接入模式具体可参考本文档章节:
    +   * 刷卡支付商户接入模式,其它接口调用仍然按照调用一次,上报一次来进行。
    +   * 
    + */ + @Required + @XStreamAlias("interface_url") + private String interfaceUrl; + /** + *
    +   * 接口耗时
    +   * execute_time
    +   * 是
    +   * Int
    +   * 1000
    +   * 接口耗时情况,单位为毫秒
    +   * 
    + */ + @Required + @XStreamAlias("execute_time_")//估计是官方接口搞错了 + private Integer executeTime; + /** + *
    +   * 返回状态码
    +   * return_code
    +   * 是
    +   * String(16)
    +   * SUCCESS
    +   * SUCCESS/FAIL,此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断
    +   * 
    + */ + @Required + @XStreamAlias("return_code") + private String returnCode; + /** + *
    +   * 返回信息
    +   * return_msg
    +   * 否
    +   * String(128)
    +   * 签名失败
    +   * 返回信息,如非空,为错误原因,签名失败,参数格式校验错误
    +   * 
    + */ + @XStreamAlias("return_msg") + private String returnMsg; + /** + *
    +   * 业务结果
    +   * result_code
    +   * 是
    +   * String(16)
    +   * SUCCESS
    +   * SUCCESS/FAIL
    +   * 
    + */ + @Required + @XStreamAlias("result_code") + private String resultCode; + /** + *
    +   * 错误代码
    +   * err_code
    +   * 否
    +   * String(32)
    +   * SYSTEMERROR
    +   * ORDERNOTEXIST—订单不存在,SYSTEMERROR—系统错误
    +   * 
    + */ + @XStreamAlias("err_code") + private String errCode; + /** + *
    +   * 错误代码描述
    +   * err_code_des
    +   * 否
    +   * String(128)
    +   * 系统错误
    +   * 结果信息描述
    +   * 
    + */ + @XStreamAlias("err_code_des") + private String errCodeDes; + /** + *
    +   * 商户订单号
    +   * out_trade_no
    +   * 否
    +   * String(32)
    +   * 1217752501201407033233368018
    +   * 商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。
    +   * 
    + */ + @XStreamAlias("out_trade_no") + private String outTradeNo; + /** + *
    +   * 访问接口IP
    +   * user_ip
    +   * 是
    +   * String(16)
    +   * 8.8.8.8
    +   * 发起接口调用时的机器IP
    +   * 
    + */ + @Required + @XStreamAlias("user_ip") + private String userIp; + /** + *
    +   * 商户上报时间
    +   * time
    +   * 否
    +   * String(14)
    +   * 20091227091010
    +   * 系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则
    +   * 
    + */ + @XStreamAlias("time") + private String time; + + public String getDeviceInfo() { + return deviceInfo; + } + + public void setDeviceInfo(String deviceInfo) { + this.deviceInfo = deviceInfo; + } + + public String getSignType() { + return signType; + } + + public void setSignType(String signType) { + this.signType = signType; + } + + public String getInterfaceUrl() { + return interfaceUrl; + } + + public void setInterfaceUrl(String interfaceUrl) { + this.interfaceUrl = interfaceUrl; + } + + public Integer getExecuteTime() { + return executeTime; + } + + public void setExecuteTime(Integer executeTime) { + this.executeTime = executeTime; + } + + public String getReturnCode() { + return returnCode; + } + + public void setReturnCode(String returnCode) { + this.returnCode = returnCode; + } + + public String getReturnMsg() { + return returnMsg; + } + + public void setReturnMsg(String returnMsg) { + this.returnMsg = returnMsg; + } + + public String getResultCode() { + return resultCode; + } + + public void setResultCode(String resultCode) { + this.resultCode = resultCode; + } + + public String getErrCode() { + return errCode; + } + + public void setErrCode(String errCode) { + this.errCode = errCode; + } + + public String getErrCodeDes() { + return errCodeDes; + } + + public void setErrCodeDes(String errCodeDes) { + this.errCodeDes = errCodeDes; + } + + public String getOutTradeNo() { + return outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getUserIp() { + return userIp; + } + + public void setUserIp(String userIp) { + this.userIp = userIp; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index 4dd133ab..88334aa7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -24,7 +24,8 @@ import java.util.Map; * @author binarywang(Binary Wang) *
    */ -public abstract class WxPayBaseResult { +@XStreamAlias("xml") +public class WxPayBaseResult { /** * 返回状态码 */ diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 248fc7dd..7e28cb43 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -6,10 +6,7 @@ import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; -import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; -import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; +import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; import org.testng.Assert; import org.testng.annotations.Guice; @@ -35,6 +32,18 @@ public class WxMpPayServiceImplTest { } + @Test + public void testReport() throws Exception { + WxPayReportRequest request = new WxPayReportRequest(); + request.setInterfaceUrl("hahahah"); + request.setSignType("HMAC-SHA256");//貌似接口未校验此字段 + request.setExecuteTime(1000); + request.setReturnCode("aaa"); + request.setResultCode("aaa"); + request.setUserIp("8.8.8"); + this.wxService.getPayService().report(request); + } + /** * 需要证书的接口需要先执行该方法 */ From fc14e7cc7c1bf3553a9326abfdcf6a4b9b753976 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 12:18:58 +0800 Subject: [PATCH 43/76] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c933b0eb..2005bdf2 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Weixin Java Tools —— 微信公众号&企业号开发 Java SDK =========== ## SDK使用交流方式说明: -1. QQ群:343954419(推荐点击按钮入群: [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=731dc3e7ea31ebe25376cc1a791445468612c63fd0e9e05399b088ec81fd9e15) 或 [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://jq.qq.com/?_wv=1027&k=40lRskK),如果无反应,可以自行搜索群号进行添加 ) +1. QQ群:343954419(推荐点击按钮入群: [![Join QQ Group](https://img.shields.io/badge/QQ群-343954419-blue.svg)](http://shang.qq.com/wpa/qunwpa?idkey=731dc3e7ea31ebe25376cc1a791445468612c63fd0e9e05399b088ec81fd9e15) 或 [![Join QQ Group](https://img.shields.io/badge/QQ群-343954419-blue.svg)](http://jq.qq.com/?_wv=1027&k=40lRskK),如果无反应,可以自行搜索群号进行添加 ) 1. 由于群容量有限,即将爆满,故开启付费入群模式以保证只有真实交流需求的人进入,并为保证群的活跃度,将不定期清理长时间不活跃的同学; 1. 微信群: 因微信群已达到100人限制,故如有想加入微信群的,请入QQ群后联系管理员,提供微信号以便邀请加入; 1. 新手提问前,请先阅读此文章:http://t.cn/RV93MRB From 270fff302c2391cbe74f35c4760f413b1554ccd6 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 12:22:46 +0800 Subject: [PATCH 44/76] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2005bdf2..cc427f39 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Weixin Java Tools —— 微信公众号&企业号开发 Java SDK =========== ## SDK使用交流方式说明: -1. QQ群:343954419(推荐点击按钮入群: [![Join QQ Group](https://img.shields.io/badge/QQ群-343954419-blue.svg)](http://shang.qq.com/wpa/qunwpa?idkey=731dc3e7ea31ebe25376cc1a791445468612c63fd0e9e05399b088ec81fd9e15) 或 [![Join QQ Group](https://img.shields.io/badge/QQ群-343954419-blue.svg)](http://jq.qq.com/?_wv=1027&k=40lRskK),如果无反应,可以自行搜索群号进行添加 ) +1. QQ群: [![Join QQ Group](https://img.shields.io/badge/QQ群-343954419-blue.svg)](http://shang.qq.com/wpa/qunwpa?idkey=731dc3e7ea31ebe25376cc1a791445468612c63fd0e9e05399b088ec81fd9e15) 或 [![Join QQ Group](https://img.shields.io/badge/QQ群-343954419-blue.svg)](http://jq.qq.com/?_wv=1027&k=40lRskK),推荐点击按钮入群,当然如果无法成功操作,请自行搜索群号343954419进行添加 ) 1. 由于群容量有限,即将爆满,故开启付费入群模式以保证只有真实交流需求的人进入,并为保证群的活跃度,将不定期清理长时间不活跃的同学; 1. 微信群: 因微信群已达到100人限制,故如有想加入微信群的,请入QQ群后联系管理员,提供微信号以便邀请加入; 1. 新手提问前,请先阅读此文章:http://t.cn/RV93MRB From 245bec709a21f6889bb3743843d6c543c0188b26 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 13:47:36 +0800 Subject: [PATCH 45/76] =?UTF-8?q?=E5=BC=95=E5=85=A5=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BD=BF=E5=BE=97=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E8=83=BD=E5=A4=9F=E6=94=AF=E6=8C=81=E4=BB=BF?= =?UTF-8?q?=E7=9C=9F=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83=20#119?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpConfigStorage.java | 4 ++ .../mp/api/WxMpInMemoryConfigStorage.java | 5 +++ .../mp/api/impl/WxMpPayServiceImpl.java | 37 +++++++++++++------ .../mp/bean/pay/result/WxPayBaseResult.java | 3 +- .../mp/bean/pay/result/WxPayCommonResult.java | 15 ++++++++ .../mp/api/WxXmlMpInMemoryConfigStorage.java | 5 +++ .../mp/api/impl/WxMpPayServiceImplTest.java | 10 +++-- 7 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayCommonResult.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java index cff903bf..79ae9318 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java @@ -144,4 +144,8 @@ public interface WxMpConfigStorage { */ boolean autoRefreshToken(); + /** + * 微信支付是否使用仿真测试环境 + */ + boolean useSandboxForWxPay(); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java index 29fbed63..f2292684 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java @@ -344,4 +344,9 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { public boolean autoRefreshToken() { return true; } + + @Override + public boolean useSandboxForWxPay() { + return false; + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java index a9ef983b..dde6431a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java @@ -52,6 +52,14 @@ public class WxMpPayServiceImpl implements WxMpPayService { return wxMpService.getWxMpConfigStorage(); } + private String getPayBaseUrl(){ + if(this.getConfig().useSandboxForWxPay()){ + return PAY_BASE_URL + "/sandboxnew"; + } + + return PAY_BASE_URL; + } + @Override public WxPayRefundResult refund(WxPayRefundRequest request) throws WxErrorException { this.initRequest(request); @@ -61,7 +69,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { this.checkParameters(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/secapi/pay/refund"; + String url = this.getPayBaseUrl() + "/secapi/pay/refund"; String responseContent = this.executeWithKey(url, request.toXML()); WxPayRefundResult result = WxPayRefundResult.fromXML(responseContent, WxPayRefundResult.class); this.checkResult(result); @@ -83,7 +91,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { request.setRefundId(StringUtils.trimToNull(refundId)); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/pay/refundquery"; + String url = this.getPayBaseUrl() + "/pay/refundquery"; String responseContent = this.executeRequest(url, request.toXML()); WxPayRefundQueryResult result = WxPayRefundQueryResult.fromXML(responseContent, WxPayRefundQueryResult.class); result.composeRefundRecords(); @@ -150,10 +158,10 @@ public class WxMpPayServiceImpl implements WxMpPayService { this.initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/mmpaymkttransfers/sendredpack"; + String url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendredpack"; if (request.getAmtType() != null) { //裂变红包 - url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack"; + url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendgroupredpack"; } String responseContent = this.executeWithKey(url, request.toXML()); WxPaySendRedpackResult result = WxPaySendRedpackResult.fromXML(responseContent, WxPaySendRedpackResult.class); @@ -169,7 +177,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/mmpaymkttransfers/gethbinfo"; + String url = this.getPayBaseUrl() + "/mmpaymkttransfers/gethbinfo"; String responseContent = this.executeWithKey(url, request.toXML()); WxPayRedpackQueryResult result = WxPayRedpackQueryResult.fromXML(responseContent, WxPayRedpackQueryResult.class); this.checkResult(result); @@ -189,7 +197,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/pay/orderquery"; + String url = this.getPayBaseUrl() + "/pay/orderquery"; String responseContent = this.executeRequest(url, request.toXML()); WxPayOrderQueryResult result = WxPayOrderQueryResult.fromXML(responseContent, WxPayOrderQueryResult.class); result.composeCoupons(); @@ -208,7 +216,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/pay/closeorder"; + String url = this.getPayBaseUrl() + "/pay/closeorder"; String responseContent = this.executeRequest(url, request.toXML()); WxPayOrderCloseResult result = WxPayOrderCloseResult.fromXML(responseContent, WxPayOrderCloseResult.class); this.checkResult(result); @@ -230,7 +238,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { checkParameters(request);//校验参数 request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/pay/unifiedorder"; + String url = this.getPayBaseUrl() + "/pay/unifiedorder"; String xmlParam = request.toXML(); log.debug("微信统一下单接口,URL:{},参数:{}", url, xmlParam); @@ -298,7 +306,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { BeanUtils.checkRequiredFields(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/mmpaymkttransfers/promotion/transfers"; + String url = this.getPayBaseUrl() + "/mmpaymkttransfers/promotion/transfers"; String responseContent = this.executeWithKey(url, request.toXML()); WxEntPayResult result = WxEntPayResult.fromXML(responseContent, WxEntPayResult.class); @@ -312,7 +320,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { this.initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/mmpaymkttransfers/gettransferinfo"; + String url = this.getPayBaseUrl() + "/mmpaymkttransfers/gettransferinfo"; String responseContent = this.executeWithKey(url, request.toXML()); WxEntPayQueryResult result = WxEntPayQueryResult.fromXML(responseContent, WxEntPayQueryResult.class); this.checkResult(result); @@ -359,9 +367,9 @@ public class WxMpPayServiceImpl implements WxMpPayService { this.initRequest(request); request.setSign(this.createSign(request)); - String url = PAY_BASE_URL + "/payitil/report"; + String url = this.getPayBaseUrl() + "/payitil/report"; String responseContent = this.wxMpService.post(url, request.toXML()); - WxPayBaseResult result = WxPayBaseResult.fromXML(responseContent, WxPayBaseResult.class); + WxPayCommonResult result = WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class); this.checkResult(result); } @@ -435,6 +443,11 @@ public class WxMpPayServiceImpl implements WxMpPayService { @Override public String createSign(Map params, String signKey) { + if(this.getConfig().useSandboxForWxPay()){ + //使用仿真测试环境 + return "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; + } + SortedMap sortedMap = new TreeMap<>(params); StringBuilder toSign = new StringBuilder(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java index 88334aa7..4dd133ab 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java @@ -24,8 +24,7 @@ import java.util.Map; * @author binarywang(Binary Wang) *
    */ -@XStreamAlias("xml") -public class WxPayBaseResult { +public abstract class WxPayBaseResult { /** * 返回状态码 */ diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayCommonResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayCommonResult.java new file mode 100644 index 00000000..a6e7de5f --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayCommonResult.java @@ -0,0 +1,15 @@ +package me.chanjar.weixin.mp.bean.pay.result; + +import com.thoughtworks.xstream.annotations.XStreamAlias; + +/** + *
    + * 微信支付结果仅包含有return 和result等相关信息的的属性类
    + * Created by Binary Wang on 2017-01-09.
    + * @author binarywang(Binary Wang)
    + * 
    + */ + +@XStreamAlias("xml") +public class WxPayCommonResult extends WxPayBaseResult { +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java index 1ab04cf1..f2a54d49 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java @@ -64,4 +64,9 @@ public class WxXmlMpInMemoryConfigStorage public void setAccessTokenLock(Lock lock){ super.accessTokenLock = lock; } + + @Override + public boolean useSandboxForWxPay() { + return true; + } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 7e28cb43..abdfb63a 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -8,13 +8,14 @@ import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; -import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.nio.file.Files; import java.nio.file.Path; +import static org.testng.Assert.*; + /** * 测试支付相关接口 * Created by Binary Wang on 2016/7/28. @@ -52,6 +53,7 @@ public class WxMpPayServiceImplTest { WxXmlMpInMemoryConfigStorage config = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); config.setSslContextFilePath(config.getKeyPath()); } + /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#refund(WxPayRefundRequest)} . */ @@ -163,8 +165,8 @@ public class WxMpPayServiceImplTest { String qrcodeContent = QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()); System.out.println(qrcodeContent); - Assert.assertTrue(qrcodeContent.startsWith("weixin://wxpay/bizpayurl?")); - Assert.assertTrue(qrcodeContent.contains("product_id=" + productId)); + assertTrue(qrcodeContent.startsWith("weixin://wxpay/bizpayurl?")); + assertTrue(qrcodeContent.contains("product_id=" + productId)); } @Test @@ -174,7 +176,7 @@ public class WxMpPayServiceImplTest { Path qrcodeFilePath = Files.createTempFile("qrcode_", ".jpg"); Files.write(qrcodeFilePath, bytes); - Assert.assertEquals(QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()), qrcodeContent); + assertEquals(QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()), qrcodeContent); } From eeb0452d649096ab1a604c6176a3f27cff47029d Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 13:57:05 +0800 Subject: [PATCH 46/76] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B0=83=E6=95=B4pom?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E5=B0=86jedis=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E7=A7=BB=E5=85=A5cp=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 11 +--- weixin-java-cp/pom.xml | 128 +++++++++++++++++++++-------------------- 2 files changed, 69 insertions(+), 70 deletions(-) diff --git a/pom.xml b/pom.xml index 2092494c..7a3697ce 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"> 4.0.0 com.github.binarywang weixin-java-parent @@ -99,7 +99,6 @@ 4.5 1.7.10 1.1.2 - 2.9.0 2.7 19.0 3.5 @@ -150,12 +149,6 @@ commons-lang3 ${commons-lang3.version} - - redis.clients - jedis - ${jedis.version} - true - com.google.guava guava diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 9b5f3877..79d68308 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -1,68 +1,74 @@ - 4.0.0 - - com.github.binarywang - weixin-java-parent - 2.4.8.BETA - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"> + 4.0.0 + + com.github.binarywang + weixin-java-parent + 2.4.8.BETA + - weixin-java-cp - WeiXin Java Tools - CP - 微信企业号Java SDK + weixin-java-cp + WeiXin Java Tools - CP + 微信企业号Java SDK - - - com.github.binarywang - weixin-java-common - ${project.version} - - - junit - junit - test - - - org.testng - testng - test - - - org.mockito - mockito-all - test - - - com.google.inject - guice - test - - - org.eclipse.jetty - jetty-server - test - - - org.eclipse.jetty - jetty-servlet - test - - + + + com.github.binarywang + weixin-java-common + ${project.version} + + + junit + junit + test + + + org.testng + testng + test + + + org.mockito + mockito-all + test + + + com.google.inject + guice + test + + + org.eclipse.jetty + jetty-server + test + + + org.eclipse.jetty + jetty-servlet + test + + + redis.clients + jedis + 2.9.0 + true + + - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/resources/testng.xml - - - - - + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/resources/testng.xml + + + + + From b1f3b71a091c6def2109853c579aff3190c2510e Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:11:54 +0800 Subject: [PATCH 47/76] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=B8=A6=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E4=BA=8C=E7=BB=B4=E7=A0=81=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=96=87=E6=A1=A3=E6=B3=A8=E9=87=8A=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=8A=A0=E5=85=A5=E5=AF=B9=E6=9C=89=E6=95=88=E6=9C=9F?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpQrcodeService.java | 20 +++++++++---------- .../mp/api/impl/WxMpQrcodeServiceImpl.java | 12 ++++++++++- .../api/impl/WxMpQrCodeServiceImplTest.java | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java index 89371208..ddfd02a5 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java @@ -7,7 +7,7 @@ import java.io.File; /** * 二维码相关操作接口 - * + * 文档地址:https://mp.weixin.qq.com/wiki?action=doc&id=mp1443433542&t=0.9274944716856435 * @author Binary Wang */ public interface WxMpQrcodeService { @@ -15,28 +15,28 @@ public interface WxMpQrcodeService { /** *
        * 换取临时二维码ticket
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * - * @param sceneId 参数。 - * @param expireSeconds 过期秒数,默认60秒,最小60秒,最大1800秒 + * @param sceneId 场景值ID,临时二维码时为32位非0整型 + * @param expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 */ WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException; /** *
        * 换取永久二维码ticket
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * - * @param sceneId 参数。永久二维码时最大值为100000(目前参数只支持1--100000) + * @param sceneId 场景值ID,最大值为100000(目前参数只支持1--100000) */ WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException; /** *
        * 换取永久字符串二维码ticket
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * * @param sceneStr 参数。字符串类型长度现在为1到64 @@ -46,7 +46,7 @@ public interface WxMpQrcodeService { /** *
        * 换取二维码图片文件,jpg格式
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * * @param ticket 二维码ticket @@ -56,7 +56,7 @@ public interface WxMpQrcodeService { /** *
        * 换取二维码图片url地址(可以选择是否生成压缩的网址)
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * * @param ticket 二维码ticket @@ -67,7 +67,7 @@ public interface WxMpQrcodeService { /** *
        * 换取二维码图片url地址
    -   * 详情请见: 生成带参数的二维码
    +   * 详情请见: 生成带参数的二维码
        * 
    * * @param ticket 二维码ticket diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java index 9726b373..5b00720a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java @@ -28,7 +28,17 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService { @Override public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { if (sceneId == 0) { - throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景只不能为0!").build()); + throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景值不能为0!").build()); + } + + //expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 + if (expireSeconds != null && expireSeconds > 2592000) { + throw new WxErrorException(WxError.newBuilder().setErrorCode(-1) + .setErrorMsg("临时二维码有效时间最大不能超过2592000(即30天)!").build()); + } + + if (expireSeconds == null) { + expireSeconds = 30; } String url = API_URL_PREFIX + "/create"; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java index a2ab5328..d1475dfe 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java @@ -19,7 +19,7 @@ import java.io.File; */ @Test(groups = "qrCodeAPI") @Guice(modules = ApiTestModule.class) -public class WxMpQrCodeServiceImplTest { +public class WxMpQrcodeServiceImplTest { @Inject protected WxMpService wxService; From c5bf83c57b9dfc92d4c3f79bed7692652493312f Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:13:20 +0800 Subject: [PATCH 48/76] rename file --- ...QrCodeServiceImplTest.java => WxMpQrcodeServiceImplTest1.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/{WxMpQrCodeServiceImplTest.java => WxMpQrcodeServiceImplTest1.java} (100%) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java similarity index 100% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java From b9908af8fb97ffb13eddb5e8d76e23ebee9c8e7e Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:13:34 +0800 Subject: [PATCH 49/76] rename file --- .../chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java index d1475dfe..c7c6965a 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java @@ -19,7 +19,7 @@ import java.io.File; */ @Test(groups = "qrCodeAPI") @Guice(modules = ApiTestModule.class) -public class WxMpQrcodeServiceImplTest { +public class WxMpQrcodeServiceImplTest1 { @Inject protected WxMpService wxService; From 5d30aa3ada5d8e5f765eb701f4dd2b1f5b542f3b Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:13:59 +0800 Subject: [PATCH 50/76] rename file --- ...QrcodeServiceImplTest1.java => WxMpQrcodeServiceImplTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/{WxMpQrcodeServiceImplTest1.java => WxMpQrcodeServiceImplTest.java} (100%) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java similarity index 100% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest1.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java From ab3b2249a9f6cfe01898305fe37aea71fa48d0b9 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:14:07 +0800 Subject: [PATCH 51/76] rename file --- .../chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java index c7c6965a..d1475dfe 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java @@ -19,7 +19,7 @@ import java.io.File; */ @Test(groups = "qrCodeAPI") @Guice(modules = ApiTestModule.class) -public class WxMpQrcodeServiceImplTest1 { +public class WxMpQrcodeServiceImplTest { @Inject protected WxMpService wxService; From 9e0fcb34d03fbce012eff83ba265cd1196d7d0a8 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 9 Jan 2017 16:14:41 +0800 Subject: [PATCH 52/76] =?UTF-8?q?=E5=BC=95=E5=85=A5=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BD=BF=E5=BE=97=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E8=83=BD=E5=A4=9F=E6=94=AF=E6=8C=81=E4=BB=BF?= =?UTF-8?q?=E7=9C=9F=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83=20#119?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java | 4 +++- .../chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java | 5 ++++- weixin-java-mp/src/test/resources/testng.xml | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java index dde6431a..b4813a33 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java @@ -445,7 +445,9 @@ public class WxMpPayServiceImpl implements WxMpPayService { public String createSign(Map params, String signKey) { if(this.getConfig().useSandboxForWxPay()){ //使用仿真测试环境 - return "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; + //TODO 目前测试发现,以下两行代码都会出问题,所以暂不建议使用这个仿真测试环境 + signKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; + //return "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; } SortedMap sortedMap = new TreeMap<>(params); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index abdfb63a..783bdb86 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -73,7 +73,10 @@ public class WxMpPayServiceImplTest { */ @Test public void testRefundQuery() throws Exception { - WxPayRefundQueryResult result = this.wxService.getPayService().refundQuery("1", "", "", ""); + WxPayRefundQueryResult result; + + result = this.wxService.getPayService().refundQuery("1", "", "", ""); + System.err.println(result); result = this.wxService.getPayService().refundQuery("", "2", "", ""); System.err.println(result); result = this.wxService.getPayService().refundQuery("", "", "3", ""); diff --git a/weixin-java-mp/src/test/resources/testng.xml b/weixin-java-mp/src/test/resources/testng.xml index d1499983..a358cf1c 100644 --- a/weixin-java-mp/src/test/resources/testng.xml +++ b/weixin-java-mp/src/test/resources/testng.xml @@ -7,7 +7,7 @@ - + From 8e831ac96184ecb5d86451f070da1707e63e0d58 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Wed, 11 Jan 2017 17:52:48 +0800 Subject: [PATCH 53/76] =?UTF-8?q?=E7=BE=A4=E5=8F=91=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0isSendAll=E5=B1=9E=E6=80=A7=E5=8F=8A=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=96=B9=E6=B3=95=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=98=BE?= =?UTF-8?q?=E5=BC=8F=E6=8C=87=E5=AE=9A=E6=98=AF=E5=90=A6=E7=BE=A4=E5=8F=91?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E8=87=B3=E6=89=80=E6=9C=89=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/bean/WxMpMassTagMessage.java | 15 +++++++++++++++ .../util/json/WxMpMassTagMessageGsonAdapter.java | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java index 083e5605..bf1ded1a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassTagMessage.java @@ -16,6 +16,7 @@ public class WxMpMassTagMessage implements Serializable { private String msgType; private String content; private String mediaId; + private boolean isSendAll = false; private boolean sendIgnoreReprint = false; public WxMpMassTagMessage() { @@ -88,4 +89,18 @@ public class WxMpMassTagMessage implements Serializable { this.sendIgnoreReprint = sendIgnoreReprint; } + /** + * 是否群发给所有用户 + */ + public boolean isSendAll() { + return isSendAll; + } + + public void setSendAll(boolean sendAll) { + if(sendAll){ + this.tagId = null; + } + + isSendAll = sendAll; + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java index 38e9515f..5b133b0e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassTagMessageGsonAdapter.java @@ -24,7 +24,7 @@ public class WxMpMassTagMessageGsonAdapter implements JsonSerializer Date: Thu, 12 Jan 2017 11:09:24 +0800 Subject: [PATCH 54/76] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=B8=AD=E6=9A=82=E6=97=B6=E5=B1=8F=E8=94=BD=E6=8E=89=E6=B2=99?= =?UTF-8?q?=E7=AE=B1=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java index f2a54d49..e51ffeb6 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java @@ -67,6 +67,8 @@ public class WxXmlMpInMemoryConfigStorage @Override public boolean useSandboxForWxPay() { - return true; + return false; + //沙箱环境不成熟,有问题无法使用,暂时屏蔽掉 + // return true; } } From c8441650d0e27b33f97bb8c8754db2758eb1800b Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 12 Jan 2017 11:09:50 +0800 Subject: [PATCH 55/76] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/bean/pay/result/WxPayUnifiedOrderResult.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayUnifiedOrderResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayUnifiedOrderResult.java index 70c13519..5097cd10 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayUnifiedOrderResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayUnifiedOrderResult.java @@ -13,12 +13,21 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; @XStreamAlias("xml") public class WxPayUnifiedOrderResult extends WxPayBaseResult { + /** + * 微信生成的预支付回话标识,用于后续接口调用中使用,该值有效期为2小时 + */ @XStreamAlias("prepay_id") private String prepayId; + /** + * 交易类型,取值为:JSAPI,NATIVE,APP等 + */ @XStreamAlias("trade_type") private String tradeType; + /** + * trade_type为NATIVE时有返回,用于生成二维码,展示给用户进行扫码支付 + */ @XStreamAlias("code_url") private String codeURL; From a2398ddeb1ee16a87bfb827098289c4bd258474b Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 12 Jan 2017 11:10:42 +0800 Subject: [PATCH 56/76] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/common/util/BeanUtils.java | 94 ++++++++++--------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java index 7c3db11f..630821e9 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java @@ -1,21 +1,20 @@ package me.chanjar.weixin.common.util; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.thoughtworks.xstream.annotations.XStreamAlias; - import me.chanjar.weixin.common.annotation.Required; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; /** *
    @@ -25,25 +24,28 @@ import me.chanjar.weixin.common.exception.WxErrorException;
      * 
    */ public class BeanUtils { - private static Logger log = LoggerFactory.getLogger(BeanUtils.class); + private static Logger log = LoggerFactory.getLogger(BeanUtils.class); /** * 检查bean里标记为@Required的field是否为空,为空则抛异常 + * * @param bean 要检查的bean对象 * @throws WxErrorException */ public static void checkRequiredFields(Object bean) throws WxErrorException { - List nullFields = Lists.newArrayList(); + List requiredFields = Lists.newArrayList(); - List fields = new ArrayList<>( Arrays.asList(bean.getClass().getDeclaredFields())); + List fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields())); fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields())); for (Field field : fields) { try { boolean isAccessible = field.isAccessible(); field.setAccessible(true); - if (field.isAnnotationPresent(Required.class) - && field.get(bean) == null) { - nullFields.add(field.getName()); + if (field.isAnnotationPresent(Required.class)) { + if (field.get(bean) == null || (field.get(bean) instanceof String && StringUtils.isBlank(field.get(bean).toString()))) { + //两种情况,一种是值为null,另外一种情况是类型为字符串,但是字符串内容为空的,都认为是没有提供值 + requiredFields.add(field.getName()); + } } field.setAccessible(isAccessible); } catch (SecurityException | IllegalArgumentException @@ -52,43 +54,43 @@ public class BeanUtils { } } - if (!nullFields.isEmpty()) { - String msg = "必填字段 " + nullFields + " 必须提供值"; + if (!requiredFields.isEmpty()) { + String msg = "必填字段 " + requiredFields + " 必须提供值"; log.debug(msg); throw new WxErrorException(WxError.newBuilder().setErrorMsg(msg).build()); } } - /** - * 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象 - * - * @param bean 包含@XStreamAlias的xml bean对象 - * @return map对象 - */ - public static Map xmlBean2Map(Object bean) { - Map result = Maps.newHashMap(); - List fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields())); - fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields())); - for (Field field : fields) { - try { - boolean isAccessible = field.isAccessible(); - field.setAccessible(true); - if (field.get(bean) == null) { - field.setAccessible(isAccessible); - continue; - } + /** + * 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象 + * + * @param bean 包含@XStreamAlias的xml bean对象 + * @return map对象 + */ + public static Map xmlBean2Map(Object bean) { + Map result = Maps.newHashMap(); + List fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields())); + fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields())); + for (Field field : fields) { + try { + boolean isAccessible = field.isAccessible(); + field.setAccessible(true); + if (field.get(bean) == null) { + field.setAccessible(isAccessible); + continue; + } - if (field.isAnnotationPresent(XStreamAlias.class)) { - result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString()); - } + if (field.isAnnotationPresent(XStreamAlias.class)) { + result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString()); + } - field.setAccessible(isAccessible); - } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - } + field.setAccessible(isAccessible); + } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } - } + } - return result; - } + return result; + } } From e97c15b6cef83216d6798afd24ce6c69ad9a9460 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 12 Jan 2017 11:12:08 +0800 Subject: [PATCH 57/76] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E4=B8=8B=E8=BD=BD=E5=AF=B9=E8=B4=A6=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=BF=98=E6=9C=AA=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E5=BE=85=E8=B0=83=E8=AF=95=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/WxMpPayService.java | 31 ++++- .../mp/api/impl/WxMpPayServiceImpl.java | 34 +++++ .../pay/request/WxPayDownloadBillRequest.java | 123 ++++++++++++++++++ .../mp/api/impl/WxMpPayServiceImplTest.java | 13 +- 4 files changed, 195 insertions(+), 6 deletions(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayDownloadBillRequest.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java index a6dd6654..004cd5bc 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java @@ -240,9 +240,10 @@ public interface WxMpPayService { * 其中XXXXX为商户需要填写的内容,商户将该链接生成二维码,如需要打印发布二维码,需要采用此格式。商户可调用第三方库生成二维码图片。 * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4 *
    - * @param productId 产品Id + * + * @param productId 产品Id * @param sideLength 要生成的二维码的边长,如果为空,则取默认值400 - * @param logoFile 商户logo图片的文件对象,可以为空 + * @param logoFile 商户logo图片的文件对象,可以为空 * @return 生成的二维码的字节数组 */ byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength); @@ -254,8 +255,9 @@ public interface WxMpPayService { * 该模式链接较短,生成的二维码打印到结账小票上的识别率较高。 * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5 *
    - * @param codeUrl 微信返回的交易会话的二维码链接 - * @param logoFile 商户logo图片的文件对象,可以为空 + * + * @param codeUrl 微信返回的交易会话的二维码链接 + * @param logoFile 商户logo图片的文件对象,可以为空 * @param sideLength 要生成的二维码的边长,如果为空,则取默认值400 * @return 生成的二维码的字节数组 */ @@ -273,4 +275,25 @@ public interface WxMpPayService { *
    */ void report(WxPayReportRequest request) throws WxErrorException; + + /** + *
    +   * 下载对账单
    +   * 商户可以通过该接口下载历史交易清单。比如掉单、系统错误等导致商户侧和微信侧数据不一致,通过对账单核对后可校正支付状态。
    +   * 注意:
    +   * 1、微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账单中,跟原支付单订单号一致,bill_type为REVOKED;
    +   * 2、微信在次日9点启动生成前一天的对账单,建议商户10点后再获取;
    +   * 3、对账单中涉及金额的字段单位为“元”。
    +   * 4、对账单接口只能下载三个月以内的账单。
    +   * 接口链接:https://api.mch.weixin.qq.com/pay/downloadbill
    +   * 详情请见: 下载对账单
    +   * 
    + * + * @param billDate 对账单日期 bill_date 下载对账单的日期,格式:20140603 + * @param billType 账单类型 bill_type ALL,返回当日所有订单信息,默认值,SUCCESS,返回当日成功支付的订单,REFUND,返回当日退款订单 + * @param tarType 压缩账单 tar_type 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。 + * @param deviceInfo 设备号 device_info 非必传参数,终端设备号 + * @return 保存到本地的临时文件 + */ + File downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxErrorException; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java index b4813a33..b0ccacd9 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java @@ -41,6 +41,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { private static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com"; private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP"}; private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS", "REFUND_SOURCE_UNSETTLED_FUNDS"}; + private static final String[] BILL_TYPE = new String[]{"ALL","REFUND","SUCCESS"};; private final Logger log = LoggerFactory.getLogger(this.getClass()); private WxMpService wxMpService; @@ -121,6 +122,19 @@ public class WxMpPayServiceImpl implements WxMpPayService { } } + private void checkParameters(WxPayDownloadBillRequest request) throws WxErrorException { + BeanUtils.checkRequiredFields(request); + + if (StringUtils.isNotBlank(request.getTarType()) && !"GZIP".equals(request.getTarType())) { + throw new IllegalArgumentException("tar_type值如果存在,只能为GZIP"); + } + + if ( !ArrayUtils.contains(BILL_TYPE, request.getBillType())) { + throw new IllegalArgumentException("bill_tpye目前必须为" + Arrays.toString(BILL_TYPE) + "其中之一,实际值:" + request.getBillType()); + } + + } + private void checkParameters(WxPayRefundRequest request) throws WxErrorException { BeanUtils.checkRequiredFields(request); @@ -373,6 +387,26 @@ public class WxMpPayServiceImpl implements WxMpPayService { this.checkResult(result); } + @Override + public File downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxErrorException { + WxPayDownloadBillRequest request = new WxPayDownloadBillRequest(); + this.initRequest(request); + request.setBillType(billType); + request.setBillDate(billDate); + request.setTarType(tarType); + request.setDeviceInfo(deviceInfo); + this.checkParameters(request); + request.setSign(this.createSign(request)); + + String url = this.getPayBaseUrl() + "/pay/downloadbill"; + //TODO 返回的内容可能是文件流,也有可能是xml,需要区分对待 + String responseContent = this.wxMpService.post(url, request.toXML()); + + WxPayCommonResult result = WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class); + this.checkResult(result); + return null; + } + private String executeRequest(String url, String requestStr) throws WxErrorException { HttpPost httpPost = new HttpPost(url); if (this.wxMpService.getHttpProxy() != null) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayDownloadBillRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayDownloadBillRequest.java new file mode 100644 index 00000000..9e1ab4dc --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayDownloadBillRequest.java @@ -0,0 +1,123 @@ +package me.chanjar.weixin.mp.bean.pay.request; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import me.chanjar.weixin.common.annotation.Required; + +/** + *
    + *   微信支付下载对账单请求参数类
    + * Created by Binary Wang on 2017-01-11.
    + * @author binarywang(Binary Wang)
    + * 
    + */ +@XStreamAlias("xml") +public class WxPayDownloadBillRequest extends WxPayBaseRequest { + /** + *
    +   * 设备号
    +   * device_info
    +   * 否
    +   * String(32)
    +   * 13467007045764
    +   * 终端设备号
    +   * 
    + */ + @XStreamAlias("device_info") + private String deviceInfo; + + /** + *
    +   * 签名类型
    +   * sign_type
    +   * 否
    +   * String(32)
    +   * HMAC-SHA256
    +   * 签名类型,目前支持HMAC-SHA256和MD5,默认为MD5
    +   * 
    + */ + @XStreamAlias("sign_type") + private String signType; + + /** + *
    +   * 账单类型
    +   * bill_type
    +   * 是
    +   * ALL
    +   * String(8)
    +   * --ALL,返回当日所有订单信息,默认值
    +   * --SUCCESS,返回当日成功支付的订单
    +   * --REFUND,返回当日退款订单
    +   * 
    + */ + @Required + @XStreamAlias("bill_type") + private String billType; + + /** + *
    +   * 对账单日期
    +   * bill_date
    +   * 是
    +   * String(8)
    +   * 20140603
    +   * 下载对账单的日期,格式:20140603
    +   * 
    + */ + @Required + @XStreamAlias("bill_date") + private String billDate; + + /** + *
    +   * 压缩账单
    +   * tar_type
    +   * 否
    +   * String(8)
    +   * GZIP
    +   * 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。
    +   * 
    + */ + @XStreamAlias("tar_type") + private String tarType; + + public String getDeviceInfo() { + return deviceInfo; + } + + public void setDeviceInfo(String deviceInfo) { + this.deviceInfo = deviceInfo; + } + + public String getSignType() { + return signType; + } + + public void setSignType(String signType) { + this.signType = signType; + } + + public String getBillType() { + return billType; + } + + public void setBillType(String billType) { + this.billType = billType; + } + + public String getBillDate() { + return billDate; + } + + public void setBillDate(String billDate) { + this.billDate = billDate; + } + + public String getTarType() { + return tarType; + } + + public void setTarType(String tarType) { + this.tarType = tarType; + } +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index 783bdb86..f46765c7 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -8,9 +8,9 @@ import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; +import java.io.File; import java.nio.file.Files; import java.nio.file.Path; @@ -25,6 +25,7 @@ import static org.testng.Assert.*; @Test @Guice(modules = ApiTestModule.class) public class WxMpPayServiceImplTest { + @Inject protected WxMpService wxService; @@ -33,6 +34,14 @@ public class WxMpPayServiceImplTest { } + @Test + public void testDownloadBill() throws Exception { + File file = this.wxService.getPayService().downloadBill("20170101","ALL","GZIP","1111111"); + assertNotNull(file); + //必填字段为空时,抛出异常 + this.wxService.getPayService().downloadBill("","","",null); + } + @Test public void testReport() throws Exception { WxPayReportRequest request = new WxPayReportRequest(); From 69aaa74eefb282a4b3ee725d70792e6ccec16d03 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 16 Jan 2017 18:12:08 +0800 Subject: [PATCH 58/76] =?UTF-8?q?=E4=BF=AE=E5=A4=8DmenuTryMatch=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E8=AF=B7=E6=B1=82=E6=96=B9=E5=BC=8F=E7=94=B1?= =?UTF-8?q?get=E5=8F=98=E6=9B=B4=E4=B8=BApost=EF=BC=8C#125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java | 5 ++++- .../chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java index 579d5c72..e05b6a80 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.api.impl; +import com.google.gson.JsonObject; import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.WxMpMenuService; @@ -68,8 +69,10 @@ public class WxMpMenuServiceImpl implements WxMpMenuService { @Override public WxMenu menuTryMatch(String userid) throws WxErrorException { String url = API_URL_PREFIX + "/trymatch"; + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("user_id",userid); try { - String resultContent = this.wxMpService.get(url, "user_id=" + userid); + String resultContent = this.wxMpService.post(url, jsonObject.toString()); return WxMenu.fromJson(resultContent); } catch (WxErrorException e) { // 46003 不存在的菜单数据 46002 不存在的菜单版本 diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java index a312b15d..52685920 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java @@ -34,7 +34,8 @@ public class WxMpMenuServiceImplTest { @Test public void testMenuTryMatch() throws Exception { - //TODO + WxMenu menu = this.wxService.getMenuService().menuTryMatch("..."); + System.out.println(menu); } @Test From 41d596654c3918bafb1ff6b181d2970e9b6c5fe9 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 17 Jan 2017 12:11:15 +0800 Subject: [PATCH 59/76] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E4=B8=AA=E6=80=A7=E5=8C=96=E8=8F=9C=E5=8D=95=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20#127?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chanjar/weixin/mp/api/WxMpMenuService.java | 8 ++++---- .../weixin/mp/api/impl/WxMpMenuServiceImpl.java | 10 ++++++---- .../weixin/mp/api/impl/WxMpMenuServiceImplTest.java | 6 ++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java index 94359025..47ec17ec 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java @@ -24,7 +24,7 @@ public interface WxMpMenuService { /** *
        * 自定义菜单删除接口
    -   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口
    +   * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141015&token=&lang=zh_CN
        * 
    */ void menuDelete() throws WxErrorException; @@ -32,12 +32,12 @@ public interface WxMpMenuService { /** *
        * 删除个性化菜单接口
    -   * 详情请见: http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html
    +   * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455782296&token=&lang=zh_CN
        * 
    * - * @param menuid + * @param menuId 个性化菜单的menuid */ - void menuDelete(String menuid) throws WxErrorException; + void menuDelete(String menuId) throws WxErrorException; /** *
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    index e05b6a80..866e4c10 100644
    --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    @@ -45,10 +45,12 @@ public class WxMpMenuServiceImpl implements WxMpMenuService {
       }
     
       @Override
    -  public void menuDelete(String menuid) throws WxErrorException {
    +  public void menuDelete(String menuId) throws WxErrorException {
         String url = API_URL_PREFIX + "/delconditional";
    -    String result = this.wxMpService.get(url, "menuid=" + menuid);
    -    log.debug("根据MeunId({})删除菜单结果:{}", menuid, result);
    +    JsonObject jsonObject = new JsonObject();
    +    jsonObject.addProperty("menuid", menuId);
    +    String result = this.wxMpService.post(url, jsonObject.toString());
    +    log.debug("根据MeunId({})删除菜单结果:{}", menuId, result);
       }
     
       @Override
    @@ -70,7 +72,7 @@ public class WxMpMenuServiceImpl implements WxMpMenuService {
       public WxMenu menuTryMatch(String userid) throws WxErrorException {
         String url = API_URL_PREFIX + "/trymatch";
         JsonObject jsonObject = new JsonObject();
    -    jsonObject.addProperty("user_id",userid);
    +    jsonObject.addProperty("user_id", userid);
         try {
           String resultContent = this.wxMpService.post(url, jsonObject.toString());
           return WxMenu.fromJson(resultContent);
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    index 52685920..1452c056 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    @@ -100,6 +100,12 @@ public class WxMpMenuServiceImplTest {
         this.wxService.getMenuService().menuDelete();
       }
     
    +  @Test
    +  public void testDeleteConditionalMenu() throws WxErrorException {
    +    String menuId = "123";
    +    this.wxService.getMenuService().menuDelete(menuId);
    +  }
    +
       @DataProvider(name="menu")
       public Object[][] getMenu() {
         WxMenu menu = new WxMenu();
    
    From d81a5e39c15dbecc834d4d44c95293c8ad97dc31 Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Tue, 17 Jan 2017 13:57:56 +0800
    Subject: [PATCH 60/76] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     .../chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java  | 7 +++----
     1 file changed, 3 insertions(+), 4 deletions(-)
    
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
    index 5b00720a..26d86baa 100644
    --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImpl.java
    @@ -3,7 +3,6 @@ package me.chanjar.weixin.mp.api.impl;
     import com.google.gson.JsonObject;
     import me.chanjar.weixin.common.bean.result.WxError;
     import me.chanjar.weixin.common.exception.WxErrorException;
    -import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
     import me.chanjar.weixin.mp.api.WxMpQrcodeService;
     import me.chanjar.weixin.mp.api.WxMpService;
     import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
    @@ -52,7 +51,7 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService {
         scene.addProperty("scene_id", sceneId);
         actionInfo.add("scene", scene);
         json.add("action_info", actionInfo);
    -    String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
    +    String responseContent = this.wxMpService.post(url, json.toString());
         return WxMpQrCodeTicket.fromJson(responseContent);
       }
     
    @@ -70,7 +69,7 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService {
         scene.addProperty("scene_id", sceneId);
         actionInfo.add("scene", scene);
         json.add("action_info", actionInfo);
    -    String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
    +    String responseContent = this.wxMpService.post(url, json.toString());
         return WxMpQrCodeTicket.fromJson(responseContent);
       }
     
    @@ -84,7 +83,7 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService {
         scene.addProperty("scene_str", sceneStr);
         actionInfo.add("scene", scene);
         json.add("action_info", actionInfo);
    -    String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
    +    String responseContent = this.wxMpService.post(url, json.toString());
         return WxMpQrCodeTicket.fromJson(responseContent);
       }
     
    
    From 5018c31e60996a5c44ebf4010d1771198f6d5c3e Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Tue, 17 Jan 2017 14:45:42 +0800
    Subject: [PATCH 61/76] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=8C=E5=96=84?=
     =?UTF-8?q?=E8=8F=9C=E5=8D=95=E7=89=B9=E5=88=AB=E6=98=AF=E4=B8=AA=E6=80=A7?=
     =?UTF-8?q?=E5=8C=96=E8=8F=9C=E5=8D=95=E7=9A=84=E5=88=9B=E5=BB=BA=E5=92=8C?=
     =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     .../common/util/json/WxMenuGsonAdapter.java   |  29 ++--
     .../weixin/mp/api/WxMpMenuService.java        |  18 ++-
     .../mp/api/impl/WxMpMenuServiceImpl.java      |  30 +++-
     .../mp/api/impl/WxMpMenuServiceImplTest.java  | 149 +++++++++++-------
     4 files changed, 153 insertions(+), 73 deletions(-)
    
    diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    index 2cfbe252..eaaeec74 100644
    --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    @@ -8,21 +8,13 @@
      */
     package me.chanjar.weixin.common.util.json;
     
    -import java.lang.reflect.Type;
    -
    -import com.google.gson.JsonArray;
    -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 com.google.gson.JsonSerializationContext;
    -import com.google.gson.JsonSerializer;
    -
    +import com.google.gson.*;
     import me.chanjar.weixin.common.bean.menu.WxMenu;
     import me.chanjar.weixin.common.bean.menu.WxMenuButton;
     import me.chanjar.weixin.common.bean.menu.WxMenuRule;
     
    +import java.lang.reflect.Type;
    +
     
     /**
      * @author Daniel Qian
    @@ -76,6 +68,18 @@ public class WxMenuGsonAdapter implements JsonSerializer, JsonDeserializ
         return matchRule;
       }
     
    +  private WxMenuRule convertToRule(JsonObject json) {
    +    WxMenuRule menuRule = new WxMenuRule();
    +    menuRule.setTagId(GsonHelper.getString(json,"tag_id"));
    +    menuRule.setSex(GsonHelper.getString(json,"sex"));
    +    menuRule.setCountry(GsonHelper.getString(json,"country"));
    +    menuRule.setProvince(GsonHelper.getString(json,"province"));
    +    menuRule.setCity(GsonHelper.getString(json,"city"));
    +    menuRule.setClientPlatformType(GsonHelper.getString(json,"client_platform_type"));
    +    menuRule.setLanguage(GsonHelper.getString(json,"language"));
    +    return menuRule;
    +  }
    +
       @Override
       public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
         /*
    @@ -84,8 +88,7 @@ public class WxMenuGsonAdapter implements JsonSerializer, JsonDeserializ
          * 查询菜单时是 { menu : { button : ... } }
          */
         WxMenu menu = new WxMenu();
    -    JsonObject menuJson = json.getAsJsonObject().get("menu").getAsJsonObject();
    -    JsonArray buttonsJson = menuJson.get("button").getAsJsonArray();
    +    JsonArray buttonsJson = json.getAsJsonObject().get("menu").getAsJsonObject().get("button").getAsJsonArray();
         for (int i = 0; i < buttonsJson.size(); i++) {
           JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject();
           WxMenuButton button = convertFromJson(buttonJson);
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    index 47ec17ec..73660d3f 100644
    --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    @@ -14,12 +14,24 @@ public interface WxMpMenuService {
       /**
        * 
        * 自定义菜单创建接口
    -   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口
    +   * 详情请见:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013&token=&lang=zh_CN
        * 如果要创建个性化菜单,请设置matchrule属性
    -   * 详情请见:http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html
    +   * 详情请见:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455782296&token=&lang=zh_CN
        * 
    + * @return 如果是个性化菜单,则返回menuid,否则返回null */ - void menuCreate(WxMenu menu) throws WxErrorException; + String menuCreate(WxMenu menu) throws WxErrorException; + + /** + *
    +   * 自定义菜单创建接口
    +   * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013&token=&lang=zh_CN
    +   * 如果要创建个性化菜单,请设置matchrule属性
    +   * 详情请见:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455782296&token=&lang=zh_CN
    +   * 
    + * @return 如果是个性化菜单,则返回menuid,否则返回null + */ + String menuCreate(String json) throws WxErrorException; /** *
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    index 866e4c10..20590e5a 100644
    --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    @@ -1,6 +1,7 @@
     package me.chanjar.weixin.mp.api.impl;
     
     import com.google.gson.JsonObject;
    +import com.google.gson.JsonParser;
     import me.chanjar.weixin.common.bean.menu.WxMenu;
     import me.chanjar.weixin.common.exception.WxErrorException;
     import me.chanjar.weixin.mp.api.WxMpMenuService;
    @@ -24,7 +25,7 @@ public class WxMpMenuServiceImpl implements WxMpMenuService {
       }
     
       @Override
    -  public void menuCreate(WxMenu menu) throws WxErrorException {
    +  public String menuCreate(WxMenu menu) throws WxErrorException {
         String menuJson = menu.toJson();
         String url = API_URL_PREFIX + "/create";
         if (menu.getMatchRule() != null) {
    @@ -35,6 +36,29 @@ public class WxMpMenuServiceImpl implements WxMpMenuService {
     
         String result = this.wxMpService.post(url, menuJson);
         log.debug("创建菜单:{},结果:{}", menuJson, result);
    +
    +    if (menu.getMatchRule() != null) {
    +      return new JsonParser().parse(result).getAsJsonObject().get("menuid").getAsString();
    +    }
    +
    +    return null;
    +  }
    +
    +  @Override
    +  public String menuCreate(String json) throws WxErrorException {
    +    JsonParser jsonParser = new JsonParser();
    +    JsonObject jsonObject = jsonParser.parse(json).getAsJsonObject();
    +    String url = API_URL_PREFIX + "/create";
    +    if (jsonObject.get("matchrule") != null) {
    +      url = API_URL_PREFIX + "/addconditional";
    +    }
    +
    +    String result = this.wxMpService.post(url, json);
    +    if (jsonObject.get("matchrule") != null) {
    +      return jsonParser.parse(result).getAsJsonObject().get("menuid").getAsString();
    +    }
    +
    +    return null;
       }
     
       @Override
    @@ -50,7 +74,7 @@ public class WxMpMenuServiceImpl implements WxMpMenuService {
         JsonObject jsonObject = new JsonObject();
         jsonObject.addProperty("menuid", menuId);
         String result = this.wxMpService.post(url, jsonObject.toString());
    -    log.debug("根据MeunId({})删除菜单结果:{}", menuId, result);
    +    log.debug("根据MeunId({})删除个性化菜单结果:{}", menuId, result);
       }
     
       @Override
    @@ -77,7 +101,7 @@ public class WxMpMenuServiceImpl implements WxMpMenuService {
           String resultContent = this.wxMpService.post(url, jsonObject.toString());
           return WxMenu.fromJson(resultContent);
         } catch (WxErrorException e) {
    -      // 46003 不存在的菜单数据     46002 不存在的菜单版本
    +      // 46003 不存在的菜单数据;46002 不存在的菜单版本
           if (e.getError().getErrorCode() == 46003
             || e.getError().getErrorCode() == 46002) {
             return null;
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    index 1452c056..04e1b3e6 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
    @@ -8,23 +8,22 @@ import me.chanjar.weixin.common.exception.WxErrorException;
     import me.chanjar.weixin.mp.api.ApiTestModule;
     import me.chanjar.weixin.mp.api.WxMpService;
     import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
    -import org.testng.Assert;
    -import org.testng.annotations.DataProvider;
    -import org.testng.annotations.Guice;
    -import org.testng.annotations.Test;
    +import org.testng.*;
    +import org.testng.annotations.*;
     
     /**
      * 测试菜单
    + *
      * @author chanjarster
      * @author Binary Wang
    - *
      */
    -@Test(groups="menuAPI")
    +@Test(groups = "menuAPI")
     @Guice(modules = ApiTestModule.class)
     public class WxMpMenuServiceImplTest {
     
       @Inject
       protected WxMpService wxService;
    +  private String menuId = null;
     
       @Test(dataProvider = "menu")
       public void testMenuCreate(WxMenu wxMenu) throws WxErrorException {
    @@ -44,69 +43,111 @@ public class WxMpMenuServiceImplTest {
         System.out.println(selfMenuInfo);
       }
     
    +  @Test
    +  public void testCreateConditionalMenu() throws WxErrorException {
    +    String json = "{\n" +
    +      " 	\"button\":[\n" +
    +      " 	{	\n" +
    +      "    	\"type\":\"click\",\n" +
    +      "    	\"name\":\"今日歌曲\",\n" +
    +      "     	\"key\":\"V1001_TODAY_MUSIC\" \n" +
    +      "	},\n" +
    +      "	{ \n" +
    +      "		\"name\":\"菜单\",\n" +
    +      "		\"sub_button\":[\n" +
    +      "		{	\n" +
    +      "			\"type\":\"view\",\n" +
    +      "			\"name\":\"搜索\",\n" +
    +      "			\"url\":\"http://www.soso.com/\"\n" +
    +      "		},\n" +
    +      "		{\n" +
    +      "			\"type\":\"view\",\n" +
    +      "			\"name\":\"视频\",\n" +
    +      "			\"url\":\"http://v.qq.com/\"\n" +
    +      "		},\n" +
    +      "		{\n" +
    +      "			\"type\":\"click\",\n" +
    +      "			\"name\":\"赞一下我们\",\n" +
    +      "			\"key\":\"V1001_GOOD\"\n" +
    +      "		}]\n" +
    +      " }],\n" +
    +      "\"matchrule\":{\n" +
    +      "  \"tag_id\":\"2\",\n" +
    +      "  \"sex\":\"1\",\n" +
    +      "  \"country\":\"中国\",\n" +
    +      "  \"province\":\"广东\",\n" +
    +      "  \"city\":\"广州\",\n" +
    +      "  \"client_platform_type\":\"2\",\n" +
    +      "  \"language\":\"zh_CN\"\n" +
    +      "  }\n" +
    +      "}";
    +
    +    this.menuId = this.wxService.getMenuService().menuCreate(json);
    +    System.out.println(this.menuId);
    +  }
    +
    +  @Test(dependsOnMethods = {"testCreateConditionalMenu"})
    +  public void testDeleteConditionalMenu() throws WxErrorException {
    +    this.wxService.getMenuService().menuDelete(menuId);
    +  }
    +
       @Test
       public void testCreateMenu2() throws WxErrorException {
         String a = "{\n"
    -        + "  \"menu\": {\n"
    -        + "    \"button\": [\n"
    -        + "      {\n"
    -        + "        \"type\": \"click\",\n"
    -        + "        \"name\": \"今日歌曲\",\n"
    -        + "        \"key\": \"V1001_TODAY_MUSIC\"\n"
    -        + "      },\n"
    -        + "      {\n"
    -        + "        \"type\": \"click\",\n"
    -        + "        \"name\": \"歌手简介\",\n"
    -        + "        \"key\": \"V1001_TODAY_SINGER\"\n"
    -        + "      },\n"
    -        + "      {\n"
    -        + "        \"name\": \"菜单\",\n"
    -        + "        \"sub_button\": [\n"
    -        + "          {\n"
    -        + "            \"type\": \"view\",\n"
    -        + "            \"name\": \"搜索\",\n"
    -        + "            \"url\": \"http://www.soso.com/\"\n"
    -        + "          },\n"
    -        + "          {\n"
    -        + "            \"type\": \"view\",\n"
    -        + "            \"name\": \"视频\",\n"
    -        + "            \"url\": \"http://v.qq.com/\"\n"
    -        + "          },\n"
    -        + "          {\n"
    -        + "            \"type\": \"click\",\n"
    -        + "            \"name\": \"赞一下我们\",\n"
    -        + "            \"key\": \"V1001_GOOD\"\n"
    -        + "          }\n"
    -        + "        ]\n"
    -        + "      }\n"
    -        + "    ]\n"
    -        + "  }\n"
    -        + "}";
    +      + "  \"menu\": {\n"
    +      + "    \"button\": [\n"
    +      + "      {\n"
    +      + "        \"type\": \"click\",\n"
    +      + "        \"name\": \"今日歌曲\",\n"
    +      + "        \"key\": \"V1001_TODAY_MUSIC\"\n"
    +      + "      },\n"
    +      + "      {\n"
    +      + "        \"type\": \"click\",\n"
    +      + "        \"name\": \"歌手简介\",\n"
    +      + "        \"key\": \"V1001_TODAY_SINGER\"\n"
    +      + "      },\n"
    +      + "      {\n"
    +      + "        \"name\": \"菜单\",\n"
    +      + "        \"sub_button\": [\n"
    +      + "          {\n"
    +      + "            \"type\": \"view\",\n"
    +      + "            \"name\": \"搜索\",\n"
    +      + "            \"url\": \"http://www.soso.com/\"\n"
    +      + "          },\n"
    +      + "          {\n"
    +      + "            \"type\": \"view\",\n"
    +      + "            \"name\": \"视频\",\n"
    +      + "            \"url\": \"http://v.qq.com/\"\n"
    +      + "          },\n"
    +      + "          {\n"
    +      + "            \"type\": \"click\",\n"
    +      + "            \"name\": \"赞一下我们\",\n"
    +      + "            \"key\": \"V1001_GOOD\"\n"
    +      + "          }\n"
    +      + "        ]\n"
    +      + "      }\n"
    +      + "    ]\n"
    +      + "  }\n"
    +      + "}";
     
         WxMenu menu = WxMenu.fromJson(a);
         System.out.println(menu.toJson());
         this.wxService.getMenuService().menuCreate(menu);
       }
     
    -  @Test(dependsOnMethods = { "testMenuCreate"})
    +  @Test(dependsOnMethods = {"testMenuCreate"})
       public void testMenuGet() throws WxErrorException {
         WxMenu wxMenu = this.wxService.getMenuService().menuGet();
         Assert.assertNotNull(wxMenu);
         System.out.println(wxMenu.toJson());
       }
     
    -  @Test(dependsOnMethods = { "testMenuGet"})
    +  @Test(dependsOnMethods = {"testMenuGet"})
       public void testMenuDelete() throws WxErrorException {
         this.wxService.getMenuService().menuDelete();
       }
     
    -  @Test
    -  public void testDeleteConditionalMenu() throws WxErrorException {
    -    String menuId = "123";
    -    this.wxService.getMenuService().menuDelete(menuId);
    -  }
    -
    -  @DataProvider(name="menu")
    +  @DataProvider(name = "menu")
       public Object[][] getMenu() {
         WxMenu menu = new WxMenu();
         WxMenuButton button1 = new WxMenuButton();
    @@ -145,10 +186,10 @@ public class WxMpMenuServiceImplTest {
         button3.getSubButtons().add(button32);
         button3.getSubButtons().add(button33);
     
    -    return new Object[][] {
    -        new Object[] {
    -            menu
    -        }
    +    return new Object[][]{
    +      new Object[]{
    +        menu
    +      }
         };
     
       }
    
    From 39c7f7cd9f502091d0c5b23af5cb941dec5bb744 Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Tue, 17 Jan 2017 15:15:21 +0800
    Subject: [PATCH 62/76] =?UTF-8?q?=E6=94=B9=E9=80=A0=E6=9F=A5=E8=AF=A2?=
     =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=8E=A5=E5=8F=A3=EF=BC=8C=E4=BB=A5=E6=94=AF?=
     =?UTF-8?q?=E6=8C=81=E4=B8=AA=E6=80=A7=E5=8C=96=E8=8F=9C=E5=8D=95=E7=9A=84?=
     =?UTF-8?q?conditionalmenu=E5=92=8Cmenuid=E5=B1=9E=E6=80=A7=EF=BC=8C=20#12?=
     =?UTF-8?q?6?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     .../weixin/mp/api/WxMpMenuService.java        |  5 +-
     .../mp/api/impl/WxMpMenuServiceImpl.java      |  5 +-
     .../chanjar/weixin/mp/bean/menu/WxMpMenu.java | 92 +++++++++++++++++++
     .../mp/api/impl/WxMpMenuServiceImplTest.java  |  3 +-
     4 files changed, 100 insertions(+), 5 deletions(-)
     create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java
    
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    index 73660d3f..f1c9fd47 100644
    --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMenuService.java
    @@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api;
     import me.chanjar.weixin.common.bean.menu.WxMenu;
     import me.chanjar.weixin.common.exception.WxErrorException;
     import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
    +import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
     
     /**
      * 菜单相关操作接口
    @@ -54,10 +55,10 @@ public interface WxMpMenuService {
       /**
        * 
        * 自定义菜单查询接口
    -   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口
    +   * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141014&token=&lang=zh_CN
        * 
    */ - WxMenu menuGet() throws WxErrorException; + WxMpMenu menuGet() throws WxErrorException; /** *
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    index 20590e5a..b28ac6a1 100644
    --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    @@ -7,6 +7,7 @@ import me.chanjar.weixin.common.exception.WxErrorException;
     import me.chanjar.weixin.mp.api.WxMpMenuService;
     import me.chanjar.weixin.mp.api.WxMpService;
     import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
    +import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
     
    @@ -78,11 +79,11 @@ public class WxMpMenuServiceImpl implements WxMpMenuService {
       }
     
       @Override
    -  public WxMenu menuGet() throws WxErrorException {
    +  public WxMpMenu menuGet() throws WxErrorException {
         String url = API_URL_PREFIX + "/get";
         try {
           String resultContent = this.wxMpService.get(url, null);
    -      return WxMenu.fromJson(resultContent);
    +      return WxMpMenu.fromJson(resultContent);
         } catch (WxErrorException e) {
           // 46003 不存在的菜单数据
           if (e.getError().getErrorCode() == 46003) {
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java
    new file mode 100644
    index 00000000..366ca2f1
    --- /dev/null
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/menu/WxMpMenu.java
    @@ -0,0 +1,92 @@
    +package me.chanjar.weixin.mp.bean.menu;
    +
    +import com.google.gson.annotations.SerializedName;
    +import me.chanjar.weixin.common.bean.menu.WxMenuButton;
    +import me.chanjar.weixin.common.bean.menu.WxMenuRule;
    +import me.chanjar.weixin.common.util.ToStringUtils;
    +import me.chanjar.weixin.common.util.json.WxGsonBuilder;
    +
    +import java.util.List;
    +
    +/**
    + * 
    + *   公众号专用的菜单类,可能包含个性化菜单
    + * Created by Binary Wang on 2017-1-17.
    + * @author binarywang(Binary Wang)
    + * 
    + */ +public class WxMpMenu { + @SerializedName("menu") + private WxMpConditionalMenu menu; + + @SerializedName("conditionalmenu") + private List conditionalMenu; + + public static WxMpMenu fromJson(String json) { + return WxGsonBuilder.create().fromJson(json, WxMpMenu.class); + } + + public WxMpConditionalMenu getMenu() { + return menu; + } + + public void setMenu(WxMpConditionalMenu menu) { + this.menu = menu; + } + + public List getConditionalMenu() { + return conditionalMenu; + } + + public void setConditionalMenu(List conditionalMenu) { + this.conditionalMenu = conditionalMenu; + } + + @Override + public String toString() { + return ToStringUtils.toSimpleString(this); + } + + public String toJson() { + return WxGsonBuilder.create().toJson(this); + } + + public static class WxMpConditionalMenu { + @SerializedName("button") + private List buttons; + @SerializedName("matchrule") + private WxMenuRule rule; + @SerializedName("menuid") + private String menuId; + + @Override + public String toString() { + return ToStringUtils.toSimpleString(this); + } + + public List getButtons() { + return buttons; + } + + public void setButtons(List buttons) { + this.buttons = buttons; + } + + public WxMenuRule getRule() { + return rule; + } + + public void setRule(WxMenuRule rule) { + this.rule = rule; + } + + public String getMenuId() { + return menuId; + } + + public void setMenuId(String menuId) { + this.menuId = menuId; + } + } + +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java index 04e1b3e6..08980a2b 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java @@ -8,6 +8,7 @@ import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; +import me.chanjar.weixin.mp.bean.menu.WxMpMenu; import org.testng.*; import org.testng.annotations.*; @@ -137,7 +138,7 @@ public class WxMpMenuServiceImplTest { @Test(dependsOnMethods = {"testMenuCreate"}) public void testMenuGet() throws WxErrorException { - WxMenu wxMenu = this.wxService.getMenuService().menuGet(); + WxMpMenu wxMenu = this.wxService.getMenuService().menuGet(); Assert.assertNotNull(wxMenu); System.out.println(wxMenu.toJson()); } From 3a87bdaaefc258c362a2730c019959cdc35ced16 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 17 Jan 2017 15:50:45 +0800 Subject: [PATCH 63/76] release 2.4.9.BETA --- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- weixin-java-osgi/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 7a3697ce..a0dfd704 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.4.8.BETA + 2.4.9.BETA pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 26fdff4a..a635fca9 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.8.BETA + 2.4.9.BETA weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 79d68308..26175c9c 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.8.BETA + 2.4.9.BETA weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 197e54c2..d595950e 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.8.BETA + 2.4.9.BETA weixin-java-mp WeiXin Java Tools - MP diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml index 5d749f8f..19cc0bb7 100644 --- a/weixin-java-osgi/pom.xml +++ b/weixin-java-osgi/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.4.8.BETA + 2.4.9.BETA weixin-java-osgi From 1f110dc984185ebaf2f5750fa143ca1b87a191e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=8C=E4=BA=91?= Date: Sun, 22 Jan 2017 11:24:35 +0800 Subject: [PATCH 64/76] =?UTF-8?q?=E4=BF=AE=E6=94=B9WxJsapiSignature?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/common/bean/WxJsapiSignature.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java index 17799058..78371583 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java @@ -8,9 +8,9 @@ import java.io.Serializable; public class WxJsapiSignature implements Serializable { private static final long serialVersionUID = -1116808193154384804L; - private String appid; + private String appId; - private String noncestr; + private String nonceStr; private long timestamp; @@ -26,12 +26,12 @@ public class WxJsapiSignature implements Serializable { this.signature = signature; } - public String getNoncestr() { - return this.noncestr; + public String getNonceStr() { + return nonceStr; } - public void setNoncestr(String noncestr) { - this.noncestr = noncestr; + public void setNonceStr(String nonceStr) { + this.nonceStr = nonceStr; } public long getTimestamp() { @@ -50,12 +50,11 @@ public class WxJsapiSignature implements Serializable { this.url = url; } - public String getAppid() { - return this.appid; + public String getAppId() { + return appId; } - public void setAppid(String appid) { - this.appid = appid; + public void setAppId(String appId) { + this.appId = appId; } - } From 89a92c245297500d64ebb66357a2383f3cfe32db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=8C=E4=BA=91?= Date: Sun, 22 Jan 2017 11:28:32 +0800 Subject: [PATCH 65/76] =?UTF-8?q?=E4=BF=AE=E6=94=B9WxJsapiSignature?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1,=E5=B1=9E=E6=80=A7=E5=90=8D=E5=AD=97?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E5=86=99=E4=B8=8E=E5=BE=AE=E4=BF=A1=E4=B8=80?= =?UTF-8?q?=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java | 4 ++-- .../java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java | 4 ++-- 2 files changed, 4 insertions(+), 4 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 8d0c47da..a10eb42e 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 @@ -166,12 +166,12 @@ public class WxCpServiceImpl implements WxCpService { ); WxJsapiSignature jsapiSignature = new WxJsapiSignature(); jsapiSignature.setTimestamp(timestamp); - jsapiSignature.setNoncestr(noncestr); + jsapiSignature.setNonceStr(noncestr); jsapiSignature.setUrl(url); jsapiSignature.setSignature(signature); // Fixed bug - jsapiSignature.setAppid(this.configStorage.getCorpId()); + jsapiSignature.setAppId(this.configStorage.getCorpId()); return jsapiSignature; } 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 2d250035..eb1e58aa 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 @@ -151,9 +151,9 @@ 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.wxMpConfigStorage.getAppId()); jsapiSignature.setTimestamp(timestamp); - jsapiSignature.setNoncestr(noncestr); + jsapiSignature.setNonceStr(noncestr); jsapiSignature.setUrl(url); jsapiSignature.setSignature(signature); return jsapiSignature; From 123eb5088d06292435d157f3f18b44e26f095c12 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 23 Jan 2017 16:48:00 +0800 Subject: [PATCH 66/76] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E5=8C=85=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/mp/api/WxMpBaseAPITest.java | 1 + .../chanjar/weixin/mp/api/WxMpJsAPITest.java | 1 + .../weixin/mp/api/WxMpMassMessageAPITest.java | 18 +++++++++--------- .../chanjar/weixin/mp/api/WxMpMiscAPITest.java | 1 + .../weixin/mp/api/WxMpShortUrlAPITest.java | 1 + .../mp/api/impl/WxMpCardServiceImplTest.java | 2 +- .../api/impl/WxMpDataCubeServiceImplTest.java | 2 +- .../mp/api/impl/WxMpDeviceServiceImplTest.java | 2 +- .../mp/api/impl/WxMpKefuServiceImplTest.java | 14 +++++++------- .../api/impl/WxMpMaterialServiceImplTest.java | 2 +- .../mp/api/impl/WxMpMenuServiceImplTest.java | 2 +- .../mp/api/impl/WxMpPayServiceImplTest.java | 8 ++++---- .../mp/api/impl/WxMpQrcodeServiceImplTest.java | 2 +- .../mp/api/impl/WxMpServiceImplTest.java | 6 +++--- .../mp/api/impl/WxMpStoreServiceImplTest.java | 2 +- .../impl/WxMpTemplateMsgServiceImplTest.java | 6 +++--- .../impl/WxMpUserBlacklistServiceImplTest.java | 10 +++++----- .../mp/api/impl/WxMpUserServiceImplTest.java | 8 ++++---- .../api/impl/WxMpUserTagServiceImplTest.java | 10 +++++----- .../mp/api/{ => test}/ApiTestModule.java | 11 ++++++----- .../TestConfigStorage.java} | 11 +++++------ 21 files changed, 62 insertions(+), 58 deletions(-) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/{ => test}/ApiTestModule.java (77%) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/{WxXmlMpInMemoryConfigStorage.java => test/TestConfigStorage.java} (87%) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java index b6904eb1..c3b53d66 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java @@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.apache.commons.lang3.StringUtils; import org.testng.Assert; import org.testng.annotations.Guice; 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 54dcdc04..8355f216 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,5 +1,6 @@ package me.chanjar.weixin.mp.api; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; 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 99b7a52c..0fd5fcab 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 @@ -4,6 +4,8 @@ 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 me.chanjar.weixin.mp.api.test.ApiTestModule; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.WxMpMassNews; import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; @@ -33,7 +35,7 @@ public class WxMpMassMessageAPITest { @Test public void testTextMassOpenIdsMessageSend() throws WxErrorException { // 发送群发消息 - WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configProvider = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); @@ -47,10 +49,9 @@ public class WxMpMassMessageAPITest { } @Test(dataProvider = "massMessages") - public void testMediaMassOpenIdsMessageSend(String massMsgType, - String mediaId) throws WxErrorException { + public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException { // 发送群发消息 - WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configProvider = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(massMsgType); @@ -83,8 +84,7 @@ public class WxMpMassMessageAPITest { WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); massMessage.setMsgType(massMsgType); massMessage.setMediaId(mediaId); - massMessage - .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); + massMessage.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); WxMpMassSendResult massResult = this.wxService .massGroupMessageSend(massMessage); @@ -118,7 +118,7 @@ public class WxMpMassMessageAPITest { messages[0] = new Object[]{WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId()}; } - /** + /* * 图片素材 */ try (InputStream inputStream = ClassLoader @@ -130,7 +130,7 @@ public class WxMpMassMessageAPITest { messages[1] = new Object[]{WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId()}; } - /** + /* * 语音素材 */ try (InputStream inputStream = ClassLoader @@ -142,7 +142,7 @@ public class WxMpMassMessageAPITest { messages[2] = new Object[]{WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId()}; } - /** + /* * 图文素材 */ try (InputStream inputStream = ClassLoader 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 656c7162..dd30538f 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 @@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java index 87cf7406..f8b0ce6f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java @@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java index 97619223..1f28f4bb 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java @@ -2,7 +2,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.bean.WxCardApiSignature; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.result.WxMpCardResult; import org.testng.annotations.Guice; 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 3e2257a3..22d0cc3e 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 @@ -14,7 +14,7 @@ import org.testng.annotations.Test; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java index e79dd250..0f621e3e 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java @@ -3,7 +3,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult; import org.testng.annotations.DataProvider; 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 3150dec3..105f078d 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 @@ -3,9 +3,9 @@ package me.chanjar.weixin.mp.api.impl; 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.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; import me.chanjar.weixin.mp.bean.kefu.result.*; @@ -31,7 +31,7 @@ public class WxMpKefuServiceImplTest { protected WxMpService wxService; public void testSendKefuMpNewsMessage() throws WxErrorException { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_MPNEWS); @@ -42,7 +42,7 @@ public class WxMpKefuServiceImplTest { } public void testSendKefuMessage() throws WxErrorException { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); @@ -54,7 +54,7 @@ public class WxMpKefuServiceImplTest { } public void testSendKefuMessageWithKfAccount() throws WxErrorException { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); @@ -85,7 +85,7 @@ public class WxMpKefuServiceImplTest { @DataProvider public Object[][] getKfAccount() { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); return new Object[][] { { configStorage.getKfAccount() } }; } @@ -131,7 +131,7 @@ public class WxMpKefuServiceImplTest { @DataProvider public Object[][] getKfAccountAndOpenid() { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); return new Object[][] { { configStorage.getKfAccount(), configStorage.getOpenid() } }; 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 043a49ec..a3d8f47f 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 @@ -5,7 +5,7 @@ import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.material.WxMpMaterial; import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java index 08980a2b..45703b7b 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java @@ -5,7 +5,7 @@ import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.bean.menu.WxMenuButton; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; import me.chanjar.weixin.mp.bean.menu.WxMpMenu; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index f46765c7..e890deda 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -3,9 +3,9 @@ package me.chanjar.weixin.mp.api.impl; import com.github.binarywang.utils.qrcode.QrcodeUtils; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; import org.testng.annotations.*; @@ -59,7 +59,7 @@ public class WxMpPayServiceImplTest { */ @Test public void setSSLKey(){ - WxXmlMpInMemoryConfigStorage config = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); + TestConfigStorage config = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); config.setSslContextFilePath(config.getKeyPath()); } @@ -107,7 +107,7 @@ public class WxMpPayServiceImplTest { request.setClientIp("aaa"); request.setMchBillNo("aaaa"); request - .setReOpenid(((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); + .setReOpenid(((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); WxPaySendRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request); System.err.println(redpackResult); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java index d1475dfe..b7957e7f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java @@ -2,7 +2,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import org.testng.Assert; 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 c6b8689f..ffb55636 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 @@ -2,9 +2,9 @@ package me.chanjar.weixin.mp.api.impl; 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.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; @@ -103,7 +103,7 @@ public class WxMpServiceImplTest { @Test public void testBuildQrConnectUrl() { - String qrconnectRedirectUrl = ((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl(); + String qrconnectRedirectUrl = ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl(); String qrConnectUrl = this.wxService.buildQrConnectUrl(qrconnectRedirectUrl, WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); Assert.assertNotNull(qrConnectUrl); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java index 63609293..0a6b5610 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java @@ -2,7 +2,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java index b37278e2..28932362 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java @@ -2,9 +2,9 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.template.WxMpTemplate; import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; @@ -33,7 +33,7 @@ public class WxMpTemplateMsgServiceImplTest { public void testSendTemplateMsg() throws WxErrorException { SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS"); - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder() .toUser(configStorage.getOpenid()) 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 index 2bcc3aea..14796f9c 100644 --- 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 @@ -1,8 +1,8 @@ package me.chanjar.weixin.mp.api.impl; -import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; import org.testng.Assert; import org.testng.annotations.Guice; @@ -23,7 +23,7 @@ public class WxMpUserBlacklistServiceImplTest { @Test public void testGetBlacklist() throws Exception { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpUserBlacklistGetResult wxMpUserBlacklistGetResult = this.wxService.getBlackListService().getBlacklist(configStorage.getOpenid()); Assert.assertNotNull(wxMpUserBlacklistGetResult); @@ -35,7 +35,7 @@ public class WxMpUserBlacklistServiceImplTest { @Test public void testPushToBlacklist() throws Exception { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); List openidList = new ArrayList<>(); openidList.add(configStorage.getOpenid()); @@ -44,7 +44,7 @@ public class WxMpUserBlacklistServiceImplTest { @Test public void testPullFromBlacklist() throws Exception { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); List openidList = new ArrayList<>(); openidList.add(configStorage.getOpenid()); 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 02252800..3163ed69 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 @@ -13,8 +13,8 @@ import org.testng.annotations.Test; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.ApiTestModule; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.ApiTestModule; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.WxMpUserQuery; import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.result.WxMpUserList; @@ -32,11 +32,11 @@ public class WxMpUserServiceImplTest { @Inject private WxMpService wxService; - private WxXmlMpInMemoryConfigStorage configProvider; + private TestConfigStorage configProvider; @BeforeTest public void setup() { - this.configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService + this.configProvider = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); } 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 bca04a06..54743ac4 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 @@ -9,8 +9,8 @@ import org.testng.annotations.Test; import com.google.inject.Inject; -import me.chanjar.weixin.mp.api.ApiTestModule; -import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.test.ApiTestModule; +import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.tag.WxTagListUser; import me.chanjar.weixin.mp.bean.tag.WxUserTag; @@ -67,7 +67,7 @@ public class WxMpUserTagServiceImplTest { @Test public void testBatchTagging() throws Exception { - String[] openids = new String[]{((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; + String[] openids = new String[]{((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; boolean res = this.wxService.getUserTagService().batchTagging(this.tagId, openids); System.out.println(res); Assert.assertTrue(res); @@ -75,7 +75,7 @@ public class WxMpUserTagServiceImplTest { @Test public void testBatchUntagging() throws Exception { - String[] openids = new String[]{((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; + String[] openids = new String[]{((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; boolean res = this.wxService.getUserTagService().batchUntagging(this.tagId, openids); System.out.println(res); Assert.assertTrue(res); @@ -84,7 +84,7 @@ public class WxMpUserTagServiceImplTest { @Test public void testUserTagList() throws Exception { List res = this.wxService.getUserTagService().userTagList( - ((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); + ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); System.out.println(res); Assert.assertNotNull(res); } 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/test/ApiTestModule.java similarity index 77% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java index c506df0f..c957bde8 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/test/ApiTestModule.java @@ -1,9 +1,11 @@ -package me.chanjar.weixin.mp.api; +package me.chanjar.weixin.mp.api.test; import com.google.inject.Binder; import com.google.inject.Module; import com.thoughtworks.xstream.XStream; import me.chanjar.weixin.common.util.xml.XStreamInitializer; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import java.io.IOException; @@ -14,10 +16,9 @@ public class ApiTestModule implements Module { @Override public void configure(Binder binder) { - try (InputStream is1 = ClassLoader - .getSystemResourceAsStream("test-config.xml")) { - WxXmlMpInMemoryConfigStorage config = this - .fromXml(WxXmlMpInMemoryConfigStorage.class, is1); + try (InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml")) { + TestConfigStorage config = this + .fromXml(TestConfigStorage.class, is1); config.setAccessTokenLock(new ReentrantLock()); WxMpService wxService = new WxMpServiceImpl(); wxService.setWxMpConfigStorage(config); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java similarity index 87% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java index e51ffeb6..0dc91151 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java @@ -1,18 +1,19 @@ -package me.chanjar.weixin.mp.api; +package me.chanjar.weixin.mp.api.test; import com.thoughtworks.xstream.annotations.XStreamAlias; +import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; import org.apache.commons.lang3.builder.ToStringBuilder; import java.util.concurrent.locks.Lock; @XStreamAlias("xml") -public class WxXmlMpInMemoryConfigStorage - extends WxMpInMemoryConfigStorage { +public class TestConfigStorage extends WxMpInMemoryConfigStorage { private String openid; private String kfAccount; private String qrconnectRedirectUrl; private String templateId; + private String keyPath; public String getKeyPath() { return keyPath; @@ -22,8 +23,6 @@ public class WxXmlMpInMemoryConfigStorage this.keyPath = keyPath; } - private String keyPath; - public String getOpenid() { return this.openid; } @@ -61,7 +60,7 @@ public class WxXmlMpInMemoryConfigStorage this.templateId = templateId; } - public void setAccessTokenLock(Lock lock){ + public void setAccessTokenLock(Lock lock) { super.accessTokenLock = lock; } From ff1b69a38f5a68601fc3bcf6cff0ce270e8a187a Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 23 Jan 2017 16:54:48 +0800 Subject: [PATCH 67/76] =?UTF-8?q?=E4=BD=BF=E7=94=A8IDEA=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpBaseAPITest.java | 7 +- .../weixin/mp/api/WxMpBusyRetryTest.java | 11 +- .../chanjar/weixin/mp/api/WxMpJsAPITest.java | 17 +-- .../weixin/mp/api/WxMpMassMessageAPITest.java | 6 +- .../weixin/mp/api/WxMpMessageRouterTest.java | 134 +++++++++--------- .../weixin/mp/api/WxMpMiscAPITest.java | 7 +- .../weixin/mp/api/WxMpShortUrlAPITest.java | 5 +- .../mp/api/impl/WxMpCardServiceImplTest.java | 8 +- .../api/impl/WxMpDataCubeServiceImplTest.java | 95 ++++++------- .../api/impl/WxMpDeviceServiceImplTest.java | 6 +- .../mp/api/impl/WxMpKefuServiceImplTest.java | 66 +++++---- .../api/impl/WxMpMaterialServiceImplTest.java | 74 +++++----- .../mp/api/impl/WxMpMenuServiceImplTest.java | 2 +- .../mp/api/impl/WxMpPayServiceImplTest.java | 8 +- .../api/impl/WxMpQrcodeServiceImplTest.java | 8 +- .../mp/api/impl/WxMpServiceImplTest.java | 9 +- .../mp/api/impl/WxMpStoreServiceImplTest.java | 17 ++- .../impl/WxMpTemplateMsgServiceImplTest.java | 11 +- .../WxMpUserBlacklistServiceImplTest.java | 7 +- .../mp/api/impl/WxMpUserServiceImplTest.java | 27 ++-- .../api/impl/WxMpUserTagServiceImplTest.java | 20 ++- .../mp/bean/kefu/WxMpKefuMessageTest.java | 18 +-- .../mp/bean/kefu/result/WxMpKfListTest.java | 50 +++---- .../kefu/result/WxMpKfOnlineListTest.java | 42 +++--- .../mp/bean/message/WxMpXmlMessageTest.java | 4 +- .../message/WxMpXmlOutImageMessageTest.java | 44 +++--- .../message/WxMpXmlOutMusicMessageTest.java | 74 +++++----- .../message/WxMpXmlOutNewsMessageTest.java | 100 ++++++------- .../message/WxMpXmlOutTextMessageTest.java | 34 ++--- .../WxMpXmlOutTransferKefuMessageTest.java | 4 +- .../message/WxMpXmlOutVideoMessageTest.java | 62 ++++---- .../message/WxMpXmlOutVoiceMessageTest.java | 34 ++--- .../bean/pay/result/WxPayBaseResultTest.java | 4 +- .../pay/result/WxPayOrderQueryResultTest.java | 4 +- .../result/WxPayRefundQueryResultTest.java | 4 +- .../result/WxPaySendRedpackResultTest.java | 57 ++++---- .../mp/demo/DemoGuessNumberHandler.java | 50 +++---- .../weixin/mp/demo/DemoImageHandler.java | 16 +-- .../weixin/mp/demo/DemoLogHandler.java | 2 +- .../weixin/mp/demo/DemoOAuth2Handler.java | 12 +- .../weixin/mp/demo/DemoTextHandler.java | 6 +- .../demo/WxMpDemoInMemoryConfigStorage.java | 13 +- .../weixin/mp/demo/WxMpDemoServer.java | 33 +++-- .../weixin/mp/demo/WxMpEndpointServlet.java | 8 +- .../weixin/mp/demo/WxMpOAuth2Servlet.java | 13 +- 45 files changed, 591 insertions(+), 642 deletions(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java index c3b53d66..c8b616fa 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java @@ -4,14 +4,13 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.apache.commons.lang3.StringUtils; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; /** * 基础API测试 - * @author chanjarster * + * @author chanjarster */ @Test(groups = "baseAPI") @Guice(modules = ApiTestModule.class) 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 8d46eba7..da646087 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 @@ -4,8 +4,7 @@ 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 org.testng.annotations.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -15,14 +14,14 @@ import java.util.concurrent.Future; @Test public class WxMpBusyRetryTest { - @DataProvider(name="getService") + @DataProvider(name = "getService") public Object[][] getService() { WxMpService service = new WxMpServiceImpl() { @Override protected synchronized T executeInternal( - RequestExecutor executor, String uri, E data) - throws WxErrorException { + RequestExecutor executor, String uri, E data) + throws WxErrorException { this.log.info("Executed"); WxError error = new WxError(); error.setErrorCode(-1); @@ -32,7 +31,7 @@ public class WxMpBusyRetryTest { service.setMaxRetryTimes(3); service.setRetrySleepMillis(500); - return new Object[][] { { service } }; + return new Object[][]{{service}}; } @Test(dataProvider = "getService", expectedExceptions = RuntimeException.class) 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 8355f216..9fd32278 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,11 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.mp.api.test.ApiTestModule; -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.crypto.SHA1; +import me.chanjar.weixin.mp.api.test.ApiTestModule; +import org.testng.*; +import org.testng.annotations.*; /** * 测试jsapi ticket接口 @@ -35,10 +32,10 @@ public class WxMpJsAPITest { String noncestr = "82693e11-b9bc-448e-892f-f5289f46cd0f"; String jsapiTicket = "bxLdikRXVbTPdHSM05e5u4RbEYQn7pNQMPrfzl8lJNb1foLDa3HIwI3BRMkQmSO_5F64VFa75uURcq6Uz7QHgA"; String result = SHA1.genWithAmple( - "jsapi_ticket=" + jsapiTicket, - "noncestr=" + noncestr, - "timestamp=" + timestamp, - "url=" + url + "jsapi_ticket=" + jsapiTicket, + "noncestr=" + noncestr, + "timestamp=" + timestamp, + "url=" + url ); Assert.assertEquals(result, "c6f04b64d6351d197b71bd23fb7dd2d44c0db486"); 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 0fd5fcab..3c42f66c 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 @@ -12,10 +12,8 @@ import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; import me.chanjar.weixin.mp.bean.WxMpMassVideo; import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.io.IOException; import java.io.InputStream; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java index dc922aab..4360440f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java @@ -5,16 +5,15 @@ import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.util.Map; /** * 测试消息路由器 - * @author chanjarster * + * @author chanjarster */ @Test public class WxMpMessageRouterTest { @@ -23,19 +22,19 @@ public class WxMpMessageRouterTest { public void prepare(boolean async, StringBuffer sb, WxMpMessageRouter router) { router .rule() - .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") - .handler(new WxEchoMpMessageHandler(sb, "COMBINE_4")) + .async(async) + .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") + .handler(new WxEchoMpMessageHandler(sb, "COMBINE_4")) .end() .rule() - .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1") - .handler(new WxEchoMpMessageHandler(sb, "COMBINE_3")) + .async(async) + .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1") + .handler(new WxEchoMpMessageHandler(sb, "COMBINE_3")) .end() .rule() - .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK) - .handler(new WxEchoMpMessageHandler(sb, "COMBINE_2")) + .async(async) + .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK) + .handler(new WxEchoMpMessageHandler(sb, "COMBINE_2")) .end() .rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoMpMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end() .rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoMpMessageHandler(sb, WxConsts.EVT_CLICK)).end() @@ -43,15 +42,15 @@ public class WxMpMessageRouterTest { .rule().async(async).content("CONTENT_1").handler(new WxEchoMpMessageHandler(sb, "CONTENT_1")).end() .rule().async(async).rContent(".*bc.*").handler(new WxEchoMpMessageHandler(sb, "abcd")).end() .rule().async(async).matcher(new WxMpMessageMatcher() { - @Override - public boolean match(WxMpXmlMessage message) { - return "strangeformat".equals(message.getFormat()); - } - }).handler(new WxEchoMpMessageHandler(sb, "matcher")).end() + @Override + public boolean match(WxMpXmlMessage message) { + return "strangeformat".equals(message.getFormat()); + } + }).handler(new WxEchoMpMessageHandler(sb, "matcher")).end() .rule().async(async).handler(new WxEchoMpMessageHandler(sb, "ALL")).end(); } - @Test(dataProvider="messages-1") + @Test(dataProvider = "messages-1") public void testSync(WxMpXmlMessage message, String expected) { StringBuffer sb = new StringBuffer(); WxMpMessageRouter router = new WxMpMessageRouter(null); @@ -60,11 +59,11 @@ public class WxMpMessageRouterTest { Assert.assertEquals(sb.toString(), expected); } - @Test(dataProvider="messages-1") + @Test(dataProvider = "messages-1") public void testAsync(WxMpXmlMessage message, String expected) throws InterruptedException { StringBuffer sb = new StringBuffer(); WxMpMessageRouter router = new WxMpMessageRouter(null); - prepare(true, sb, router); + prepare(true, sb, router); router.route(message); Thread.sleep(500l); Assert.assertEquals(sb.toString(), expected); @@ -75,7 +74,7 @@ public class WxMpMessageRouterTest { router.rule().handler(new WxMpMessageHandler() { @Override public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService, - WxSessionManager sessionManager) { + WxSessionManager sessionManager) { return null; } }).end(); @@ -97,7 +96,8 @@ public class WxMpMessageRouterTest { Thread.sleep(1000l * 2); } - @DataProvider(name="messages-1") + + @DataProvider(name = "messages-1") public Object[][] messages2() { WxMpXmlMessage message1 = new WxMpXmlMessage(); message1.setMsgType(WxConsts.XML_MSG_TEXT); @@ -135,40 +135,21 @@ public class WxMpMessageRouterTest { c4.setEventKey("KEY_1"); c4.setContent("CONTENT_1"); - return new Object[][] { - new Object[] { message1, WxConsts.XML_MSG_TEXT + "," }, - new Object[] { message2, WxConsts.EVT_CLICK + "," }, - new Object[] { message3, "KEY_1," }, - new Object[] { message4, "CONTENT_1," }, - new Object[] { message5, "ALL," }, - new Object[] { message6, "abcd," }, - new Object[] { message7, "matcher," }, - new Object[] { c2, "COMBINE_2," }, - new Object[] { c3, "COMBINE_3," }, - new Object[] { c4, "COMBINE_4," } + return new Object[][]{ + new Object[]{message1, WxConsts.XML_MSG_TEXT + ","}, + new Object[]{message2, WxConsts.EVT_CLICK + ","}, + new Object[]{message3, "KEY_1,"}, + new Object[]{message4, "CONTENT_1,"}, + new Object[]{message5, "ALL,"}, + new Object[]{message6, "abcd,"}, + new Object[]{message7, "matcher,"}, + new Object[]{c2, "COMBINE_2,"}, + new Object[]{c3, "COMBINE_3,"}, + new Object[]{c4, "COMBINE_4,"} }; } - public static class WxEchoMpMessageHandler implements WxMpMessageHandler { - - private StringBuffer sb; - private String echoStr; - - public WxEchoMpMessageHandler(StringBuffer sb, String echoStr) { - this.sb = sb; - this.echoStr = echoStr; - } - - @Override - public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService, - WxSessionManager sessionManager) { - this.sb.append(this.echoStr).append(','); - return null; - } - - } - @DataProvider public Object[][] standardSessionManager() { @@ -178,8 +159,8 @@ public class WxMpMessageRouterTest { ism.setProcessExpiresFrequency(1); ism.setBackgroundProcessorDelay(1); - return new Object[][] { - new Object[] { ism } + return new Object[][]{ + new Object[]{ism} }; } @@ -191,8 +172,8 @@ public class WxMpMessageRouterTest { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(false).handler(new WxSessionMessageHandler()).next() - .rule().async(false).handler(new WxSessionMessageHandler()).end(); + .rule().async(false).handler(new WxSessionMessageHandler()).next() + .rule().async(false).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -211,8 +192,8 @@ public class WxMpMessageRouterTest { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(false).handler(new WxSessionMessageHandler()).next() - .rule().async(true).handler(new WxSessionMessageHandler()).end(); + .rule().async(false).handler(new WxSessionMessageHandler()).next() + .rule().async(true).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -225,8 +206,8 @@ public class WxMpMessageRouterTest { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(true).handler(new WxSessionMessageHandler()).next() - .rule().async(false).handler(new WxSessionMessageHandler()).end(); + .rule().async(true).handler(new WxSessionMessageHandler()).next() + .rule().async(false).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -245,8 +226,8 @@ public class WxMpMessageRouterTest { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(true).handler(new WxSessionMessageHandler()).next() - .rule().async(true).handler(new WxSessionMessageHandler()).end(); + .rule().async(true).handler(new WxSessionMessageHandler()).next() + .rule().async(true).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -265,7 +246,7 @@ public class WxMpMessageRouterTest { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(false).handler(new WxSessionMessageHandler()).end(); + .rule().async(false).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -279,7 +260,7 @@ public class WxMpMessageRouterTest { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router - .rule().async(true).handler(new WxSessionMessageHandler()).end(); + .rule().async(true).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); @@ -290,11 +271,30 @@ public class WxMpMessageRouterTest { } } - public static class WxSessionMessageHandler implements WxMpMessageHandler { + public static class WxEchoMpMessageHandler implements WxMpMessageHandler { + + private StringBuffer sb; + private String echoStr; + + public WxEchoMpMessageHandler(StringBuffer sb, String echoStr) { + this.sb = sb; + this.echoStr = echoStr; + } + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService, + WxSessionManager sessionManager) { + this.sb.append(this.echoStr).append(','); + return null; + } + + } + + public static class WxSessionMessageHandler implements WxMpMessageHandler { @Override public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService, - WxSessionManager sessionManager) { + WxSessionManager sessionManager) { sessionManager.getSession(wxMessage.getFromUser()); return null; } 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 dd30538f..8c61a560 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 @@ -3,16 +3,13 @@ package me.chanjar.weixin.mp.api; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.test.ApiTestModule; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.util.Arrays; /** - * * @author chanjarster - * */ @Test(groups = "miscAPI") @Guice(modules = ApiTestModule.class) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java index f8b0ce6f..3e8a45c3 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java @@ -3,9 +3,8 @@ package me.chanjar.weixin.mp.api; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.test.ApiTestModule; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; /** * 测试短连接 diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java index 1f28f4bb..3036013a 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java @@ -2,17 +2,17 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.bean.WxCardApiSignature; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.result.WxMpCardResult; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; -import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.*; /** * 测试代码仅供参考,未做严格测试,因原接口作者并未提供单元测试代码 * Created by Binary Wang on 2016/7/27. + * * @author binarywang (https://github.com/binarywang) */ @Test 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 22d0cc3e..0f465d4a 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,83 +1,74 @@ package me.chanjar.weixin.mp.api.impl; -import java.text.ParseException; -import java.util.Date; -import java.util.List; - -import me.chanjar.weixin.mp.api.WxMpService; -import org.apache.commons.lang3.time.FastDateFormat; -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.exception.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; -import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult; -import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal; -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.bean.datacube.*; +import org.apache.commons.lang3.time.FastDateFormat; +import org.testng.*; +import org.testng.annotations.*; + +import java.text.ParseException; +import java.util.Date; +import java.util.List; /** * 测试统计分析相关的接口 - * Created by Binary Wang on 2016/8/23. + * Created by Binary Wang on 2016/8/23. + * * @author binarywang (https://github.com/binarywang) */ @Guice(modules = ApiTestModule.class) public class WxMpDataCubeServiceImplTest { - private FastDateFormat simpleDateFormat = FastDateFormat - .getInstance("yyyy-MM-dd"); - @Inject protected WxMpService wxService; + private FastDateFormat simpleDateFormat = FastDateFormat + .getInstance("yyyy-MM-dd"); @DataProvider public Object[][] oneDay() throws ParseException { - return new Object[][] { { this.simpleDateFormat.parse("2016-08-22") } }; + return new Object[][]{{this.simpleDateFormat.parse("2016-08-22")}}; } @DataProvider public Object[][] threeDays() throws ParseException { - return new Object[][] { { this.simpleDateFormat.parse("2016-08-20"), - this.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[][] { { this.simpleDateFormat.parse("2016-08-16"), - this.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[][] { { this.simpleDateFormat.parse("2016-08-14"), - this.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[][] { { this.simpleDateFormat.parse("2016-07-30"), - this.simpleDateFormat.parse("2016-08-27") } }; + return new Object[][]{{this.simpleDateFormat.parse("2016-07-30"), + this.simpleDateFormat.parse("2016-08-27")}}; } @Test(dataProvider = "sevenDays") public void testGetUserSummary(Date beginDate, Date endDate) - throws WxErrorException { + throws WxErrorException { List summaries = this.wxService.getDataCubeService() - .getUserSummary(beginDate, endDate); + .getUserSummary(beginDate, endDate); Assert.assertNotNull(summaries); System.out.println(summaries); } @Test(dataProvider = "sevenDays") public void testGetUserCumulate(Date beginDate, Date endDate) - throws WxErrorException { + throws WxErrorException { List result = this.wxService.getDataCubeService() - .getUserCumulate(beginDate, endDate); + .getUserCumulate(beginDate, endDate); Assert.assertNotNull(result); System.out.println(result); } @@ -85,7 +76,7 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "oneDay") public void testGetArticleSummary(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getArticleSummary(date, date); + .getArticleSummary(date, date); Assert.assertNotNull(results); System.out.println(results); } @@ -96,16 +87,16 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "oneDay") public void testGetArticleTotal(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getArticleTotal(date, date); + .getArticleTotal(date, date); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "threeDays") public void testGetUserRead(Date beginDate, Date endDate) - throws WxErrorException { + throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUserRead(beginDate, endDate); + .getUserRead(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -113,16 +104,16 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "oneDay") public void testGetUserReadHour(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUserReadHour(date, date); + .getUserReadHour(date, date); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "sevenDays") public void testGetUserShare(Date beginDate, Date endDate) - throws WxErrorException { + throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUserShare(beginDate, endDate); + .getUserShare(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -130,7 +121,7 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "oneDay") public void testGetUserShareHour(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUserShareHour(date, date); + .getUserShareHour(date, date); Assert.assertNotNull(results); System.out.println(results); } @@ -138,7 +129,7 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "sevenDays") public void testGetUpstreamMsg(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsg(beginDate, endDate); + .getUpstreamMsg(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -146,7 +137,7 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "oneDay") public void testGetUpstreamMsgHour(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgHour(date, date); + .getUpstreamMsgHour(date, date); Assert.assertNotNull(results); System.out.println(results); } @@ -154,7 +145,7 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgWeek(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgWeek(beginDate, endDate); + .getUpstreamMsgWeek(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -165,7 +156,7 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgMonth(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgMonth(beginDate, endDate); + .getUpstreamMsgMonth(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -173,7 +164,7 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "fifteenDays") public void testGetUpstreamMsgDist(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgDist(beginDate, endDate); + .getUpstreamMsgDist(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -181,7 +172,7 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgDistWeek(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgDistWeek(beginDate, endDate); + .getUpstreamMsgDistWeek(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -192,7 +183,7 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgDistMonth(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getUpstreamMsgDistMonth(beginDate, endDate); + .getUpstreamMsgDistMonth(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -200,7 +191,7 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "thirtyDays") public void testGetInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getInterfaceSummary(beginDate, endDate); + .getInterfaceSummary(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @@ -208,7 +199,7 @@ public class WxMpDataCubeServiceImplTest { @Test(dataProvider = "oneDay") public void testGetInterfaceSummaryHour(Date date) throws WxErrorException { List results = this.wxService.getDataCubeService() - .getInterfaceSummaryHour(date, date); + .getInterfaceSummaryHour(date, date); Assert.assertNotNull(results); System.out.println(results); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java index 0f621e3e..d48161e3 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java @@ -3,12 +3,10 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; /** * Created by keungtung on 14/12/2016. 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 105f078d..2bf5de1d 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 @@ -3,25 +3,23 @@ package me.chanjar.weixin.mp.api.impl; 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.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; import me.chanjar.weixin.mp.bean.kefu.result.*; import org.joda.time.DateTime; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.io.File; import java.util.Date; /** * 测试客服相关接口 - * @author Binary Wang * + * @author Binary Wang */ @Test @Guice(modules = ApiTestModule.class) @@ -43,25 +41,25 @@ public class WxMpKefuServiceImplTest { public void testSendKefuMessage() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); + .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); message.setToUser(configStorage.getOpenid()); message.setContent( - "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); + "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); this.wxService.getKefuService().sendKefuMessage(message); } public void testSendKefuMessageWithKfAccount() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); + .getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); message.setToUser(configStorage.getOpenid()); message.setKfAccount(configStorage.getKfAccount()); message.setContent( - "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); + "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); this.wxService.getKefuService().sendKefuMessage(message); } @@ -76,7 +74,7 @@ public class WxMpKefuServiceImplTest { public void testKfOnlineList() throws WxErrorException { WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService() - .kfOnlineList(); + .kfOnlineList(); Assert.assertNotNull(kfOnlineList); for (WxMpKfInfo k : kfOnlineList.getKfOnlineList()) { System.err.println(k); @@ -86,40 +84,40 @@ public class WxMpKefuServiceImplTest { @DataProvider public Object[][] getKfAccount() { TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); - return new Object[][] { { configStorage.getKfAccount() } }; + .getWxMpConfigStorage(); + return new Object[][]{{configStorage.getKfAccount()}}; } @Test(dataProvider = "getKfAccount") public void testKfAccountAdd(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() - .kfAccount(kfAccount).nickName("我晕").build(); + .kfAccount(kfAccount).nickName("我晕").build(); Assert.assertTrue(this.wxService.getKefuService().kfAccountAdd(request)); } @Test(dependsOnMethods = { - "testKfAccountAdd" }, dataProvider = "getKfAccount") + "testKfAccountAdd"}, dataProvider = "getKfAccount") public void testKfAccountUpdate(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() - .kfAccount(kfAccount).nickName("我晕").build(); + .kfAccount(kfAccount).nickName("我晕").build(); Assert.assertTrue(this.wxService.getKefuService().kfAccountUpdate(request)); } @Test(dependsOnMethods = { - "testKfAccountAdd" }, dataProvider = "getKfAccount") + "testKfAccountAdd"}, dataProvider = "getKfAccount") public void testKfAccountInviteWorker(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() - .kfAccount(kfAccount).inviteWx(" ").build(); + .kfAccount(kfAccount).inviteWx(" ").build(); Assert.assertTrue(this.wxService.getKefuService().kfAccountInviteWorker(request)); } @Test(dependsOnMethods = { - "testKfAccountUpdate" }, dataProvider = "getKfAccount") + "testKfAccountUpdate"}, dataProvider = "getKfAccount") public void testKfAccountUploadHeadImg(String kfAccount) - throws WxErrorException { + throws WxErrorException { File imgFile = new File("src\\test\\resources\\mm.jpeg"); boolean result = this.wxService.getKefuService() - .kfAccountUploadHeadImg(kfAccount, imgFile); + .kfAccountUploadHeadImg(kfAccount, imgFile); Assert.assertTrue(result); } @@ -132,32 +130,32 @@ public class WxMpKefuServiceImplTest { @DataProvider public Object[][] getKfAccountAndOpenid() { TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); - return new Object[][] { - { configStorage.getKfAccount(), configStorage.getOpenid() } }; + .getWxMpConfigStorage(); + return new Object[][]{ + {configStorage.getKfAccount(), configStorage.getOpenid()}}; } @Test(dataProvider = "getKfAccountAndOpenid") public void testKfSessionCreate(String kfAccount, String openid) - throws WxErrorException { + throws WxErrorException { boolean result = this.wxService.getKefuService().kfSessionCreate(openid, - kfAccount); + kfAccount); Assert.assertTrue(result); } @Test(dataProvider = "getKfAccountAndOpenid") public void testKfSessionClose(String kfAccount, String openid) - throws WxErrorException { + throws WxErrorException { boolean result = this.wxService.getKefuService().kfSessionClose(openid, - kfAccount); + kfAccount); Assert.assertTrue(result); } @Test(dataProvider = "getKfAccountAndOpenid") public void testKfSessionGet(@SuppressWarnings("unused") String kfAccount, - String openid) throws WxErrorException { + String openid) throws WxErrorException { WxMpKfSessionGetResult result = this.wxService.getKefuService() - .kfSessionGet(openid); + .kfSessionGet(openid); Assert.assertNotNull(result); System.err.println(result); } @@ -165,7 +163,7 @@ public class WxMpKefuServiceImplTest { @Test(dataProvider = "getKfAccount") public void testKfSessionList(String kfAccount) throws WxErrorException { WxMpKfSessionList result = this.wxService.getKefuService() - .kfSessionList(kfAccount); + .kfSessionList(kfAccount); Assert.assertNotNull(result); System.err.println(result); } @@ -173,7 +171,7 @@ public class WxMpKefuServiceImplTest { @Test public void testKfSessionGetWaitCase() throws WxErrorException { WxMpKfSessionWaitCaseList result = this.wxService.getKefuService() - .kfSessionGetWaitCase(); + .kfSessionGetWaitCase(); Assert.assertNotNull(result); System.err.println(result); } @@ -182,7 +180,7 @@ public class WxMpKefuServiceImplTest { 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); + WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime, 1L, 50); Assert.assertNotNull(result); System.err.println(result); } @@ -191,7 +189,7 @@ public class WxMpKefuServiceImplTest { 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); + WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime); Assert.assertNotNull(result); System.err.println(result); } 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 a3d8f47f..ca90a7b5 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 @@ -5,15 +5,10 @@ import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.bean.material.WxMpMaterial; -import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate; -import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.material.*; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; import java.io.File; import java.io.IOException; @@ -44,14 +39,16 @@ public class WxMpMaterialServiceImplTest { private String multiNewsMediaId = ""; // 先查询保存测试开始前永久素材数据 private WxMpMaterialCountResult wxMaterialCountResultBeforeTest; + // 以下为media接口的测试 + private List mediaIdsToDownload = new ArrayList<>(); @DataProvider public Object[][] mediaFiles() { - return new Object[][] { - new Object[] { WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg" }, - new Object[] { WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3" }, - new Object[] { WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4" }, - new Object[] { WxConsts.MEDIA_THUMB, WxConsts.FILE_JPG, "mm.jpeg" } + return new Object[][]{ + new Object[]{WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg"}, + new Object[]{WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3"}, + new Object[]{WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4"}, + new Object[]{WxConsts.MEDIA_THUMB, WxConsts.FILE_JPG, "mm.jpeg"} }; } @@ -59,13 +56,13 @@ public class WxMpMaterialServiceImplTest { public void testUploadMaterial(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { if (this.wxMaterialCountResultBeforeTest == null) { this.wxMaterialCountResultBeforeTest = this.wxService.getMaterialService() - .materialCount(); + .materialCount(); } try (InputStream inputStream = ClassLoader - .getSystemResourceAsStream(fileName)) { + .getSystemResourceAsStream(fileName)) { File tempFile = FileUtils.createTmpFile(inputStream, - UUID.randomUUID().toString(), fileType); + UUID.randomUUID().toString(), fileType); WxMpMaterial wxMaterial = new WxMpMaterial(); wxMaterial.setFile(tempFile); wxMaterial.setName(fileName); @@ -75,11 +72,11 @@ public class WxMpMaterialServiceImplTest { } WxMpMaterialUploadResult res = this.wxService.getMaterialService() - .materialFileUpload(mediaType, wxMaterial); + .materialFileUpload(mediaType, wxMaterial); assertNotNull(res.getMediaId()); if (WxConsts.MEDIA_IMAGE.equals(mediaType) - || WxConsts.MEDIA_THUMB.equals(mediaType)) { + || WxConsts.MEDIA_THUMB.equals(mediaType)) { assertNotNull(res.getUrl()); } @@ -145,16 +142,16 @@ public class WxMpMaterialServiceImplTest { WxMpMaterialCountResult wxMaterialCountResult = this.wxService.getMaterialService().materialCount(); // 测试上传过程中添加了一个音频,一个视频,两个图片,两个图文消息 assertEquals( - this.wxMaterialCountResultBeforeTest.getVoiceCount() + 1, - wxMaterialCountResult.getVoiceCount()); + this.wxMaterialCountResultBeforeTest.getVoiceCount() + 1, + wxMaterialCountResult.getVoiceCount()); assertEquals( - this.wxMaterialCountResultBeforeTest.getVideoCount() + 1, - wxMaterialCountResult.getVideoCount()); + this.wxMaterialCountResultBeforeTest.getVideoCount() + 1, + wxMaterialCountResult.getVideoCount()); assertEquals( - this.wxMaterialCountResultBeforeTest.getImageCount() + 2, - wxMaterialCountResult.getImageCount()); + this.wxMaterialCountResultBeforeTest.getImageCount() + 2, + wxMaterialCountResult.getImageCount()); assertEquals(this.wxMaterialCountResultBeforeTest.getNewsCount() + 2, - wxMaterialCountResult.getNewsCount()); + wxMaterialCountResult.getNewsCount()); } @Test(dependsOnMethods = {"testMaterialCount"}, dataProvider = "downloadMaterial") @@ -164,7 +161,7 @@ public class WxMpMaterialServiceImplTest { String filename = materialInfo.get("filename").toString(); if (filename.endsWith(".mp3") || filename.endsWith(".jpeg")) { try (InputStream inputStream = this.wxService.getMaterialService() - .materialImageOrVoiceDownload(mediaId)) { + .materialImageOrVoiceDownload(mediaId)) { assertNotNull(inputStream); } } @@ -178,9 +175,9 @@ public class WxMpMaterialServiceImplTest { @Test(dependsOnMethods = {"testAddNews"}) public void testGetNewsInfo() throws WxErrorException { WxMpMaterialNews wxMpMaterialNewsSingle = this.wxService - .getMaterialService().materialNewsInfo(this.singleNewsMediaId); + .getMaterialService().materialNewsInfo(this.singleNewsMediaId); WxMpMaterialNews wxMpMaterialNewsMultiple = this.wxService - .getMaterialService().materialNewsInfo(this.multiNewsMediaId); + .getMaterialService().materialNewsInfo(this.multiNewsMediaId); assertNotNull(wxMpMaterialNewsSingle); assertNotNull(wxMpMaterialNewsMultiple); } @@ -188,7 +185,7 @@ public class WxMpMaterialServiceImplTest { @Test(dependsOnMethods = {"testGetNewsInfo"}) public void testUpdateNewsInfo() throws WxErrorException { WxMpMaterialNews wxMpMaterialNewsSingle = this.wxService - .getMaterialService().materialNewsInfo(this.singleNewsMediaId); + .getMaterialService().materialNewsInfo(this.singleNewsMediaId); assertNotNull(wxMpMaterialNewsSingle); WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateSingle = new WxMpMaterialArticleUpdate(); WxMpMaterialNews.WxMpMaterialNewsArticle articleSingle = wxMpMaterialNewsSingle.getArticles().get(0); @@ -199,13 +196,13 @@ public class WxMpMaterialServiceImplTest { boolean resultSingle = this.wxService.getMaterialService().materialNewsUpdate(wxMpMaterialArticleUpdateSingle); assertTrue(resultSingle); wxMpMaterialNewsSingle = this.wxService.getMaterialService() - .materialNewsInfo(this.singleNewsMediaId); + .materialNewsInfo(this.singleNewsMediaId); assertNotNull(wxMpMaterialNewsSingle); assertEquals("content single update", - wxMpMaterialNewsSingle.getArticles().get(0).getContent()); + wxMpMaterialNewsSingle.getArticles().get(0).getContent()); WxMpMaterialNews wxMpMaterialNewsMultiple = this.wxService - .getMaterialService().materialNewsInfo(this.multiNewsMediaId); + .getMaterialService().materialNewsInfo(this.multiNewsMediaId); assertNotNull(wxMpMaterialNewsMultiple); WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateMulti = new WxMpMaterialArticleUpdate(); WxMpMaterialNews.WxMpMaterialNewsArticle articleMulti = wxMpMaterialNewsMultiple.getArticles().get(1); @@ -216,10 +213,10 @@ public class WxMpMaterialServiceImplTest { boolean resultMulti = this.wxService.getMaterialService().materialNewsUpdate(wxMpMaterialArticleUpdateMulti); assertTrue(resultMulti); wxMpMaterialNewsMultiple = this.wxService.getMaterialService() - .materialNewsInfo(this.multiNewsMediaId); + .materialNewsInfo(this.multiNewsMediaId); assertNotNull(wxMpMaterialNewsMultiple); assertEquals("content 2 update", - wxMpMaterialNewsMultiple.getArticles().get(1).getContent()); + wxMpMaterialNewsMultiple.getArticles().get(1).getContent()); } @Test(dependsOnMethods = {"testUpdateNewsInfo"}) @@ -266,12 +263,9 @@ public class WxMpMaterialServiceImplTest { return params.iterator(); } - // 以下为media接口的测试 - private List mediaIdsToDownload = new ArrayList<>(); - - @Test(dataProvider="mediaFiles") + @Test(dataProvider = "mediaFiles") public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { - try(InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName)){ + try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName)) { WxMediaUploadResult res = this.wxService.getMaterialService().mediaUpload(mediaType, fileType, inputStream); assertNotNull(res.getType()); assertNotNull(res.getCreatedAt()); @@ -294,12 +288,12 @@ public class WxMpMaterialServiceImplTest { public Object[][] downloadMedia() { Object[][] params = new Object[this.mediaIdsToDownload.size()][]; for (int i = 0; i < this.mediaIdsToDownload.size(); i++) { - params[i] = new Object[] { this.mediaIdsToDownload.get(i) }; + params[i] = new Object[]{this.mediaIdsToDownload.get(i)}; } return params; } - @Test(dependsOnMethods = { "testUploadMedia" }, dataProvider="downloadMedia") + @Test(dependsOnMethods = {"testUploadMedia"}, dataProvider = "downloadMedia") public void testDownloadMedia(String mediaId) throws WxErrorException { File file = this.wxService.getMaterialService().mediaDownload(mediaId); assertNotNull(file); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java index 45703b7b..42819b2f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java @@ -5,8 +5,8 @@ import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.bean.menu.WxMenuButton; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; import me.chanjar.weixin.mp.bean.menu.WxMpMenu; import org.testng.*; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index e890deda..2783ee7f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -3,8 +3,8 @@ package me.chanjar.weixin.mp.api.impl; import com.github.binarywang.utils.qrcode.QrcodeUtils; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.result.*; @@ -36,10 +36,10 @@ public class WxMpPayServiceImplTest { @Test public void testDownloadBill() throws Exception { - File file = this.wxService.getPayService().downloadBill("20170101","ALL","GZIP","1111111"); + File file = this.wxService.getPayService().downloadBill("20170101", "ALL", "GZIP", "1111111"); assertNotNull(file); //必填字段为空时,抛出异常 - this.wxService.getPayService().downloadBill("","","",null); + this.wxService.getPayService().downloadBill("", "", "", null); } @Test @@ -58,7 +58,7 @@ public class WxMpPayServiceImplTest { * 需要证书的接口需要先执行该方法 */ @Test - public void setSSLKey(){ + public void setSSLKey() { TestConfigStorage config = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); config.setSslContextFilePath(config.getKeyPath()); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java index b7957e7f..c61e3833 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java @@ -2,13 +2,11 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.io.File; 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 ffb55636..d5bf6212 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 @@ -2,12 +2,11 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test @Guice(modules = ApiTestModule.class) @@ -105,7 +104,7 @@ public class WxMpServiceImplTest { public void testBuildQrConnectUrl() { String qrconnectRedirectUrl = ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl(); String qrConnectUrl = this.wxService.buildQrConnectUrl(qrconnectRedirectUrl, - WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); + WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); Assert.assertNotNull(qrConnectUrl); System.out.println(qrConnectUrl); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java index 0a6b5610..e4edca74 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java @@ -2,13 +2,12 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.annotations.*; import java.math.BigDecimal; import java.util.List; @@ -18,7 +17,6 @@ import static org.junit.Assert.assertNotNull; /** * @author binarywang(Binary Wang) * Created by Binary Wang on 2016-09-23. - * */ @Test @Guice(modules = ApiTestModule.class) @@ -28,16 +26,17 @@ public class WxMpStoreServiceImplTest { /** * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpStoreServiceImpl#add(me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo)}. + * * @throws WxErrorException */ public void testAdd() throws WxErrorException { this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build()); this.wxMpService.getStoreService() - .add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc") - .province("aaa").district("aaa").telephone("122").address("abc").categories(new String[] { "美食,江浙菜" }) - .longitude(new BigDecimal("115.32375")) - .latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1) - .build()); + .add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc") + .province("aaa").district("aaa").telephone("122").address("abc").categories(new String[]{"美食,江浙菜"}) + .longitude(new BigDecimal("115.32375")) + .latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1) + .build()); } public void testUpdate() throws WxErrorException { diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java index 28932362..2c348702 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java @@ -2,17 +2,16 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.template.WxMpTemplate; import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; import org.apache.commons.lang3.RandomStringUtils; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.text.SimpleDateFormat; import java.util.Date; @@ -39,7 +38,7 @@ public class WxMpTemplateMsgServiceImplTest { .toUser(configStorage.getOpenid()) .templateId(configStorage.getTemplateId()).build(); templateMessage.addWxMpTemplateData( - new WxMpTemplateData("first", dateFormat.format(new Date()),"#FF00FF")); + new WxMpTemplateData("first", dateFormat.format(new Date()), "#FF00FF")); templateMessage.addWxMpTemplateData( new WxMpTemplateData("remark", RandomStringUtils.randomAlphanumeric(100), "#FF00FF")); templateMessage.setUrl(" "); @@ -58,7 +57,7 @@ public class WxMpTemplateMsgServiceImplTest { @Test public void testSetIndustry() throws Exception { WxMpTemplateIndustry industry = new WxMpTemplateIndustry(new WxMpTemplateIndustry.Industry("1"), - new WxMpTemplateIndustry.Industry("04")); + new WxMpTemplateIndustry.Industry("04")); boolean result = this.wxService.getTemplateMsgService().setIndustry(industry); Assert.assertTrue(result); } 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 index 14796f9c..528ca290 100644 --- 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 @@ -1,12 +1,11 @@ package me.chanjar.weixin.mp.api.impl; -import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import javax.inject.Inject; import java.util.ArrayList; 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 3163ed69..09ba9e99 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 @@ -1,23 +1,18 @@ - package me.chanjar.weixin.mp.api.impl; -import java.util.ArrayList; -import java.util.List; - -import me.chanjar.weixin.mp.api.WxMpService; -import org.testng.Assert; -import org.testng.annotations.BeforeTest; -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.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.WxMpUserQuery; import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.result.WxMpUserList; +import org.testng.*; +import org.testng.annotations.*; + +import java.util.ArrayList; +import java.util.List; /** * 测试用户相关的接口 @@ -37,17 +32,17 @@ public class WxMpUserServiceImplTest { @BeforeTest public void setup() { this.configProvider = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); + .getWxMpConfigStorage(); } public void testUserUpdateRemark() throws WxErrorException { this.wxService.getUserService() - .userUpdateRemark(this.configProvider.getOpenid(), "测试备注名"); + .userUpdateRemark(this.configProvider.getOpenid(), "测试备注名"); } public void testUserInfo() throws WxErrorException { WxMpUser user = this.wxService.getUserService() - .userInfo(this.configProvider.getOpenid(), null); + .userInfo(this.configProvider.getOpenid(), null); Assert.assertNotNull(user); System.out.println(user); } @@ -56,7 +51,7 @@ public class WxMpUserServiceImplTest { List openids = new ArrayList<>(); openids.add(this.configProvider.getOpenid()); List userList = this.wxService.getUserService() - .userInfoList(openids); + .userInfoList(openids); Assert.assertEquals(userList.size(), 1); System.out.println(userList); } @@ -65,7 +60,7 @@ public class WxMpUserServiceImplTest { WxMpUserQuery query = new WxMpUserQuery(); query.add(this.configProvider.getOpenid(), "zh_CN"); List userList = this.wxService.getUserService() - .userInfoList(query); + .userInfoList(query); Assert.assertEquals(userList.size(), 1); System.out.println(userList); } 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 54743ac4..cc8676d4 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,21 +1,17 @@ package me.chanjar.weixin.mp.api.impl; -import java.util.List; - -import me.chanjar.weixin.mp.api.WxMpService; -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.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.tag.WxTagListUser; import me.chanjar.weixin.mp.bean.tag.WxUserTag; +import org.testng.*; +import org.testng.annotations.*; + +import java.util.List; /** - * * @author binarywang(Binary Wang) * Created by Binary Wang on 2016/9/2. */ @@ -43,7 +39,7 @@ public class WxMpUserTagServiceImplTest { Assert.assertNotNull(res); } - @Test(dependsOnMethods = { "testTagCreate" }) + @Test(dependsOnMethods = {"testTagCreate"}) public void testTagUpdate() throws Exception { String tagName = "修改标签" + System.currentTimeMillis(); Boolean res = this.wxService.getUserTagService().tagUpdate(this.tagId, tagName); @@ -51,7 +47,7 @@ public class WxMpUserTagServiceImplTest { Assert.assertTrue(res); } - @Test(dependsOnMethods = { "testTagCreate" }) + @Test(dependsOnMethods = {"testTagCreate"}) public void testTagDelete() throws Exception { Boolean res = this.wxService.getUserTagService().tagDelete(this.tagId); System.out.println(res); @@ -84,7 +80,7 @@ public class WxMpUserTagServiceImplTest { @Test public void testUserTagList() throws Exception { List res = this.wxService.getUserTagService().userTagList( - ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); + ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); System.out.println(res); Assert.assertNotNull(res); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java index 9f19029e..c25c5024 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java @@ -2,8 +2,8 @@ package me.chanjar.weixin.mp.bean.kefu; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage.WxArticle; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpKefuMessageTest { @@ -77,13 +77,13 @@ public class WxMpKefuMessageTest { public void testMusicBuild() { WxMpKefuMessage reply = WxMpKefuMessage.MUSIC() - .toUser("OPENID") - .title("TITLE") - .thumbMediaId("MEDIA_ID") - .description("DESCRIPTION") - .musicUrl("MUSIC_URL") - .hqMusicUrl("HQ_MUSIC_URL") - .build(); + .toUser("OPENID") + .title("TITLE") + .thumbMediaId("MEDIA_ID") + .description("DESCRIPTION") + .musicUrl("MUSIC_URL") + .hqMusicUrl("HQ_MUSIC_URL") + .build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfListTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfListTest.java index 0f52ae02..282890e0 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfListTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfListTest.java @@ -1,36 +1,36 @@ package me.chanjar.weixin.mp.bean.kefu.result; import org.apache.commons.lang3.builder.ToStringBuilder; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpKfListTest { public void testFromJson() { - String json=" {\r\n" + - " \"kf_list\" : [\r\n" + - " {\r\n" + - " \"kf_account\" : \"test1@test\",\r\n" + - " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + - " \"kf_id\" : \"1001\",\r\n" + - " \"kf_nick\" : \"ntest1\"\r\n" + - " },\r\n" + - " {\r\n" + - " \"kf_account\" : \"test2@test\",\r\n" + - " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + - " \"kf_id\" : \"1002\",\r\n" + - " \"kf_nick\" : \"ntest2\"\r\n" + - " },\r\n" + - " {\r\n" + - " \"kf_account\" : \"test3@test\",\r\n" + - " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + - " \"kf_id\" : \"1003\",\r\n" + - " \"kf_nick\" : \"ntest3\"\r\n" + - " }\r\n" + - " ]\r\n" + - " }"; - + String json = " {\r\n" + + " \"kf_list\" : [\r\n" + + " {\r\n" + + " \"kf_account\" : \"test1@test\",\r\n" + + " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + + " \"kf_id\" : \"1001\",\r\n" + + " \"kf_nick\" : \"ntest1\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"kf_account\" : \"test2@test\",\r\n" + + " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + + " \"kf_id\" : \"1002\",\r\n" + + " \"kf_nick\" : \"ntest2\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"kf_account\" : \"test3@test\",\r\n" + + " \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + + " \"kf_id\" : \"1003\",\r\n" + + " \"kf_nick\" : \"ntest3\"\r\n" + + " }\r\n" + + " ]\r\n" + + " }"; + WxMpKfList wxMpKfList = WxMpKfList.fromJson(json); Assert.assertNotNull(wxMpKfList); System.err.println(ToStringBuilder.reflectionToString(wxMpKfList)); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineListTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineListTest.java index fa514aba..daf98ab1 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineListTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineListTest.java @@ -1,34 +1,32 @@ package me.chanjar.weixin.mp.bean.kefu.result; import org.apache.commons.lang3.builder.ToStringBuilder; -import org.testng.Assert; -import org.testng.annotations.Test; - -import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpKfOnlineListTest { @Test public void testFromJson() { - String json = "{\r\n" + - " \"kf_online_list\": [\r\n" + - " {\r\n" + - " \"kf_account\": \"test1@test\", \r\n" + - " \"status\": 1, \r\n" + - " \"kf_id\": \"1001\", \r\n" + - " \"auto_accept\": 0, \r\n" + - " \"accepted_case\": 1\r\n" + - " },\r\n" + - " {\r\n" + - " \"kf_account\": \"test2@test\", \r\n" + - " \"status\": 1, \r\n" + - " \"kf_id\": \"1002\", \r\n" + - " \"auto_accept\": 0, \r\n" + - " \"accepted_case\": 2\r\n" + - " }\r\n" + - " ]\r\n" + - "}"; + String json = "{\r\n" + + " \"kf_online_list\": [\r\n" + + " {\r\n" + + " \"kf_account\": \"test1@test\", \r\n" + + " \"status\": 1, \r\n" + + " \"kf_id\": \"1001\", \r\n" + + " \"auto_accept\": 0, \r\n" + + " \"accepted_case\": 1\r\n" + + " },\r\n" + + " {\r\n" + + " \"kf_account\": \"test2@test\", \r\n" + + " \"status\": 1, \r\n" + + " \"kf_id\": \"1002\", \r\n" + + " \"auto_accept\": 0, \r\n" + + " \"accepted_case\": 2\r\n" + + " }\r\n" + + " ]\r\n" + + "}"; WxMpKfOnlineList wxMpKfOnlineList = WxMpKfOnlineList.fromJson(json); Assert.assertNotNull(wxMpKfOnlineList); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java index 23de3fe6..bbb8ce83 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java @@ -1,8 +1,8 @@ package me.chanjar.weixin.mp.bean.message; import me.chanjar.weixin.common.api.WxConsts; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlMessageTest { diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessageTest.java index 3addedb5..ab732c31 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutImageMessageTest { @@ -14,12 +14,12 @@ public class WxMpXmlOutImageMessageTest { m.setToUserName("to"); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } @@ -27,22 +27,22 @@ public class WxMpXmlOutImageMessageTest { public void testBuild() { WxMpXmlOutImageMessage m = WxMpXmlOutMessage.IMAGE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m - .toXml() - .replaceAll("\\s", "") - .replaceAll(".*?", ""), - expected - .replaceAll("\\s", "") - .replaceAll(".*?", "") - ); + m + .toXml() + .replaceAll("\\s", "") + .replaceAll(".*?", ""), + expected + .replaceAll("\\s", "") + .replaceAll(".*?", "") + ); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java index 3e7a96f0..f75e6321 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutMusicMessageTest { @@ -18,55 +18,55 @@ public class WxMpXmlOutMusicMessageTest { m.setToUserName("toUser"); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + ""; + + "" + + "" + + "1122" + + "" + + "" + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } public void testBuild() { WxMpXmlOutMusicMessage m = WxMpXmlOutMessage.MUSIC() - .fromUser("fromUser") - .toUser("toUser") - .title("title") - .description("ddfff") - .hqMusicUrl("hQMusicUrl") - .musicUrl("musicUrl") - .thumbMediaId("thumbMediaId") - .build(); + .fromUser("fromUser") + .toUser("toUser") + .title("title") + .description("ddfff") + .hqMusicUrl("hQMusicUrl") + .musicUrl("musicUrl") + .thumbMediaId("thumbMediaId") + .build(); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + ""; + + "" + + "" + + "1122" + + "" + + "" + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m + m .toXml() .replaceAll("\\s", "") .replaceAll(".*?", ""), - expected + expected .replaceAll("\\s", "") .replaceAll(".*?", "") - ); + ); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessageTest.java index 60d8571a..c9a1f982 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutNewsMessageTest { @@ -20,26 +20,26 @@ public class WxMpXmlOutNewsMessageTest { m.addArticle(item); m.addArticle(item); String expected = "" - + "" - + "" - + "1122" - + "" - + " 2" - + " " - + " " - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + ""; + + "" + + "" + + "1122" + + "" + + " 2" + + " " + + " " + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } @@ -52,42 +52,42 @@ public class WxMpXmlOutNewsMessageTest { item.setUrl("url"); WxMpXmlOutNewsMessage m = WxMpXmlOutMessage.NEWS() - .fromUser("fromUser") - .toUser("toUser") - .addArticle(item) - .addArticle(item) - .build(); + .fromUser("fromUser") + .toUser("toUser") + .addArticle(item) + .addArticle(item) + .build(); String expected = "" - + "" - + "" - + "1122" - + "" - + " 2" - + " " - + " " - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + " <![CDATA[title]]>" - + " " - + " " - + " " - + " " - + " " - + ""; + + "" + + "" + + "1122" + + "" + + " 2" + + " " + + " " + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + " <![CDATA[title]]>" + + " " + + " " + + " " + + " " + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m + m .toXml() .replaceAll("\\s", "") .replaceAll(".*?", ""), - expected + expected .replaceAll("\\s", "") .replaceAll(".*?", "") - ); + ); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessageTest.java index 56658967..c005c261 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutTextMessageTest { @@ -14,12 +14,12 @@ public class WxMpXmlOutTextMessageTest { m.setToUserName("to"); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } @@ -27,22 +27,22 @@ public class WxMpXmlOutTextMessageTest { public void testBuild() { WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content("content").fromUser("from").toUser("to").build(); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m + m .toXml() .replaceAll("\\s", "") .replaceAll(".*?", ""), - expected + expected .replaceAll("\\s", "") .replaceAll(".*?", "") - ); + ); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessageTest.java index 222f563f..97dfdd96 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; /** * Created by ben on 2015/12/29. diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessageTest.java index 0c53b28a..2ba9f549 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutVideoMessageTest { @@ -16,49 +16,49 @@ public class WxMpXmlOutVideoMessageTest { m.setToUserName("toUser"); String expected = "" - + "" - + "" - + "1122" - + "" - + " " - + ""; + + "" + + "" + + "1122" + + "" + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } public void testBuild() { WxMpXmlOutVideoMessage m = WxMpXmlOutMessage.VIDEO() - .mediaId("media_id") - .fromUser("fromUser") - .toUser("toUser") - .title("title") - .description("ddfff") - .build(); + .mediaId("media_id") + .fromUser("fromUser") + .toUser("toUser") + .title("title") + .description("ddfff") + .build(); String expected = "" - + "" - + "" - + "1122" - + "" - + " " - + ""; + + "" + + "" + + "1122" + + "" + + " " + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m + m .toXml() .replaceAll("\\s", "") .replaceAll(".*?", ""), - expected + expected .replaceAll("\\s", "") .replaceAll(".*?", "") - ); + ); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessageTest.java index 34314390..d3f1346f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessageTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.message; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; @Test public class WxMpXmlOutVoiceMessageTest { @@ -14,12 +14,12 @@ public class WxMpXmlOutVoiceMessageTest { m.setToUserName("to"); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); } @@ -27,22 +27,22 @@ public class WxMpXmlOutVoiceMessageTest { public void testBuild() { WxMpXmlOutVoiceMessage m = WxMpXmlOutMessage.VOICE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); String expected = "" - + "" - + "" - + "1122" - + "" - + "" - + ""; + + "" + + "" + + "1122" + + "" + + "" + + ""; System.out.println(m.toXml()); Assert.assertEquals( - m + m .toXml() .replaceAll("\\s", "") .replaceAll(".*?", ""), - expected + expected .replaceAll("\\s", "") .replaceAll(".*?", "") - ); + ); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java index 0b1e7ac9..aaab37a2 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResultTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.pay.result; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; import java.util.Map; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java index 1582ea17..e0fd9808 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResultTest.java @@ -1,7 +1,7 @@ package me.chanjar.weixin.mp.bean.pay.result; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.testng.*; +import org.testng.annotations.*; /** *
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java
    index 34672417..6b8a9ae9 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundQueryResultTest.java
    @@ -1,8 +1,8 @@
     package me.chanjar.weixin.mp.bean.pay.result;
     
     
    -import org.testng.Assert;
    -import org.testng.annotations.Test;
    +import org.testng.*;
    +import org.testng.annotations.*;
     
     /**
      * 
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResultTest.java
    index a07ec972..f2aa0a94 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResultTest.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResultTest.java
    @@ -2,9 +2,8 @@ package me.chanjar.weixin.mp.bean.pay.result;
     
     import com.thoughtworks.xstream.XStream;
     import me.chanjar.weixin.common.util.xml.XStreamInitializer;
    -import org.testng.Assert;
    -import org.testng.annotations.BeforeTest;
    -import org.testng.annotations.Test;
    +import org.testng.*;
    +import org.testng.annotations.*;
     
     public class WxPaySendRedpackResultTest {
     
    @@ -12,26 +11,26 @@ public class WxPaySendRedpackResultTest {
     
       @BeforeTest
       public void setup() {
    -     this.xstream = XStreamInitializer.getInstance();
    -     this.xstream.processAnnotations(WxPaySendRedpackResult.class);
    +    this.xstream = XStreamInitializer.getInstance();
    +    this.xstream.processAnnotations(WxPaySendRedpackResult.class);
       }
     
       @Test
       public void loadSuccessResult() {
         final String successSample = "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "10010404\n" +
    -        "\n" +
    -        "\n" +
    -        "1\n" +
    -        "100000000020150520314766074200\n" +
    -        "20150520102602\n" +
    -        "";
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "10010404\n" +
    +      "\n" +
    +      "\n" +
    +      "1\n" +
    +      "100000000020150520314766074200\n" +
    +      "20150520102602\n" +
    +      "";
         WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(successSample);
         Assert.assertEquals("SUCCESS", wxMpRedpackResult.getReturnCode());
         Assert.assertEquals("SUCCESS", wxMpRedpackResult.getResultCode());
    @@ -41,17 +40,17 @@ public class WxPaySendRedpackResultTest {
       @Test
       public void loadFailureResult() {
         final String failureSample = "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "\n" +
    -        "10010404\n" +
    -        "\n" +
    -        "\n" +
    -        "1\n" +
    -        "";
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "\n" +
    +      "10010404\n" +
    +      "\n" +
    +      "\n" +
    +      "1\n" +
    +      "";
         WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(failureSample);
         Assert.assertEquals("FAIL", wxMpRedpackResult.getReturnCode());
         Assert.assertEquals("FAIL", wxMpRedpackResult.getResultCode());
    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 69636d0b..1743b1f9 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,9 +1,5 @@
     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;
    @@ -14,6 +10,10 @@ import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
     import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
     import me.chanjar.weixin.mp.bean.message.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();
    @@ -35,7 +35,7 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa
     
       @Override
       public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService,
    -      WxSessionManager sessionManager) throws WxErrorException {
    +                                  WxSessionManager sessionManager) throws WxErrorException {
     
         if (isUserWantGuess(wxMessage)) {
           letsGo(wxMessage, wxMpService, sessionManager);
    @@ -53,17 +53,17 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa
         WxSession session = sessionManager.getSession(wxMessage.getFromUser());
         if (session.getAttribute("guessing") == null) {
           WxMpKefuMessage m = WxMpKefuMessage
    -          .TEXT()
    -          .toUser(wxMessage.getFromUser())
    -          .content("请猜一个100以内的数字")
    -          .build();
    +        .TEXT()
    +        .toUser(wxMessage.getFromUser())
    +        .content("请猜一个100以内的数字")
    +        .build();
           wxMpService.getKefuService().sendKefuMessage(m);
         } else {
           WxMpKefuMessage m = WxMpKefuMessage
    -          .TEXT()
    -          .toUser(wxMessage.getFromUser())
    -          .content("放弃了吗?那请重新猜一个100以内的数字")
    -          .build();
    +        .TEXT()
    +        .toUser(wxMessage.getFromUser())
    +        .content("放弃了吗?那请重新猜一个100以内的数字")
    +        .build();
           wxMpService.getKefuService().sendKefuMessage(m);
         }
     
    @@ -88,25 +88,25 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa
         int guessNumber = Integer.valueOf(wxMessage.getContent());
         if (guessNumber < answer) {
           WxMpKefuMessage m = WxMpKefuMessage
    -          .TEXT()
    -          .toUser(wxMessage.getFromUser())
    -          .content("小了")
    -          .build();
    +        .TEXT()
    +        .toUser(wxMessage.getFromUser())
    +        .content("小了")
    +        .build();
           wxMpService.getKefuService().sendKefuMessage(m);
     
         } else if (guessNumber > answer) {
           WxMpKefuMessage m = WxMpKefuMessage
    -          .TEXT()
    -          .toUser(wxMessage.getFromUser())
    -          .content("大了")
    -          .build();
    +        .TEXT()
    +        .toUser(wxMessage.getFromUser())
    +        .content("大了")
    +        .build();
           wxMpService.getKefuService().sendKefuMessage(m);
         } else {
           WxMpKefuMessage m = WxMpKefuMessage
    -          .TEXT()
    -          .toUser(wxMessage.getFromUser())
    -          .content("Bingo!")
    -          .build();
    +        .TEXT()
    +        .toUser(wxMessage.getFromUser())
    +        .content("Bingo!")
    +        .build();
           session.removeAttribute("guessing");
           wxMpService.getKefuService().sendKefuMessage(m);
         }
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java
    index 145a0130..2cfb8ce3 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java
    @@ -15,17 +15,17 @@ import java.util.Map;
     public class DemoImageHandler implements WxMpMessageHandler {
       @Override
       public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context,
    -      WxMpService wxMpService, WxSessionManager sessionManager) {
    +                                  WxMpService wxMpService, WxSessionManager sessionManager) {
         try {
           WxMediaUploadResult wxMediaUploadResult = wxMpService.getMaterialService()
    -          .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, ClassLoader.getSystemResourceAsStream("mm.jpeg"));
    +        .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, ClassLoader.getSystemResourceAsStream("mm.jpeg"));
           WxMpXmlOutImageMessage m
    -          = WxMpXmlOutMessage
    -          .IMAGE()
    -          .mediaId(wxMediaUploadResult.getMediaId())
    -          .fromUser(wxMessage.getToUser())
    -          .toUser(wxMessage.getFromUser())
    -          .build();
    +        = WxMpXmlOutMessage
    +        .IMAGE()
    +        .mediaId(wxMediaUploadResult.getMediaId())
    +        .fromUser(wxMessage.getToUser())
    +        .toUser(wxMessage.getFromUser())
    +        .build();
           return m;
         } catch (WxErrorException e) {
           e.printStackTrace();
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java
    index 8e38b3f7..7eb684f9 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java
    @@ -14,7 +14,7 @@ import java.util.Map;
     public class DemoLogHandler implements WxMpMessageHandler {
       @Override
       public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService,
    -      WxSessionManager sessionManager) {
    +                                  WxSessionManager sessionManager) {
         System.out.println(wxMessage.toString());
         return null;
       }
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java
    index 82046452..6460f851 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java
    @@ -15,13 +15,13 @@ import java.util.Map;
     public class DemoOAuth2Handler implements WxMpMessageHandler {
       @Override
       public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
    -      Map context, WxMpService wxMpService,
    -      WxSessionManager sessionManager) {
    +                                  Map context, WxMpService wxMpService,
    +                                  WxSessionManager sessionManager) {
         String href = "测试oauth2";
    +      wxMpService.getWxMpConfigStorage().getOauth2redirectUri(),
    +      WxConsts.OAUTH2_SCOPE_USER_INFO, null) + "\">测试oauth2";
         return WxMpXmlOutMessage.TEXT().content(href)
    -        .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
    -        .build();
    +      .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
    +      .build();
       }
     }
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java
    index 5934eff2..c4540433 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java
    @@ -15,10 +15,10 @@ import java.util.Map;
     public class DemoTextHandler implements WxMpMessageHandler {
       @Override
       public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context,
    -      WxMpService wxMpService, WxSessionManager sessionManager) {
    +                                  WxMpService wxMpService, WxSessionManager sessionManager) {
         WxMpXmlOutTextMessage m
    -        = WxMpXmlOutMessage.TEXT().content("测试加密消息").fromUser(wxMessage.getToUser())
    -        .toUser(wxMessage.getFromUser()).build();
    +      = WxMpXmlOutMessage.TEXT().content("测试加密消息").fromUser(wxMessage.getToUser())
    +      .toUser(wxMessage.getFromUser()).build();
         return m;
       }
     
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoInMemoryConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoInMemoryConfigStorage.java
    index 44b80647..e42a192b 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoInMemoryConfigStorage.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoInMemoryConfigStorage.java
    @@ -13,17 +13,16 @@ import java.io.InputStream;
     @XStreamAlias("xml")
     class WxMpDemoInMemoryConfigStorage extends WxMpInMemoryConfigStorage {
     
    -  @Override
    -  public String toString() {
    -    return "SimpleWxConfigProvider [appId=" + this.appId + ", secret=" + this.secret + ", accessToken=" + this.accessToken
    -        + ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]";
    -  }
    -
    -
       public static WxMpDemoInMemoryConfigStorage fromXml(InputStream is) {
         XStream xstream = XStreamInitializer.getInstance();
         xstream.processAnnotations(WxMpDemoInMemoryConfigStorage.class);
         return (WxMpDemoInMemoryConfigStorage) xstream.fromXML(is);
       }
     
    +  @Override
    +  public String toString() {
    +    return "SimpleWxConfigProvider [appId=" + this.appId + ", secret=" + this.secret + ", accessToken=" + this.accessToken
    +      + ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]";
    +  }
    +
     }
    diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java
    index 98b8d0cc..1c189376 100644
    --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java
    +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java
    @@ -1,18 +1,17 @@
     package me.chanjar.weixin.mp.demo;
     
    -import java.io.IOException;
    -import java.io.InputStream;
    -
    -import org.eclipse.jetty.server.Server;
    -import org.eclipse.jetty.servlet.ServletHandler;
    -import org.eclipse.jetty.servlet.ServletHolder;
    -
     import me.chanjar.weixin.common.api.WxConsts;
     import me.chanjar.weixin.mp.api.WxMpConfigStorage;
     import me.chanjar.weixin.mp.api.WxMpMessageHandler;
     import me.chanjar.weixin.mp.api.WxMpMessageRouter;
     import me.chanjar.weixin.mp.api.WxMpService;
     import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
    +import org.eclipse.jetty.server.Server;
    +import org.eclipse.jetty.servlet.ServletHandler;
    +import org.eclipse.jetty.servlet.ServletHolder;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
     
     public class WxMpDemoServer {
     
    @@ -29,12 +28,12 @@ public class WxMpDemoServer {
         server.setHandler(servletHandler);
     
         ServletHolder endpointServletHolder = new ServletHolder(
    -        new WxMpEndpointServlet(wxMpConfigStorage, wxMpService,
    -            wxMpMessageRouter));
    +      new WxMpEndpointServlet(wxMpConfigStorage, wxMpService,
    +        wxMpMessageRouter));
         servletHandler.addServletWithMapping(endpointServletHolder, "/*");
     
         ServletHolder oauthServletHolder = new ServletHolder(
    -        new WxMpOAuth2Servlet(wxMpService));
    +      new WxMpOAuth2Servlet(wxMpService));
         servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*");
     
         server.start();
    @@ -43,9 +42,9 @@ public class WxMpDemoServer {
     
       private static void initWeixin() {
         try (InputStream is1 = ClassLoader
    -        .getSystemResourceAsStream("test-config.xml")) {
    +      .getSystemResourceAsStream("test-config.xml")) {
           WxMpDemoInMemoryConfigStorage config = WxMpDemoInMemoryConfigStorage
    -          .fromXml(is1);
    +        .fromXml(is1);
     
           wxMpConfigStorage = config;
           wxMpService = new WxMpServiceImpl();
    @@ -59,11 +58,11 @@ public class WxMpDemoServer {
     
           wxMpMessageRouter = new WxMpMessageRouter(wxMpService);
           wxMpMessageRouter.rule().handler(logHandler).next().rule()
    -          .msgType(WxConsts.XML_MSG_TEXT).matcher(guessNumberHandler)
    -          .handler(guessNumberHandler).end().rule().async(false).content("哈哈")
    -          .handler(textHandler).end().rule().async(false).content("图片")
    -          .handler(imageHandler).end().rule().async(false).content("oauth")
    -          .handler(oauth2handler).end();
    +        .msgType(WxConsts.XML_MSG_TEXT).matcher(guessNumberHandler)
    +        .handler(guessNumberHandler).end().rule().async(false).content("哈哈")
    +        .handler(textHandler).end().rule().async(false).content("图片")
    +        .handler(imageHandler).end().rule().async(false).content("oauth")
    +        .handler(oauth2handler).end();
         } catch (IOException e) {
           e.printStackTrace();
         }
    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 4a6fd85b..3f32d9c9 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
    @@ -23,7 +23,7 @@ public class WxMpEndpointServlet extends HttpServlet {
       protected WxMpMessageRouter wxMpMessageRouter;
     
       public WxMpEndpointServlet(WxMpConfigStorage wxMpConfigStorage, WxMpService wxMpService,
    -      WxMpMessageRouter wxMpMessageRouter) {
    +                             WxMpMessageRouter wxMpMessageRouter) {
         this.wxMpConfigStorage = wxMpConfigStorage;
         this.wxMpService = wxMpService;
         this.wxMpMessageRouter = wxMpMessageRouter;
    @@ -31,7 +31,7 @@ public class WxMpEndpointServlet extends HttpServlet {
     
       @Override
       protected void service(HttpServletRequest request, HttpServletResponse response)
    -      throws IOException {
    +    throws IOException {
     
         response.setContentType("text/html;charset=utf-8");
         response.setStatus(HttpServletResponse.SC_OK);
    @@ -54,8 +54,8 @@ public class WxMpEndpointServlet extends HttpServlet {
         }
     
         String encryptType = StringUtils.isBlank(request.getParameter("encrypt_type")) ?
    -        "raw" :
    -        request.getParameter("encrypt_type");
    +      "raw" :
    +      request.getParameter("encrypt_type");
     
         if ("raw".equals(encryptType)) {
           // 明文传输的消息
    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 8eeb9052..e739a936 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
    @@ -1,16 +1,15 @@
     package me.chanjar.weixin.mp.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.exception.WxErrorException;
     import me.chanjar.weixin.mp.api.WxMpService;
     import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
     import me.chanjar.weixin.mp.bean.result.WxMpUser;
     
    +import javax.servlet.http.HttpServlet;
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +import java.io.IOException;
    +
     public class WxMpOAuth2Servlet extends HttpServlet {
       private static final long serialVersionUID = 1L;
     
    @@ -22,7 +21,7 @@ public class WxMpOAuth2Servlet extends HttpServlet {
     
       @Override
       protected void service(HttpServletRequest request, HttpServletResponse response)
    -      throws IOException {
    +    throws IOException {
     
         response.setContentType("text/html;charset=utf-8");
         response.setStatus(HttpServletResponse.SC_OK);
    
    From 28b4d896d64b7b4bdb2c02a5703d2f2a227f9fdf Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Tue, 7 Feb 2017 10:54:02 +0800
    Subject: [PATCH 68/76] Update README.md
    
    ---
     README.md | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/README.md b/README.md
    index cc427f39..b43f4c0f 100644
    --- a/README.md
    +++ b/README.md
    @@ -17,7 +17,7 @@ Weixin Java Tools —— 微信公众号&企业号开发 Java SDK
     ===========
     
     ## SDK使用交流方式说明:
    -1. QQ群: [![Join QQ Group](https://img.shields.io/badge/QQ群-343954419-blue.svg)](http://shang.qq.com/wpa/qunwpa?idkey=731dc3e7ea31ebe25376cc1a791445468612c63fd0e9e05399b088ec81fd9e15) 或 [![Join QQ Group](https://img.shields.io/badge/QQ群-343954419-blue.svg)](http://jq.qq.com/?_wv=1027&k=40lRskK),推荐点击按钮入群,当然如果无法成功操作,请自行搜索群号343954419进行添加 )
    +1. QQ群: [![加入QQ群](https://img.shields.io/badge/QQ群-343954419-blue.svg)](http://shang.qq.com/wpa/qunwpa?idkey=731dc3e7ea31ebe25376cc1a791445468612c63fd0e9e05399b088ec81fd9e15) 或 [![加入QQ群](https://img.shields.io/badge/QQ群-343954419-blue.svg)](http://jq.qq.com/?_wv=1027&k=40lRskK),推荐点击按钮入群,当然如果无法成功操作,请自行搜索群号343954419进行添加 )
     1. 由于群容量有限,即将爆满,故开启付费入群模式以保证只有真实交流需求的人进入,并为保证群的活跃度,将不定期清理长时间不活跃的同学;
     1. 微信群: 因微信群已达到100人限制,故如有想加入微信群的,请入QQ群后联系管理员,提供微信号以便邀请加入;
     1. 新手提问前,请先阅读此文章:http://t.cn/RV93MRB
    
    From 6c9afe8a8aae3fac4bb4ca98ee79cbaff03c8fbf Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Thu, 9 Feb 2017 22:53:23 +0800
    Subject: [PATCH 69/76] =?UTF-8?q?=E4=BF=AE=E5=A4=8DWxMenuRule=E4=B8=80?=
     =?UTF-8?q?=E4=B8=AA=E5=8F=98=E6=80=81=E5=B1=9E=E6=80=A7=E7=9A=84=E9=97=AE?=
     =?UTF-8?q?=E9=A2=98=20#136?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     .../common/util/json/WxMenuGsonAdapter.java      | 16 +++++++++-------
     .../weixin/mp/api/impl/WxMpMenuServiceImpl.java  |  3 +--
     2 files changed, 10 insertions(+), 9 deletions(-)
    
    diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    index eaaeec74..578aa41c 100644
    --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
    @@ -70,13 +70,15 @@ public class WxMenuGsonAdapter implements JsonSerializer, JsonDeserializ
     
       private WxMenuRule convertToRule(JsonObject json) {
         WxMenuRule menuRule = new WxMenuRule();
    -    menuRule.setTagId(GsonHelper.getString(json,"tag_id"));
    -    menuRule.setSex(GsonHelper.getString(json,"sex"));
    -    menuRule.setCountry(GsonHelper.getString(json,"country"));
    -    menuRule.setProvince(GsonHelper.getString(json,"province"));
    -    menuRule.setCity(GsonHelper.getString(json,"city"));
    -    menuRule.setClientPlatformType(GsonHelper.getString(json,"client_platform_type"));
    -    menuRule.setLanguage(GsonHelper.getString(json,"language"));
    +    //变态的微信接口,这里居然反人类的使用和序列化时不一样的名字
    +    //menuRule.setTagId(GsonHelper.getString(json,"tag_id"));
    +    menuRule.setTagId(GsonHelper.getString(json, "group_id"));
    +    menuRule.setSex(GsonHelper.getString(json, "sex"));
    +    menuRule.setCountry(GsonHelper.getString(json, "country"));
    +    menuRule.setProvince(GsonHelper.getString(json, "province"));
    +    menuRule.setCity(GsonHelper.getString(json, "city"));
    +    menuRule.setClientPlatformType(GsonHelper.getString(json, "client_platform_type"));
    +    menuRule.setLanguage(GsonHelper.getString(json, "language"));
         return menuRule;
       }
     
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    index b28ac6a1..d22f4c82 100644
    --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java
    @@ -16,8 +16,7 @@ import org.slf4j.LoggerFactory;
      */
     public class WxMpMenuServiceImpl implements WxMpMenuService {
       private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/menu";
    -  private static Logger log = LoggerFactory
    -    .getLogger(WxMpMenuServiceImpl.class);
    +  private static Logger log = LoggerFactory.getLogger(WxMpMenuServiceImpl.class);
     
       private WxMpService wxMpService;
     
    
    From a5682cdfd926e383b7edbb816debac73b6675c78 Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Sun, 12 Feb 2017 13:44:55 +0800
    Subject: [PATCH 70/76] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=89=88=E6=9C=AC?=
     =?UTF-8?q?=E5=8F=B7=E4=B8=BA2.5.0=EF=BC=8C=E5=87=86=E5=A4=87=E5=8F=91?=
     =?UTF-8?q?=E5=B8=83=E6=96=B0=E7=9A=84=E6=AD=A3=E5=BC=8F=E7=89=88?=
    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-java-osgi/pom.xml   | 2 +-
     5 files changed, 5 insertions(+), 5 deletions(-)
    
    diff --git a/pom.xml b/pom.xml
    index a0dfd704..57ae6b92 100644
    --- a/pom.xml
    +++ b/pom.xml
    @@ -5,7 +5,7 @@
       4.0.0
       com.github.binarywang
       weixin-java-parent
    -  2.4.9.BETA
    +  2.5.0
       pom
       WeiXin Java Tools - Parent
       微信公众号、企业号上级POM
    diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml
    index a635fca9..12611c12 100644
    --- a/weixin-java-common/pom.xml
    +++ b/weixin-java-common/pom.xml
    @@ -6,7 +6,7 @@
       
         com.github.binarywang
         weixin-java-parent
    -    2.4.9.BETA
    +    2.5.0
       
     
       weixin-java-common
    diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
    index 26175c9c..6478ada2 100644
    --- a/weixin-java-cp/pom.xml
    +++ b/weixin-java-cp/pom.xml
    @@ -6,7 +6,7 @@
       
         com.github.binarywang
         weixin-java-parent
    -    2.4.9.BETA
    +    2.5.0
       
     
       weixin-java-cp
    diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
    index d595950e..7070d018 100644
    --- a/weixin-java-mp/pom.xml
    +++ b/weixin-java-mp/pom.xml
    @@ -6,7 +6,7 @@
       
         com.github.binarywang
         weixin-java-parent
    -    2.4.9.BETA
    +    2.5.0
       
       weixin-java-mp
       WeiXin Java Tools - MP
    diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml
    index 19cc0bb7..fbcfaba6 100644
    --- a/weixin-java-osgi/pom.xml
    +++ b/weixin-java-osgi/pom.xml
    @@ -6,7 +6,7 @@
       
         com.github.binarywang
         weixin-java-parent
    -    2.4.9.BETA
    +    2.5.0
       
     
       weixin-java-osgi
    
    From 8b0efdc99d81dc8c1ba322d18c10aa6ad508971d Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Sun, 12 Feb 2017 14:18:47 +0800
    Subject: [PATCH 71/76] Update README.md
    
    ---
     README.md | 10 +++++-----
     1 file changed, 5 insertions(+), 5 deletions(-)
    
    diff --git a/README.md b/README.md
    index b43f4c0f..967d4595 100644
    --- a/README.md
    +++ b/README.md
    @@ -5,7 +5,7 @@ Weixin Java Tools —— 微信公众号&企业号开发 Java SDK
     
     ### 注意事项:
     1. 声明: ***本项目Fork自chanjarster/weixin-java-tools,但由于原项目已停止维护,故单独维护和发布,且发布到maven上的groupId也会不同,详细信息见下文。***
    -1. 最新更新:**2016-11-30 发布[【2.4.0正式版】](https://github.com/Wechat-Group/weixin-java-tools/releases)**!
    +1. 最新更新:**2017-2-12 发布[【2.5.0正式版】](https://github.com/Wechat-Group/weixin-java-tools/releases)**!
     1. 开源中国网站的本项目首页链接地址:https://www.oschina.net/p/weixin-java-tools-new
     1. 自2.0.0版本以来,公众号的接口调整比较大,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。
     1. SDK详细开发文档请查阅 [【Wiki】](https://github.com/wechat-group/weixin-java-tools/wiki),部分文档可能未能及时更新,如有发现,可以及时上报或者自行修改。
    @@ -55,12 +55,12 @@ maven:
     
       com.github.binarywang
       weixin-java-mp
    -  2.4.0
    +  2.5.0
     
     ```
     gradle:
     ```groovy
    -compile 'com.github.binarywang:weixin-java-mp:2.4.0'
    +compile 'com.github.binarywang:weixin-java-mp:2.5.0'
     ```
     
     * 企业号:
    @@ -70,11 +70,11 @@ maven:
     
       com.github.binarywang
       weixin-java-cp
    -  2.4.0
    +  2.5.0
     
     ```
     gradle:
     ```groovy
    -compile 'com.github.binarywang:weixin-java-cp:2.4.0'
    +compile 'com.github.binarywang:weixin-java-cp:2.5.0'
     ```
     
    
    From 29763f3012e7941ff3db66fb04fb7fa0e0bd4256 Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Sun, 12 Feb 2017 14:26:31 +0800
    Subject: [PATCH 72/76] Update build.gradle
    
    ---
     build.gradle | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/build.gradle b/build.gradle
    index 49d71c34..e5231e24 100644
    --- a/build.gradle
    +++ b/build.gradle
    @@ -2,7 +2,7 @@ allprojects  {
       apply plugin: 'maven'
     
       group = 'com.github.binarywang'
    -  version = '2.5.0-SNAPSHOT'
    +  version = '2.5.0'
     }
     
     subprojects {
    
    From e296d237ebad5fa49effa37f8ab4a138a9e28393 Mon Sep 17 00:00:00 2001
    From: Binary Wang 
    Date: Mon, 13 Feb 2017 17:51:11 +0800
    Subject: [PATCH 73/76] minor updates
    
    ---
     .../main/java/me/chanjar/weixin/mp/api/WxMpPayService.java    | 4 ++--
     .../me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java     | 1 +
     2 files changed, 3 insertions(+), 2 deletions(-)
    
    diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java
    index 004cd5bc..543b59bd 100644
    --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java
    +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java
    @@ -28,7 +28,7 @@ public interface WxMpPayService {
        * 
    * * @param transactionId 微信订单号 - * @param outTradeNo 商户系统内部的订单号,当没提供transaction_id时需要传这个。 + * @param outTradeNo 商户系统内部的订单号,当没提供transactionId时需要传这个。 */ WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException; @@ -44,7 +44,7 @@ public interface WxMpPayService { * 是否需要证书: 不需要。 *
    * - * @param outTradeNo 商户系统内部的订单号,当没提供transaction_id时需要传这个。 + * @param outTradeNo 商户系统内部的订单号 */ WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorException; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java index b0ccacd9..4424e211 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java @@ -404,6 +404,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { WxPayCommonResult result = WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class); this.checkResult(result); + //TODO 待实现,暂时无测试帐号,无法调试 return null; } From b2b04609dbbb0b75e14783372e2904a4e932e5d9 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Mon, 13 Feb 2017 17:57:58 +0800 Subject: [PATCH 74/76] update version to 2.6.0-SNAPSHOT --- build.gradle | 2 +- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- weixin-java-osgi/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index e5231e24..e572c391 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ allprojects { apply plugin: 'maven' group = 'com.github.binarywang' - version = '2.5.0' + version = '2.6.0-SNAPSHOT' } subprojects { diff --git a/pom.xml b/pom.xml index 57ae6b92..c941dbc7 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.binarywang weixin-java-parent - 2.5.0 + 2.6.0-SNAPSHOT pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 12611c12..1d1ad69c 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.5.0 + 2.6.0-SNAPSHOT weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 6478ada2..e49f6c16 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.5.0 + 2.6.0-SNAPSHOT weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 7070d018..9cbea35a 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.5.0 + 2.6.0-SNAPSHOT weixin-java-mp WeiXin Java Tools - MP diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml index fbcfaba6..892870f0 100644 --- a/weixin-java-osgi/pom.xml +++ b/weixin-java-osgi/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang weixin-java-parent - 2.5.0 + 2.6.0-SNAPSHOT weixin-java-osgi From e2a19959633ad4780287d9f9bfc8fb7064fb9d07 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 14 Feb 2017 16:57:53 +0800 Subject: [PATCH 75/76] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E4=BC=81=E4=B8=9A=E7=BA=A2=E5=8C=85=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9A=E5=8F=91=E9=80=81=E7=BA=A2=E5=8C=85?= =?UTF-8?q?=E7=9A=84=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=9C=E4=B8=AD=EF=BC=8C?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E7=AD=BE=E5=90=8D=EF=BC=8C=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E8=BF=9B=E8=A1=8C=E7=AD=BE=E5=90=8D=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E3=80=82=20#140?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java index 4424e211..fae2d931 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java @@ -179,7 +179,8 @@ public class WxMpPayServiceImpl implements WxMpPayService { } String responseContent = this.executeWithKey(url, request.toXML()); WxPaySendRedpackResult result = WxPaySendRedpackResult.fromXML(responseContent, WxPaySendRedpackResult.class); - this.checkResult(result); + //毋须校验,因为没有返回签名信息 + // this.checkResult(result); return result; } From 00c2aae212d947f20d4193d19e3e16698be61ebd Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 19 Feb 2017 18:17:48 +0800 Subject: [PATCH 76/76] small update for a test method --- .../me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java index 42819b2f..51b80e36 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java @@ -93,7 +93,7 @@ public class WxMpMenuServiceImplTest { } @Test - public void testCreateMenu2() throws WxErrorException { + public void testCreateMenu_by_json() throws WxErrorException { String a = "{\n" + " \"menu\": {\n" + " \"button\": [\n"