, JsonSeri
}
switch (attr.getType()) {
- case 0: {
- JsonObject text = new JsonObject();
- text.addProperty("value", attr.getValue());
- attrJson.add("text", text);
+ case 0:
+ attrJson.add("text", GsonHelper.buildJsonObject("value", attr.getValue()));
break;
- }
- case 1: {
- JsonObject web = new JsonObject();
- web.addProperty("url", attr.getUrl());
- web.addProperty("title", attr.getTitle());
- attrJson.add("web", web);
+ case 1:
+ attrJson.add("web", GsonHelper.buildJsonObject("url", attr.getUrl(), "title", attr.getTitle()));
break;
- }
- case 2: {
- JsonObject miniprogram = new JsonObject();
- miniprogram.addProperty("appid", attr.getAppid());
- miniprogram.addProperty("pagepath", attr.getPagePath());
- miniprogram.addProperty("title", attr.getTitle());
- attrJson.add("miniprogram", miniprogram);
+ case 2:
+ attrJson.add("miniprogram", GsonHelper.buildJsonObject("appid", attr.getAppid(),
+ "pagepath", attr.getPagePath(), "title", attr.getTitle()));
break;
- }
default://忽略
}
}
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java
index d78175c1b..a83e8837d 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java
@@ -91,7 +91,7 @@ public class WxCpUserGsonAdapterTest {
assertThat(user).isNotNull();
assertThat(user.getOrders()).isNotEmpty();
- assertThat(user.getOrders().length).isEqualTo(2);
+ assertThat(user.getOrders()).hasSize(2);
assertThat(user.getOrders()[0]).isEqualTo(1);
assertThat(user.getOrders()[1]).isEqualTo(2);
@@ -140,6 +140,12 @@ public class WxCpUserGsonAdapterTest {
public void testSerialize() {
WxCpUser user = new WxCpUser();
user.setOrders(new Integer[]{1, 2});
+ user.addExtAttr(WxCpUser.Attr.builder()
+ .type(0)
+ .name("文本名称")
+ .textValue("文本")
+ .build());
+
user.addExternalAttr(WxCpUser.ExternalAttribute.builder()
.type(0)
.name("文本名称")
@@ -159,7 +165,9 @@ public class WxCpUserGsonAdapterTest {
.title("my miniprogram")
.build());
- assertThat(user.toJson()).isEqualTo("{\"order\":[1,2],\"external_profile\":{\"external_attr\":" +
+ assertThat(user.toJson()).isEqualTo("{\"order\":[1,2]," +
+ "\"extattr\":{\"attrs\":[{\"type\":0,\"name\":\"文本名称\",\"text\":{\"value\":\"文本\"}}]}," +
+ "\"external_profile\":{\"external_attr\":" +
"[{\"type\":0,\"name\":\"文本名称\",\"text\":{\"value\":\"文本\"}}," +
"{\"type\":1,\"name\":\"网页名称\",\"web\":{\"url\":\"http://www.test.com\",\"title\":\"标题\"}}," +
"{\"type\":2,\"name\":\"测试app\"," +
diff --git a/weixin-java-miniapp/pom.xml b/weixin-java-miniapp/pom.xml
index 16d56b930..d708de8a9 100644
--- a/weixin-java-miniapp/pom.xml
+++ b/weixin-java-miniapp/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.9.0
+ 3.9.1.B
weixin-java-miniapp
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index a89664d46..f1fad08a8 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.9.0
+ 3.9.1.B
weixin-java-mp
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java
index 98ef7716f..9b2ca03fe 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java
@@ -1,18 +1,5 @@
package me.chanjar.weixin.mp.api;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
@@ -23,6 +10,18 @@ import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.common.util.LogExceptionHandler;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
/**
*
@@ -183,7 +182,7 @@ public class WxMpMessageRouter {
}
}
- if (matchRules.size() == 0) {
+ if (matchRules.isEmpty()) {
return null;
}
@@ -193,11 +192,8 @@ public class WxMpMessageRouter {
// 返回最后一个非异步的rule的执行结果
if (rule.isAsync()) {
futures.add(
- this.executorService.submit(new Runnable() {
- @Override
- public void run() {
- rule.service(wxMessage, context, mpService, WxMpMessageRouter.this.sessionManager, WxMpMessageRouter.this.exceptionHandler);
- }
+ this.executorService.submit(() -> {
+ rule.service(wxMessage, context, mpService, WxMpMessageRouter.this.sessionManager, WxMpMessageRouter.this.exceptionHandler);
})
);
} else {
@@ -208,35 +204,34 @@ public class WxMpMessageRouter {
}
}
- if (futures.size() > 0) {
- this.executorService.submit(new Runnable() {
- @Override
- public void run() {
- for (Future> future : futures) {
- try {
- future.get();
- WxMpMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUser());
- // 异步操作结束,session访问结束
- sessionEndAccess(wxMessage);
- } catch (InterruptedException e) {
- WxMpMessageRouter.this.log.error("Error happened when wait task finish", e);
- Thread.currentThread().interrupt();
- } catch (ExecutionException e) {
- WxMpMessageRouter.this.log.error("Error happened when wait task finish", e);
- }
- }
- }
- });
+ if (futures.isEmpty()) {
+ return res;
}
+
+ this.executorService.submit(() -> {
+ for (Future> future : futures) {
+ try {
+ future.get();
+ WxMpMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUser());
+ // 异步操作结束,session访问结束
+ sessionEndAccess(wxMessage);
+ } catch (InterruptedException e) {
+ WxMpMessageRouter.this.log.error("Error happened when wait task finish", e);
+ Thread.currentThread().interrupt();
+ } catch (ExecutionException e) {
+ WxMpMessageRouter.this.log.error("Error happened when wait task finish", e);
+ }
+ }
+ });
return res;
}
public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage) {
- return this.route(wxMessage, new HashMap(2));
+ return this.route(wxMessage, new HashMap<>(2));
}
public WxMpXmlOutMessage route(String appid, final WxMpXmlMessage wxMessage) {
- return this.route(appid, wxMessage, new HashMap(2));
+ return this.route(appid, wxMessage, new HashMap<>(2));
}
private boolean isMsgDuplicated(WxMpXmlMessage wxMessage) {
diff --git a/weixin-java-open/pom.xml b/weixin-java-open/pom.xml
index cf743a404..8001b4ab8 100644
--- a/weixin-java-open/pom.xml
+++ b/weixin-java-open/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.9.0
+ 3.9.1.B
weixin-java-open
diff --git a/weixin-java-pay/pom.xml b/weixin-java-pay/pom.xml
index 1a51f3aad..bfc41e354 100644
--- a/weixin-java-pay/pom.xml
+++ b/weixin-java-pay/pom.xml
@@ -5,7 +5,7 @@
com.github.binarywang
wx-java
- 3.9.0
+ 3.9.1.B
4.0.0
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EntPayServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EntPayServiceImpl.java
index 5e768bef9..00e2ede65 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EntPayServiceImpl.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EntPayServiceImpl.java
@@ -8,7 +8,6 @@ import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.EntPayService;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.util.SignUtils;
-import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.PEMParser;
@@ -22,6 +21,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.security.PublicKey;
import java.security.Security;
+import java.util.Base64;
/**
*
@@ -168,7 +168,7 @@ public class EntPayServiceImpl implements EntPayService {
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] encrypt = cipher.doFinal(srcString.getBytes(StandardCharsets.UTF_8));
- return Base64.encodeBase64String(encrypt);
+ return Base64.getEncoder().encodeToString(encrypt);
}
} catch (Exception e) {
throw new WxPayException("加密出错", e);
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java
index c03713473..fe25bffc6 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java
@@ -3,7 +3,6 @@ package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.wxpay.bean.WxPayApiData;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.google.gson.JsonObject;
-import jodd.util.Base64;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
@@ -29,6 +28,7 @@ import org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import java.net.URI;
import java.nio.charset.StandardCharsets;
+import java.util.Base64;
/**
*
@@ -48,7 +48,7 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
try (CloseableHttpClient httpClient = httpClientBuilder.build()) {
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
final byte[] bytes = EntityUtils.toByteArray(response.getEntity());
- final String responseData = Base64.encodeToString(bytes);
+ final String responseData = Base64.getEncoder().encodeToString(bytes);
this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据(Base64编码后)】:{}", url, requestStr, responseData);
wxApiData.set(new WxPayApiData(url, requestStr, responseData, null));
return bytes;
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java
index b7ef11695..65f5e869b 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java
@@ -1,11 +1,5 @@
package com.github.binarywang.wxpay.service.impl;
-import java.net.URI;
-import java.nio.charset.StandardCharsets;
-import javax.net.ssl.SSLContext;
-
-import org.apache.commons.lang3.StringUtils;
-
import com.github.binarywang.wxpay.bean.WxPayApiData;
import com.github.binarywang.wxpay.exception.WxPayException;
import jodd.http.HttpConnectionProvider;
@@ -15,9 +9,14 @@ import jodd.http.ProxyInfo;
import jodd.http.ProxyInfo.ProxyType;
import jodd.http.net.SSLSocketHttpConnectionProvider;
import jodd.http.net.SocketHttpConnectionProvider;
-import jodd.util.Base64;
+import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpPost;
+import javax.net.ssl.SSLContext;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+
/**
* 微信支付请求实现类,jodd-http实现.
* Created by Binary Wang on 2016/7/28.
@@ -30,7 +29,7 @@ public class WxPayServiceJoddHttpImpl extends BaseWxPayServiceImpl {
try {
HttpRequest request = this.buildHttpRequest(url, requestStr, useKey);
byte[] responseBytes = request.send().bodyBytes();
- final String responseString = Base64.encodeToString(responseBytes);
+ final String responseString = Base64.getEncoder().encodeToString(responseBytes);
this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据(Base64编码后)】:{}", url, requestStr, responseString);
if (this.getConfig().isIfSaveApiData()) {
wxApiData.set(new WxPayApiData(url, requestStr, responseString, null));