diff --git a/pom.xml b/pom.xml index ada8d65a03..1faea9f319 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 com.github.binarywang wx-java - 3.9.2.B + 3.9.4.B pom WxJava - Weixin/Wechat Java SDK 微信开发Java SDK @@ -134,7 +134,7 @@ org.jodd jodd-http - 5.1.6 + 5.2.0 provided diff --git a/spring-boot-starters/pom.xml b/spring-boot-starters/pom.xml index ef5681e5c1..72cde108a2 100644 --- a/spring-boot-starters/pom.xml +++ b/spring-boot-starters/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang wx-java - 3.9.2.B + 3.9.4.B pom wx-java-spring-boot-starters diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml index 894de14c96..869042f310 100644 --- a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml +++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ wx-java-spring-boot-starters com.github.binarywang - 3.9.2.B + 3.9.4.B 4.0.0 diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md b/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md index 5059a59f5d..ae6ed94592 100644 --- a/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md +++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md @@ -20,12 +20,19 @@ wx.mp.config-storage.key-prefix = wx # 相关redis前缀配置: wx(默认) wx.mp.config-storage.redis.host = 127.0.0.1 wx.mp.config-storage.redis.port = 6379 + #单机和sentinel同时存在时,优先使用sentinel配置 + #wx.mp.config-storage.redis.sentinel-ips=127.0.0.1:16379,127.0.0.1:26379 + #wx.mp.config-storage.redis.sentinel-name=mymaster # http客户端配置 wx.mp.config-storage.http-client-type=httpclient # http客户端类型: HttpClient(默认), OkHttp, JoddHttp wx.mp.config-storage.http-proxy-host= wx.mp.config-storage.http-proxy-port= wx.mp.config-storage.http-proxy-username= wx.mp.config-storage.http-proxy-password= + # 公众号地址host配置 + #wx.mp.hosts.api-host=http://proxy.com/ + #wx.mp.hosts.open-host=http://proxy.com/ + #wx.mp.hosts.mp-host=http://proxy.com/ ``` 3. 自动注入的类型 - `WxMpService`以及~~相关的服务类, 比如: `wxMpService.getXxxService`。~~ diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml index e28fb5adc1..c4613752fa 100644 --- a/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml +++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ wx-java-spring-boot-starters com.github.binarywang - 3.9.2.B + 3.9.4.B 4.0.0 diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java index ad4fb31e4b..ef8e5348e2 100644 --- a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java +++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java @@ -1,24 +1,32 @@ package com.binarywang.spring.starter.wxjava.mp.config; -import com.binarywang.spring.starter.wxjava.mp.properties.RedisProperties; +import java.util.Set; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.core.StringRedisTemplate; + import com.binarywang.spring.starter.wxjava.mp.enums.StorageType; +import com.binarywang.spring.starter.wxjava.mp.properties.RedisProperties; import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties; +import com.google.common.collect.Sets; + import lombok.RequiredArgsConstructor; import me.chanjar.weixin.common.redis.JedisWxRedisOps; import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; import me.chanjar.weixin.common.redis.WxRedisOps; +import me.chanjar.weixin.mp.bean.WxMpHostConfig; import me.chanjar.weixin.mp.config.WxMpConfigStorage; import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.redis.core.StringRedisTemplate; import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolAbstract; import redis.clients.jedis.JedisPoolConfig; +import redis.clients.jedis.JedisSentinelPool; /** * 微信公众号存储策略自动配置. @@ -28,99 +36,113 @@ @Configuration @RequiredArgsConstructor public class WxMpStorageAutoConfiguration { - private final ApplicationContext applicationContext; - - private final WxMpProperties wxMpProperties; - - @Value("${wx.mp.config-storage.redis.host:") - private String redisHost; - - @Value("${wx.mp.configStorage.redis.host:") - private String redisHost2; - - @Bean - @ConditionalOnMissingBean(WxMpConfigStorage.class) - public WxMpConfigStorage wxMpConfigStorage() { - StorageType type = wxMpProperties.getConfigStorage().getType(); - WxMpConfigStorage config; - switch (type) { - case Jedis: - config = jedisConfigStorage(); - break; - case RedisTemplate: - config = redisTemplateConfigStorage(); - break; - default: - config = defaultConfigStorage(); - break; - } - return config; - } - - private WxMpConfigStorage defaultConfigStorage() { - WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl(); - setWxMpInfo(config); - return config; - } - - private WxMpConfigStorage jedisConfigStorage() { - JedisPool jedisPool; - if (StringUtils.isNotEmpty(redisHost) || StringUtils.isNotEmpty(redisHost2)) { - jedisPool = getJedisPool(); - } else { - jedisPool = applicationContext.getBean(JedisPool.class); - } - WxRedisOps redisOps = new JedisWxRedisOps(jedisPool); - WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps, wxMpProperties.getConfigStorage().getKeyPrefix()); - setWxMpInfo(wxMpRedisConfig); - return wxMpRedisConfig; - } - - private WxMpConfigStorage redisTemplateConfigStorage() { - StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class); - WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate); - WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps, wxMpProperties.getConfigStorage().getKeyPrefix()); - setWxMpInfo(wxMpRedisConfig); - return wxMpRedisConfig; - } - - private void setWxMpInfo(WxMpDefaultConfigImpl config) { - WxMpProperties properties = wxMpProperties; - WxMpProperties.ConfigStorage configStorageProperties = properties.getConfigStorage(); - config.setAppId(properties.getAppId()); - config.setSecret(properties.getSecret()); - config.setToken(properties.getToken()); - config.setAesKey(properties.getAesKey()); - - config.setHttpProxyHost(configStorageProperties.getHttpProxyHost()); - config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername()); - config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword()); - if (configStorageProperties.getHttpProxyPort() != null) { - config.setHttpProxyPort(configStorageProperties.getHttpProxyPort()); - } - } - - private JedisPool getJedisPool() { - WxMpProperties.ConfigStorage storage = wxMpProperties.getConfigStorage(); - RedisProperties redis = storage.getRedis(); - - JedisPoolConfig config = new JedisPoolConfig(); - if (redis.getMaxActive() != null) { - config.setMaxTotal(redis.getMaxActive()); - } - if (redis.getMaxIdle() != null) { - config.setMaxIdle(redis.getMaxIdle()); - } - if (redis.getMaxWaitMillis() != null) { - config.setMaxWaitMillis(redis.getMaxWaitMillis()); - } - if (redis.getMinIdle() != null) { - config.setMinIdle(redis.getMinIdle()); - } - config.setTestOnBorrow(true); - config.setTestWhileIdle(true); - - return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(), - redis.getDatabase()); - } + private final ApplicationContext applicationContext; + + private final WxMpProperties wxMpProperties; + + @Value("${wx.mp.config-storage.redis.host:") + private String redisHost; + + @Value("${wx.mp.configStorage.redis.host:") + private String redisHost2; + + @Bean + @ConditionalOnMissingBean(WxMpConfigStorage.class) + public WxMpConfigStorage wxMpConfigStorage() { + StorageType type = wxMpProperties.getConfigStorage().getType(); + WxMpConfigStorage config; + switch (type) { + case Jedis: + config = jedisConfigStorage(); + break; + case RedisTemplate: + config = redisTemplateConfigStorage(); + break; + default: + config = defaultConfigStorage(); + break; + } + // wx host config + if (null != wxMpProperties.getHosts() && StringUtils.isNotEmpty(wxMpProperties.getHosts().getApiHost())) { + WxMpHostConfig hostConfig = new WxMpHostConfig(); + hostConfig.setApiHost(wxMpProperties.getHosts().getApiHost()); + hostConfig.setMpHost(wxMpProperties.getHosts().getMpHost()); + hostConfig.setOpenHost(wxMpProperties.getHosts().getOpenHost()); + config.setHostConfig(hostConfig); + } + return config; + } + + private WxMpConfigStorage defaultConfigStorage() { + WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl(); + setWxMpInfo(config); + return config; + } + + private WxMpConfigStorage jedisConfigStorage() { + JedisPoolAbstract jedisPool; + if (StringUtils.isNotEmpty(redisHost) || StringUtils.isNotEmpty(redisHost2)) { + jedisPool = getJedisPool(); + } else { + jedisPool = applicationContext.getBean(JedisPool.class); + } + WxRedisOps redisOps = new JedisWxRedisOps(jedisPool); + WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps, + wxMpProperties.getConfigStorage().getKeyPrefix()); + setWxMpInfo(wxMpRedisConfig); + return wxMpRedisConfig; + } + + private WxMpConfigStorage redisTemplateConfigStorage() { + StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class); + WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate); + WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps, + wxMpProperties.getConfigStorage().getKeyPrefix()); + setWxMpInfo(wxMpRedisConfig); + return wxMpRedisConfig; + } + + private void setWxMpInfo(WxMpDefaultConfigImpl config) { + WxMpProperties properties = wxMpProperties; + WxMpProperties.ConfigStorage configStorageProperties = properties.getConfigStorage(); + config.setAppId(properties.getAppId()); + config.setSecret(properties.getSecret()); + config.setToken(properties.getToken()); + config.setAesKey(properties.getAesKey()); + + config.setHttpProxyHost(configStorageProperties.getHttpProxyHost()); + config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername()); + config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword()); + if (configStorageProperties.getHttpProxyPort() != null) { + config.setHttpProxyPort(configStorageProperties.getHttpProxyPort()); + } + } + + private JedisPoolAbstract getJedisPool() { + WxMpProperties.ConfigStorage storage = wxMpProperties.getConfigStorage(); + RedisProperties redis = storage.getRedis(); + + JedisPoolConfig config = new JedisPoolConfig(); + if (redis.getMaxActive() != null) { + config.setMaxTotal(redis.getMaxActive()); + } + if (redis.getMaxIdle() != null) { + config.setMaxIdle(redis.getMaxIdle()); + } + if (redis.getMaxWaitMillis() != null) { + config.setMaxWaitMillis(redis.getMaxWaitMillis()); + } + if (redis.getMinIdle() != null) { + config.setMinIdle(redis.getMinIdle()); + } + config.setTestOnBorrow(true); + config.setTestWhileIdle(true); + if (StringUtils.isNotEmpty(redis.getSentinelIps())) { + Set sentinels = Sets.newHashSet(redis.getSentinelIps().split(",")); + return new JedisSentinelPool(redis.getSentinelName(), sentinels); + } + + return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(), + redis.getDatabase()); + } } diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/HostConfig.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/HostConfig.java new file mode 100644 index 0000000000..3ade23b9a6 --- /dev/null +++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/HostConfig.java @@ -0,0 +1,18 @@ +package com.binarywang.spring.starter.wxjava.mp.properties; + +import java.io.Serializable; + +import lombok.Data; + +@Data +public class HostConfig implements Serializable { + + private static final long serialVersionUID = -4172767630740346001L; + + private String apiHost; + + private String openHost; + + private String mpHost; + +} diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java index c8c3307fea..07e4280b2f 100644 --- a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java +++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java @@ -38,6 +38,16 @@ public class RedisProperties implements Serializable { * 数据库. */ private int database = 0; + + /** + * sentinel ips + */ + private String sentinelIps; + + /** + * sentinel name + */ + private String sentinelName; private Integer maxActive; private Integer maxIdle; diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java index 14a61b5748..818d55f3ee 100644 --- a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java +++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java @@ -40,6 +40,11 @@ public class WxMpProperties { * 设置微信公众号的EncodingAESKey. */ private String aesKey; + + /** + * 自定义host配置 + */ + private HostConfig hosts; /** * 存储策略 diff --git a/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml index 83e07d221e..e2a25ae129 100644 --- a/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml +++ b/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ wx-java-spring-boot-starters com.github.binarywang - 3.9.2.B + 3.9.4.B 4.0.0 diff --git a/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml index a6239501d7..53205d5596 100644 --- a/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml +++ b/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ wx-java-spring-boot-starters com.github.binarywang - 3.9.2.B + 3.9.4.B 4.0.0 diff --git a/weixin-graal/pom.xml b/weixin-graal/pom.xml index a0c352ff78..1e99616714 100644 --- a/weixin-graal/pom.xml +++ b/weixin-graal/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang wx-java - 3.9.2.B + 3.9.4.B weixin-graal diff --git a/weixin-graal/src/main/java/cn/binarywang/wx/graal/GraalProcessor.java b/weixin-graal/src/main/java/com/github/binarywang/wx/graal/GraalProcessor.java similarity index 97% rename from weixin-graal/src/main/java/cn/binarywang/wx/graal/GraalProcessor.java rename to weixin-graal/src/main/java/com/github/binarywang/wx/graal/GraalProcessor.java index a7b02cae99..a983a51897 100644 --- a/weixin-graal/src/main/java/cn/binarywang/wx/graal/GraalProcessor.java +++ b/weixin-graal/src/main/java/com/github/binarywang/wx/graal/GraalProcessor.java @@ -1,4 +1,4 @@ -package cn.binarywang.wx.graal; +package com.github.binarywang.wx.graal; import lombok.Data; @@ -26,12 +26,12 @@ * @author outersky */ @SupportedAnnotationTypes("lombok.Data") -@SupportedSourceVersion(SourceVersion.RELEASE_7) +@SupportedSourceVersion(SourceVersion.RELEASE_8) public class GraalProcessor extends AbstractProcessor { private static final String REFLECTION_CONFIG_JSON = "reflection-config.json"; private static final String NATIVE_IMAGE_PROPERTIES = "native-image.properties"; - private SortedSet classSet = new TreeSet<>(); + private final SortedSet classSet = new TreeSet<>(); private String shortestPackageName = null; @Override diff --git a/weixin-graal/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/weixin-graal/src/main/resources/META-INF/services/javax.annotation.processing.Processor index fed7c4d9cd..f358b92ef9 100644 --- a/weixin-graal/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ b/weixin-graal/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -1 +1 @@ -cn.binarywang.wx.graal.GraalProcessor +com.github.binarywang.wx.graal.GraalProcessor diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index aeb9649fb8..31c04cd080 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang wx-java - 3.9.2.B + 3.9.4.B weixin-java-common @@ -165,7 +165,7 @@ 3.5.1 - cn.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor + com.github.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java index d7ac36c7c6..465f35434b 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java @@ -61,23 +61,20 @@ protected void checkBackgroundProcessStarted() { if (this.backgroundProcessStarted.getAndSet(true)) { return; } - Thread t = new Thread(new Runnable() { - @Override - public void run() { - try { - while (true) { - Thread.sleep(WxMessageInMemoryDuplicateChecker.this.clearPeriod); - Long now = System.currentTimeMillis(); - for (Map.Entry entry : - WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet()) { - if (now - entry.getValue() > WxMessageInMemoryDuplicateChecker.this.timeToLive) { - WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet().remove(entry); - } + Thread t = new Thread(() -> { + try { + while (true) { + Thread.sleep(WxMessageInMemoryDuplicateChecker.this.clearPeriod); + Long now = System.currentTimeMillis(); + for (Map.Entry entry : + WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet()) { + if (now - entry.getValue() > WxMessageInMemoryDuplicateChecker.this.timeToLive) { + WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet().remove(entry); } } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } }); t.setDaemon(true); diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxErrorException.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxErrorException.java index 6e9a2c538d..8b07086b24 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxErrorException.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxErrorException.java @@ -6,7 +6,11 @@ public class WxErrorException extends Exception { private static final long serialVersionUID = -6357149550353160810L; - private WxError error; + private final WxError error; + + public WxErrorException(String message) { + this(WxError.builder().errorCode(-1).errorMsg(message).build()); + } public WxErrorException(WxError error) { super(error.toString()); diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxMaErrorMsgEnum.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxMaErrorMsgEnum.java index eced6027e9..2a9fe01845 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxMaErrorMsgEnum.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxMaErrorMsgEnum.java @@ -464,11 +464,200 @@ public enum WxMaErrorMsgEnum { CODE_85004(85004, "微信号已经绑定"), + /** + * 53010 + * 名称格式不合法 + */ + CODE_53010(53010, "名称格式不合法"), + + /** + * 53011 + * 名称检测命中频率限制 + */ + CODE_53011(53011, "名称检测命中频率限制"), + + /** + * 53012 + * 禁止使用该名称 + */ + CODE_53012(53012, "禁止使用该名称"), + + /** + * 53013 + * 公众号:名称与已有公众号名称重复;小程序:该名称与已有小程序名称重复 + */ + CODE_53013(53013, "公众号:名称与已有公众号名称重复;小程序:该名称与已有小程序名称重复"), + + /** + * 53014 + * 公众号:公众号已有{名称 A+}时,需与该帐号相同主体才可申请{名称 A};小程序:小程序已有{名称 A+}时,需与该帐号相同主体才可申请{名称 A} + */ + CODE_53014(53014, "公众号:公众号已有{名称 A+}时,需与该帐号相同主体才可申请{名称 A};小程序:小程序已有{名称 A+}时,需与该帐号相同主体才可申请{名称 A}"), + + /** + * 53015 + * 公众号:该名称与已有小程序名称重复,需与该小程序帐号相同主体才可申请;小程序:该名称与已有公众号名称重复,需与该公众号帐号相同主体才可申请 + */ + CODE_53015(53015, "公众号:该名称与已有小程序名称重复,需与该小程序帐号相同主体才可申请;小程序:该名称与已有公众号名称重复,需与该公众号帐号相同主体才可申请"), + + /** + * 53016 + * 公众号:该名称与已有多个小程序名称重复,暂不支持申请;小程序:该名称与已有多个公众号名称重复,暂不支持申请 + */ + CODE_53016(53016, "公众号:该名称与已有多个小程序名称重复,暂不支持申请;小程序:该名称与已有多个公众号名称重复,暂不支持申请"), + + /** + * 53017 + * 公众号:小程序已有{名称 A+}时,需与该帐号相同主体才可申请{名称 A};小程序:公众号已有{名称 A+}时,需与该帐号相同主体才可申请{名称 A} + */ + CODE_53017(53017, "公众号:小程序已有{名称 A+}时,需与该帐号相同主体才可申请{名称 A};小程序:公众号已有{名称 A+}时,需与该帐号相同主体才可申请{名称 A}"), + + /** + * 53018 + * 名称命中微信号 + */ + CODE_53018(53018, "名称命中微信号"), + + /** + * 53019 + * 名称在保护期内 + */ + CODE_53019(53019, "名称在保护期内"), + + /** + * 61070 + * 法人姓名与微信号不一致 name, wechat name not in accordance + */ + CODE_61070(61070, "法人姓名与微信号不一致"), + + /** + * 85015 + * 该账号不是小程序账号 + */ + CODE_85015(85015, "该账号不是小程序账号"), + + /** + * 85066 + * 链接错误 + */ + CODE_85066(85066, "链接错误"), + + /** + * 85068 + * 测试链接不是子链接 + */ + CODE_85068(85068, "测试链接不是子链接"), + + /** + * 85069 + * 校验文件失败 + */ + CODE_85069(85069, "校验文件失败"), + + /** + * 85070 + * 个人类型小程序无法设置二维码规则 + */ + CODE_85070(85070, "个人类型小程序无法设置二维码规则"), + + /** + * 85071 + * 已添加该链接,请勿重复添加 + */ + CODE_85071(85071, "已添加该链接,请勿重复添加"), + + /** + * 85072 + * 该链接已被占用 + */ + CODE_85072(85072, "该链接已被占用"), + + /** + * 85073 + * 二维码规则已满 + */ + CODE_85073(85073, "二维码规则已满"), + + /** + * 85074 + * 小程序未发布, 小程序必须先发布代码才可以发布二维码跳转规则 + */ + CODE_85074(85074, "小程序未发布, 小程序必须先发布代码才可以发布二维码跳转规则"), + + /** + * 85075 + * 个人类型小程序无法设置二维码规则 + */ + CODE_85075(85075, "个人类型小程序无法设置二维码规则"), + + /** + * 86004 + * 无效微信号 invalid wechat + */ + CODE_86004(86004, "无效微信号"), + + /** + * 89247 + * 内部错误 inner error + */ + CODE_89247(89247, "内部错误"), + + /** + * 89248 + * 企业代码类型无效,请选择正确类型填写 invalid code_type type + */ + CODE_89248(89248, "企业代码类型无效,请选择正确类型填写"), + + /** + * 89249 + * 该主体已有任务执行中,距上次任务 24h 后再试 task running + */ + CODE_89249(89249, "该主体已有任务执行中,距上次任务 24h 后再试"), + + /** + * 89250 + * 未找到该任务 task not found + */ + CODE_89250(89250, "未找到该任务"), + + + /** + * 89251 + * 待法人人脸核身校验 legal person checking + */ + CODE_89251(89251, "待法人人脸核身校验"), + + /** + * 89252 + * 法人&企业信息一致性校验中 front checking + */ + CODE_89252(89252, "法人&企业信息一致性校验中"), + + /** + * 89253 + * 缺少参数 lack of some params + */ + CODE_89253(89253, "缺少参数s"), + + + /** + * 89254 + * 第三方权限集不全,补全权限集全网发布后生效 lack of some component rights + */ + CODE_89254(89254, "第三方权限集不全,补全权限集全网发布后生效"), + + /** + * 89255 + * code参数无效,请检查code长度以及内容是否正确 code参数无效,请检查code长度以及内容是否正确_; + * 注意code_type的值不同需要传的code长度不一样 ;注意code_type的值不同需要传的code长度不一样 enterprise code_invalid invalid + */ + CODE_89255(89255, "code参数无效,请检查code长度以及内容是否正确_;注意code_type的值不同需要传的code长度不一样 ;注意code_type的值不同需要传的code长度不一样"), + // CODE_504002(-504002, "云函数未找到 Function not found"), ; - private int code; - private String msg; + private final int code; + private final String msg; WxMaErrorMsgEnum(int code, String msg) { this.code = code; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxRuntimeException.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxRuntimeException.java new file mode 100644 index 0000000000..ccb8aecefb --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxRuntimeException.java @@ -0,0 +1,23 @@ +package me.chanjar.weixin.common.error; + +/** + * WxJava专用的runtime exception. + * + * @author Binary Wang + * @date 2020-09-26 + */ +public class WxRuntimeException extends RuntimeException { + private static final long serialVersionUID = 4881698471192264412L; + + public WxRuntimeException(Throwable e) { + super(e); + } + + public WxRuntimeException(String msg) { + super(msg); + } + + public WxRuntimeException(String msg, Throwable e) { + super(msg, e); + } +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSessionManager.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSessionManager.java index 591b7025dd..290a0c04f7 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSessionManager.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSessionManager.java @@ -183,18 +183,15 @@ protected InternalSession getNewSession() { public void add(InternalSession session) { // 当第一次有session创建的时候,开启session清理线程 if (!this.backgroundProcessStarted.getAndSet(true)) { - Thread t = new Thread(new Runnable() { - @Override - public void run() { - while (true) { - try { - // 每秒清理一次 - Thread.sleep(StandardSessionManager.this.backgroundProcessorDelay * 1000L); - backgroundProcess(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - StandardSessionManager.this.log.error("SessionManagerImpl.backgroundProcess error", e); - } + Thread t = new Thread(() -> { + while (true) { + try { + // 每秒清理一次 + Thread.sleep(StandardSessionManager.this.backgroundProcessorDelay * 1000L); + backgroundProcess(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + StandardSessionManager.this.log.error("SessionManagerImpl.backgroundProcess error", e); } } }); 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 768f2e5324..73b6cff368 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 @@ -58,7 +58,7 @@ public static void checkRequiredFields(Object bean) throws WxErrorException { if (!requiredFields.isEmpty()) { String msg = String.format("必填字段【%s】必须提供值!", requiredFields); log.debug(msg); - throw new WxErrorException(WxError.builder().errorMsg(msg).build()); + throw new WxErrorException(msg); } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/LogExceptionHandler.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/LogExceptionHandler.java index 7487a0fe29..35b0eea822 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/LogExceptionHandler.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/LogExceptionHandler.java @@ -1,20 +1,17 @@ package me.chanjar.weixin.common.util; +import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.api.WxErrorExceptionHandler; import me.chanjar.weixin.common.error.WxErrorException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +/** + * @author Daniel Qian + */ +@Slf4j public class LogExceptionHandler implements WxErrorExceptionHandler { - - private Logger log = LoggerFactory.getLogger(WxErrorExceptionHandler.class); - @Override public void handle(WxErrorException e) { - - this.log.error("Error happens", e); - + log.error("Error happens", e); } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/XmlUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/XmlUtils.java index c2ffdb001b..91c6b8f2ec 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/XmlUtils.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/XmlUtils.java @@ -3,10 +3,9 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import org.dom4j.Document; -import org.dom4j.DocumentException; -import org.dom4j.Element; -import org.dom4j.Node; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.error.WxRuntimeException; +import org.dom4j.*; import org.dom4j.io.SAXReader; import org.dom4j.tree.DefaultText; import org.xml.sax.SAXException; @@ -43,21 +42,23 @@ public static Map xml2Map(String xmlString) { map.put(element.getName(), element2MapOrString(element)); } } catch (DocumentException | SAXException e) { - throw new RuntimeException(e); + throw new WxRuntimeException(e); } return map; } private static Object element2MapOrString(Element element) { - Map result = Maps.newHashMap(); final List content = element.content(); - if (content.size() <= 1) { + final Set names = names(content); + + // 判断节点下有无非文本节点(非Text和CDATA),如无,直接取Text文本内容 + if (names.size() < 1) { return element.getText(); } - final Set names = names(content); + Map result = Maps.newHashMap(); if (names.size() == 1) { // 说明是个列表,各个子对象是相同的name List list = Lists.newArrayList(); @@ -90,7 +91,8 @@ private static Object element2MapOrString(Element element) { private static Set names(List nodes) { Set names = Sets.newHashSet(); for (Node node : nodes) { - if (node instanceof DefaultText) { + // 如果节点类型是Text或CDATA跳过 + if (node instanceof DefaultText || node instanceof CDATA) { continue; } names.add(node.getName()); diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java index 0103fc7f06..d47414fefc 100755 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java @@ -14,6 +14,7 @@ import com.google.common.base.CharMatcher; import com.google.common.io.BaseEncoding; +import me.chanjar.weixin.common.error.WxRuntimeException; import org.apache.commons.codec.binary.Base64; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -77,7 +78,7 @@ private static String extractEncryptPart(String xml) { Element root = document.getDocumentElement(); return root.getElementsByTagName("Encrypt").item(0).getTextContent(); } catch (Exception e) { - throw new RuntimeException(e); + throw new WxRuntimeException(e); } } @@ -198,7 +199,7 @@ protected String encrypt(String randomStr, String plainText) { // 使用BASE64对加密后的字符串进行编码 return BASE64.encodeToString(encrypted); } catch (Exception e) { - throw new RuntimeException(e); + throw new WxRuntimeException(e); } } @@ -224,7 +225,7 @@ public String decrypt(String msgSignature, String timeStamp, String nonce, Strin // 验证安全签名 String signature = SHA1.gen(this.token, timeStamp, nonce, cipherText); if (!signature.equals(msgSignature)) { - throw new RuntimeException("加密消息签名校验失败"); + throw new WxRuntimeException("加密消息签名校验失败"); } // 解密 @@ -252,7 +253,7 @@ public String decrypt(String cipherText) { // 解密 original = cipher.doFinal(encrypted); } catch (Exception e) { - throw new RuntimeException(e); + throw new WxRuntimeException(e); } String xmlContent; @@ -269,12 +270,12 @@ public String decrypt(String cipherText) { xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), CHARSET); fromAppid = new String(Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length), CHARSET); } catch (Exception e) { - throw new RuntimeException(e); + throw new WxRuntimeException(e); } // appid不相同的情况 暂时忽略这段判断 // if (!fromAppid.equals(this.appidOrCorpid)) { -// throw new RuntimeException("AppID不正确,请核实!"); +// throw new WxRuntimeException("AppID不正确,请核实!"); // } return xmlContent; diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java index 0d68518849..49d8b2a749 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java @@ -58,7 +58,7 @@ public String getFileName() throws WxErrorException { private String getFileName(CloseableHttpResponse response) throws WxErrorException { Header[] contentDispositionHeader = response.getHeaders("Content-disposition"); if (contentDispositionHeader == null || contentDispositionHeader.length == 0) { - throw new WxErrorException(WxError.builder().errorMsg("无法获取到文件名").errorCode(99999).build()); + throw new WxErrorException("无法获取到文件名"); } return this.extractFileNameFromContentString(contentDispositionHeader[0].getValue()); @@ -76,7 +76,7 @@ private String getFileName(Response response) throws WxErrorException { private String extractFileNameFromContentString(String content) throws WxErrorException { if (content == null || content.length() == 0) { - throw new WxErrorException(WxError.builder().errorMsg("无法获取到文件名").errorCode(99999).build()); + throw new WxErrorException("无法获取到文件名"); } Matcher m = PATTERN.matcher(content); @@ -84,7 +84,7 @@ private String extractFileNameFromContentString(String content) throws WxErrorEx return m.group(1); } - throw new WxErrorException(WxError.builder().errorMsg("无法获取到文件名").errorCode(99999).build()); + throw new WxErrorException("无法获取到文件名"); } } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java index c0952b32d4..0366b156af 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java @@ -44,7 +44,7 @@ public static RequestExecutor create(RequestHttp requestHttp) { @NotNull public String handleResponse(WxType wxType, String responseContent) throws WxErrorException { if (responseContent.isEmpty()) { - throw new WxErrorException(WxError.builder().errorCode(9999).errorMsg("无响应内容").build()); + throw new WxErrorException("无响应内容"); } if (responseContent.startsWith("")) { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaDownloadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaDownloadRequestExecutor.java index 5c67cbffe1..00df2a640a 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaDownloadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaDownloadRequestExecutor.java @@ -19,6 +19,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; /** * . @@ -47,7 +48,7 @@ public File execute(String uri, String queryParam, WxType wxType) throws WxError request.withConnectionProvider(requestHttp.getRequestHttpClient()); HttpResponse response = request.send(); - response.charset(StringPool.UTF_8); + response.charset(StandardCharsets.UTF_8.name()); String contentType = response.header("Content-Type"); if (contentType != null && contentType.startsWith("application/json")) { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaUploadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaUploadRequestExecutor.java index 93f25fb740..89ea05a029 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaUploadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMediaUploadRequestExecutor.java @@ -14,6 +14,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; /** * . @@ -35,7 +36,7 @@ public WxMediaUploadResult execute(String uri, File file, WxType wxType) throws request.withConnectionProvider(requestHttp.getRequestHttpClient()); request.form("media", file); HttpResponse response = request.send(); - response.charset(StringPool.UTF_8); + response.charset(StandardCharsets.UTF_8.name()); String responseContent = response.bodyText(); WxError error = WxError.fromJson(responseContent, wxType); diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimpleGetRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimpleGetRequestExecutor.java index e8adad6b66..5960274eb6 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimpleGetRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimpleGetRequestExecutor.java @@ -11,6 +11,7 @@ import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; import java.io.IOException; +import java.nio.charset.StandardCharsets; /** * . @@ -38,7 +39,7 @@ public String execute(String uri, String queryParam, WxType wxType) throws WxErr } request.withConnectionProvider(requestHttp.getRequestHttpClient()); HttpResponse response = request.send(); - response.charset(StringPool.UTF_8); + response.charset(StandardCharsets.UTF_8.name()); return handleResponse(wxType, response.bodyText()); } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimplePostRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimplePostRequestExecutor.java index 7b2f5f61ef..50360cae56 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimplePostRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpSimplePostRequestExecutor.java @@ -11,6 +11,7 @@ import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import java.io.IOException; +import java.nio.charset.StandardCharsets; /** * . @@ -37,7 +38,7 @@ public String execute(String uri, String postEntity, WxType wxType) throws WxErr request.bodyText(postEntity); } HttpResponse response = request.send(); - response.charset(StringPool.UTF_8); + response.charset(StandardCharsets.UTF_8.name()); return this.handleResponse(wxType, response.bodyText()); } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/GsonHelper.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/GsonHelper.java index 11a0742a71..030ba6fa5a 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/GsonHelper.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/GsonHelper.java @@ -5,6 +5,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import jodd.util.MathUtil; +import me.chanjar.weixin.common.error.WxRuntimeException; import java.util.List; @@ -173,7 +174,7 @@ public static JsonObject buildJsonObject(Object... keyOrValue) { */ public static void put(JsonObject jsonObject, Object... keyOrValue) { if (MathUtil.isOdd(keyOrValue.length)) { - throw new RuntimeException("参数个数必须为偶数"); + throw new WxRuntimeException("参数个数必须为偶数"); } for (int i = 0; i < keyOrValue.length / 2; i++) { diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/locks/JedisDistributedLock.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/locks/JedisDistributedLock.java index 074f9d9351..7261d4a118 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/locks/JedisDistributedLock.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/locks/JedisDistributedLock.java @@ -5,6 +5,7 @@ import java.util.concurrent.locks.Lock; import com.github.jedis.lock.JedisLock; +import me.chanjar.weixin.common.error.WxRuntimeException; import redis.clients.jedis.Jedis; import redis.clients.jedis.util.Pool; @@ -26,10 +27,10 @@ public JedisDistributedLock(Pool jedisPool, String key){ public void lock() { try (Jedis jedis = jedisPool.getResource()) { if (!lock.acquire(jedis)) { - throw new RuntimeException("acquire timeouted"); + throw new WxRuntimeException("acquire timeouted"); } } catch (InterruptedException e) { - throw new RuntimeException("lock failed", e); + throw new WxRuntimeException("lock failed", e); } } @@ -37,7 +38,7 @@ public void lock() { public void lockInterruptibly() throws InterruptedException { try (Jedis jedis = jedisPool.getResource()) { if (!lock.acquire(jedis)) { - throw new RuntimeException("acquire timeouted"); + throw new WxRuntimeException("acquire timeouted"); } } } @@ -47,7 +48,7 @@ public boolean tryLock() { try (Jedis jedis = jedisPool.getResource()) { return lock.acquire(jedis); } catch (InterruptedException e) { - throw new RuntimeException("lock failed", e); + throw new WxRuntimeException("lock failed", e); } } @@ -67,7 +68,7 @@ public void unlock() { @Override public Condition newCondition() { - throw new RuntimeException("unsupported method"); + throw new WxRuntimeException("unsupported method"); } } diff --git a/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/locks/RedisTemplateSimpleDistributedLockTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/locks/RedisTemplateSimpleDistributedLockTest.java index 50a17ed94b..4b65e31f0b 100644 --- a/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/locks/RedisTemplateSimpleDistributedLockTest.java +++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/locks/RedisTemplateSimpleDistributedLockTest.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.common.util.locks; -import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.core.StringRedisTemplate; import org.testng.annotations.BeforeTest; @@ -12,6 +12,7 @@ import static org.testng.Assert.*; +@Slf4j @Test(enabled = false) public class RedisTemplateSimpleDistributedLockTest { @@ -40,19 +41,19 @@ public void testLockExclusive() throws InterruptedException { final CountDownLatch endLatch = new CountDownLatch(threadSize); for (int i = 0; i < threadSize; i++) { - new Thread(new Runnable() { - @SneakyThrows - @Override - public void run() { + new Thread(() -> { + try { startLatch.await(); + } catch (InterruptedException e) { + log.error("unexpected exception", e); + } - redisLock.lock(); - assertEquals(lockCurrentExecuteCounter.incrementAndGet(), 1, "临界区同时只能有一个线程执行"); - lockCurrentExecuteCounter.decrementAndGet(); - redisLock.unlock(); + redisLock.lock(); + assertEquals(lockCurrentExecuteCounter.incrementAndGet(), 1, "临界区同时只能有一个线程执行"); + lockCurrentExecuteCounter.decrementAndGet(); + redisLock.unlock(); - endLatch.countDown(); - } + endLatch.countDown(); }).start(); startLatch.countDown(); } diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index acad7bb5f5..10fab71e2a 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -7,7 +7,7 @@ com.github.binarywang wx-java - 3.9.2.B + 3.9.4.B weixin-java-cp @@ -119,7 +119,7 @@ 3.5.1 - cn.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor + com.github.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java index a386b0ead2..3f5ee36773 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java @@ -132,6 +132,20 @@ public interface WxCpExternalContactService { */ WxCpUserExternalContactInfo getContactDetail(String userId) throws WxErrorException; + /** + * 修改客户备注信息. + *
+   * 企业可通过此接口修改指定用户添加的客户的备注信息。
+   * 请求方式: POST(HTTP)
+   * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/remark?access_token=ACCESS_TOKEN
+   * 文档地址:https://work.weixin.qq.com/api/doc/90000/90135/92115
+   * 
+ * + * @param request 备注信息请求 + * @throws WxErrorException . + */ + void updateRemark(WxCpUpdateRemarkRequest request) throws WxErrorException; + /** * 获取客户列表. *
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpGroupRobotService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpGroupRobotService.java
index 007dff78fc..b5a9579e0d 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpGroupRobotService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpGroupRobotService.java
@@ -31,7 +31,7 @@ public interface WxCpGroupRobotService {
    * @param content markdown内容,最长不超过4096个字节,必须是utf8编码
    * @throws WxErrorException 异常
    */
-  void sendMarkDown(String content) throws WxErrorException;
+  void sendMarkdown(String content) throws WxErrorException;
 
   /**
    * 发送image类型的消息
@@ -49,4 +49,43 @@ public interface WxCpGroupRobotService {
    * @throws WxErrorException 异常
    */
   void sendNews(List articleList) throws WxErrorException;
+
+  /**
+   * 发送text类型的消息
+   *
+   * @param webhookUrl    webhook地址
+   * @param content       文本内容,最长不超过2048个字节,必须是utf8编码
+   * @param mentionedList userId的列表,提醒群中的指定成员(@某个成员),@all表示提醒所有人,如果开发者获取不到userId,可以使用mentioned_mobile_list
+   * @param mobileList    手机号列表,提醒手机号对应的群成员(@某个成员),@all表示提醒所有人
+   * @throws WxErrorException 异常
+   */
+  void sendText(String webhookUrl, String content, List mentionedList, List mobileList) throws WxErrorException;
+
+  /**
+   * 发送markdown类型的消息
+   *
+   * @param webhookUrl webhook地址
+   * @param content    markdown内容,最长不超过4096个字节,必须是utf8编码
+   * @throws WxErrorException 异常
+   */
+  void sendMarkdown(String webhookUrl, String content) throws WxErrorException;
+
+  /**
+   * 发送image类型的消息
+   *
+   * @param webhookUrl webhook地址
+   * @param base64     图片内容的base64编码
+   * @param md5        图片内容(base64编码前)的md5值
+   * @throws WxErrorException 异常
+   */
+  void sendImage(String webhookUrl, String base64, String md5) throws WxErrorException;
+
+  /**
+   * 发送news类型的消息
+   *
+   * @param webhookUrl  webhook地址
+   * @param articleList 图文消息,支持1到8条图文
+   * @throws WxErrorException 异常
+   */
+  void sendNews(String webhookUrl, List articleList) throws WxErrorException;
 }
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaCalendarService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaCalendarService.java
new file mode 100644
index 0000000000..8dc0d31364
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaCalendarService.java
@@ -0,0 +1,29 @@
+package me.chanjar.weixin.cp.api;
+
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.bean.oa.calendar.WxCpOaCalendar;
+
+/**
+ * 企业微信日历接口.
+ *
+ * @author Binary Wang
+ * @date 2020-09-20
+ */
+public interface WxCpOaCalendarService {
+  /**
+   * 创建日历.
+   * 
+   * 该接口用于通过应用在企业内创建一个日历。
+   * 注: 企业微信需要更新到3.0.2及以上版本
+   * 请求方式: POST(HTTPS)
+   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/oa/calendar/add?access_token=ACCESS_TOKEN
+   *
+   * 文档地址:https://work.weixin.qq.com/api/doc/90000/90135/92618
+   * 
+ * + * @param calendar 日历对象 + * @return 日历ID + * @throws WxErrorException . + */ + String add(WxCpOaCalendar calendar) throws WxErrorException; +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java index 3378f88626..465090f193 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java @@ -388,7 +388,14 @@ public interface WxCpService { * * @return the oa service */ - WxCpOaService getOAService(); + WxCpOaService getOaService(); + + /** + * 获取日历相关接口的服务类对象 + * + * @return the menu service + */ + WxCpOaCalendarService getOaCalendarService(); /** * 获取群机器人消息推送服务 @@ -445,4 +452,5 @@ public interface WxCpService { * @param tagService the tag service */ void setTagService(WxCpTagService tagService); + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java index 97faa4c969..0aa44c1995 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java @@ -9,6 +9,7 @@ import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.WxSession; import me.chanjar.weixin.common.session.WxSessionManager; @@ -52,6 +53,7 @@ public abstract class BaseWxCpServiceImpl implements WxCpService, RequestH private WxCpExternalContactService externalContactService = new WxCpExternalContactServiceImpl(this); private WxCpGroupRobotService groupRobotService = new WxCpGroupRobotServiceImpl(this); private WxCpMessageService messageService = new WxCpMessageServiceImpl(this); + private WxCpOaCalendarService oaCalendarService = new WxCpOaCalendarServiceImpl(this); /** * 全局的是否正在刷新access token的锁. @@ -226,7 +228,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro if (retryTimes + 1 > this.maxRetryTimes) { log.warn("重试达到最大次数【{}】", this.maxRetryTimes); //最后一次重试失败后,直接抛出异常,不再等待 - throw new RuntimeException("微信服务端异常,超出重试次数"); + throw new WxRuntimeException("微信服务端异常,超出重试次数"); } WxError error = e.getError(); @@ -248,7 +250,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro } while (retryTimes++ < this.maxRetryTimes); log.warn("重试达到最大次数【{}】", this.maxRetryTimes); - throw new RuntimeException("微信服务端异常,超出重试次数"); + throw new WxRuntimeException("微信服务端异常,超出重试次数"); } protected T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { @@ -284,7 +286,7 @@ protected T executeInternal(RequestExecutor executor, String uri, E return null; } catch (IOException e) { log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage()); - throw new RuntimeException(e); + throw new WxRuntimeException(e); } } @@ -305,7 +307,7 @@ private T executeNormal(RequestExecutor executor, String uri, E dat return null; } catch (IOException e) { log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uri, data, e.getMessage()); - throw new RuntimeException(e); + throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).errorCode(-1).build(), e); } } @@ -421,10 +423,15 @@ public WxCpChatService getChatService() { } @Override - public WxCpOaService getOAService() { + public WxCpOaService getOaService() { return oaService; } + @Override + public WxCpOaCalendarService getOaCalendarService() { + return this.oaCalendarService; + } + @Override public WxCpGroupRobotService getGroupRobotService() { return groupRobotService; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java index b64ec0e870..6c6a413a7f 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java @@ -6,9 +6,10 @@ import lombok.RequiredArgsConstructor; import me.chanjar.weixin.common.error.WxCpErrorMsgEnum; import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.cp.api.WxCpExternalContactService; import me.chanjar.weixin.cp.api.WxCpService; -import me.chanjar.weixin.cp.bean.*; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; import me.chanjar.weixin.cp.bean.external.*; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -30,7 +31,7 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic public WxCpContactWayResult addContactWay(@NonNull WxCpContactWayInfo info) throws WxErrorException { if (info.getContactWay().getUsers() != null && info.getContactWay().getUsers().size() > 100) { - throw new RuntimeException("「联系我」使用人数默认限制不超过100人(包括部门展开后的人数)"); + throw new WxRuntimeException("「联系我」使用人数默认限制不超过100人(包括部门展开后的人数)"); } final String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_CONTACT_WAY); @@ -52,10 +53,10 @@ public WxCpContactWayInfo getContactWay(@NonNull String configId) throws WxError @Override public WxCpBaseResp updateContactWay(@NonNull WxCpContactWayInfo info) throws WxErrorException { if (StringUtils.isBlank(info.getContactWay().getConfigId())) { - throw new RuntimeException("更新「联系我」方式需要指定configId"); + throw new WxRuntimeException("更新「联系我」方式需要指定configId"); } if (info.getContactWay().getUsers() != null && info.getContactWay().getUsers().size() > 100) { - throw new RuntimeException("「联系我」使用人数默认限制不超过100人(包括部门展开后的人数)"); + throw new WxRuntimeException("「联系我」使用人数默认限制不超过100人(包括部门展开后的人数)"); } final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_CONTACT_WAY); @@ -67,7 +68,7 @@ public WxCpBaseResp updateContactWay(@NonNull WxCpContactWayInfo info) throws Wx @Override public WxCpBaseResp deleteContactWay(@NonNull String configId) throws WxErrorException { JsonObject json = new JsonObject(); - json.addProperty("config_id",configId); + json.addProperty("config_id", configId); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEL_CONTACT_WAY); String responseContent = this.mainService.post(url, json.toString()); @@ -79,8 +80,8 @@ public WxCpBaseResp deleteContactWay(@NonNull String configId) throws WxErrorExc public WxCpBaseResp closeTempChat(@NonNull String userId, @NonNull String externalUserId) throws WxErrorException { JsonObject json = new JsonObject(); - json.addProperty("userid",userId); - json.addProperty("external_userid",externalUserId); + json.addProperty("userid", userId); + json.addProperty("external_userid", externalUserId); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(CLOSE_TEMP_CHAT); @@ -103,6 +104,12 @@ public WxCpUserExternalContactInfo getContactDetail(String userId) throws WxErro return WxCpUserExternalContactInfo.fromJson(responseContent); } + @Override + public void updateRemark(WxCpUpdateRemarkRequest request) throws WxErrorException { + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_REMARK); + this.mainService.post(url, request.toJson()); + } + @Override public List listExternalContacts(String userId) throws WxErrorException { final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_EXTERNAL_CONTACT + userId); @@ -233,66 +240,66 @@ public void sendWelcomeMsg(WxCpWelcomeMsg msg) throws WxErrorException { @Override public WxCpUserExternalTagGroupList getCorpTagList(String[] tagId) throws WxErrorException { JsonObject json = new JsonObject(); - if(ArrayUtils.isNotEmpty(tagId)){ - json.add("tag_id",new Gson().toJsonTree(tagId).getAsJsonArray()); + if (ArrayUtils.isNotEmpty(tagId)) { + json.add("tag_id", new Gson().toJsonTree(tagId).getAsJsonArray()); } final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CORP_TAG_LIST); - final String result = this.mainService.post(url,json.toString()); + final String result = this.mainService.post(url, json.toString()); return WxCpUserExternalTagGroupList.fromJson(result); } @Override - public WxCpUserExternalTagGroupInfo addCorpTag(WxCpUserExternalTagGroupInfo tagGroup) throws WxErrorException{ + public WxCpUserExternalTagGroupInfo addCorpTag(WxCpUserExternalTagGroupInfo tagGroup) throws WxErrorException { final String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_CORP_TAG); - final String result = this.mainService.post(url,tagGroup.getTagGroup().toJson()); + final String result = this.mainService.post(url, tagGroup.getTagGroup().toJson()); return WxCpUserExternalTagGroupInfo.fromJson(result); } @Override - public WxCpBaseResp editCorpTag(String id, String name, Integer order) throws WxErrorException{ + public WxCpBaseResp editCorpTag(String id, String name, Integer order) throws WxErrorException { JsonObject json = new JsonObject(); - json.addProperty("id",id); - json.addProperty("name",name); - json.addProperty("order",order); + json.addProperty("id", id); + json.addProperty("name", name); + json.addProperty("order", order); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(EDIT_CORP_TAG); - final String result = this.mainService.post(url,json.toString()); + final String result = this.mainService.post(url, json.toString()); return WxCpBaseResp.fromJson(result); } @Override - public WxCpBaseResp delCorpTag(String[] tagId, String[] groupId) throws WxErrorException{ + public WxCpBaseResp delCorpTag(String[] tagId, String[] groupId) throws WxErrorException { JsonObject json = new JsonObject(); - if(ArrayUtils.isNotEmpty(tagId)){ - json.add("tag_id",new Gson().toJsonTree(tagId).getAsJsonArray()); + if (ArrayUtils.isNotEmpty(tagId)) { + json.add("tag_id", new Gson().toJsonTree(tagId).getAsJsonArray()); } - if(ArrayUtils.isNotEmpty(groupId)){ - json.add("group_id",new Gson().toJsonTree(groupId).getAsJsonArray()); + if (ArrayUtils.isNotEmpty(groupId)) { + json.add("group_id", new Gson().toJsonTree(groupId).getAsJsonArray()); } final String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEL_CORP_TAG); - final String result = this.mainService.post(url,json.toString()); + final String result = this.mainService.post(url, json.toString()); return WxCpBaseResp.fromJson(result); } @Override - public WxCpBaseResp markTag(String userid, String externalUserid, String[] addTag, String[] removeTag)throws WxErrorException{ + public WxCpBaseResp markTag(String userid, String externalUserid, String[] addTag, String[] removeTag) throws WxErrorException { JsonObject json = new JsonObject(); - json.addProperty("userid",userid); - json.addProperty("external_userid",externalUserid); + json.addProperty("userid", userid); + json.addProperty("external_userid", externalUserid); - if(ArrayUtils.isNotEmpty(addTag)){ - json.add("add_tag",new Gson().toJsonTree(addTag).getAsJsonArray()); + if (ArrayUtils.isNotEmpty(addTag)) { + json.add("add_tag", new Gson().toJsonTree(addTag).getAsJsonArray()); } - if(ArrayUtils.isNotEmpty(removeTag)){ - json.add("remove_tag",new Gson().toJsonTree(removeTag).getAsJsonArray()); + if (ArrayUtils.isNotEmpty(removeTag)) { + json.add("remove_tag", new Gson().toJsonTree(removeTag).getAsJsonArray()); } final String url = this.mainService.getWxCpConfigStorage().getApiUrl(MARK_TAG); - final String result = this.mainService.post(url,json.toString()); + final String result = this.mainService.post(url, json.toString()); return WxCpBaseResp.fromJson(result); } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImpl.java index c5e71f5f25..c20c4a138d 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImpl.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.cp.api.impl; import lombok.RequiredArgsConstructor; +import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpGroupRobotService; import me.chanjar.weixin.cp.api.WxCpService; @@ -8,14 +9,16 @@ import me.chanjar.weixin.cp.bean.message.WxCpGroupRobotMessage; import me.chanjar.weixin.cp.config.WxCpConfigStorage; import me.chanjar.weixin.cp.constant.WxCpApiPathConsts; +import org.apache.commons.lang3.StringUtils; import java.util.List; import static me.chanjar.weixin.cp.constant.WxCpConsts.GroupRobotMsgType; -import static me.chanjar.weixin.cp.constant.WxCpConsts.GroupRobotMsgType.*; +import static me.chanjar.weixin.cp.constant.WxCpConsts.GroupRobotMsgType.MARKDOWN; +import static me.chanjar.weixin.cp.constant.WxCpConsts.GroupRobotMsgType.TEXT; /** - * 微信群机器人消息发送api 实现 + * 企业微信群机器人消息发送api 实现 * * @author yr * @date 2020-08-20 @@ -24,44 +27,66 @@ public class WxCpGroupRobotServiceImpl implements WxCpGroupRobotService { private final WxCpService cpService; - private String getApiUrl() { - WxCpConfigStorage wxCpConfigStorage = cpService.getWxCpConfigStorage(); - return wxCpConfigStorage.getApiUrl(WxCpApiPathConsts.WEBHOOK_SEND) + wxCpConfigStorage.getWebhookKey(); + private String getWebhookUrl() throws WxErrorException { + WxCpConfigStorage wxCpConfigStorage = this.cpService.getWxCpConfigStorage(); + final String webhookKey = wxCpConfigStorage.getWebhookKey(); + if (StringUtils.isEmpty(webhookKey)) { + throw new WxErrorException("请先设置WebhookKey"); + } + return wxCpConfigStorage.getApiUrl(WxCpApiPathConsts.WEBHOOK_SEND) + webhookKey; } @Override public void sendText(String content, List mentionedList, List mobileList) throws WxErrorException { - WxCpGroupRobotMessage message = new WxCpGroupRobotMessage() + this.sendText(this.getWebhookUrl(), content, mentionedList, mobileList); + } + + @Override + public void sendMarkdown(String content) throws WxErrorException { + this.sendMarkdown(this.getWebhookUrl(), content); + } + + @Override + public void sendImage(String base64, String md5) throws WxErrorException { + this.sendImage(this.getWebhookUrl(), base64, md5); + } + + @Override + public void sendNews(List articleList) throws WxErrorException { + this.sendNews(this.getWebhookUrl(), articleList); + } + + @Override + public void sendText(String webhookUrl, String content, List mentionedList, List mobileList) throws WxErrorException { + this.cpService.postWithoutToken(webhookUrl, new WxCpGroupRobotMessage() .setMsgType(TEXT) .setContent(content) .setMentionedList(mentionedList) - .setMentionedMobileList(mobileList); - cpService.postWithoutToken(this.getApiUrl(), message.toJson()); + .setMentionedMobileList(mobileList) + .toJson()); } @Override - public void sendMarkDown(String content) throws WxErrorException { - WxCpGroupRobotMessage message = new WxCpGroupRobotMessage() + public void sendMarkdown(String webhookUrl, String content) throws WxErrorException { + this.cpService.postWithoutToken(webhookUrl, new WxCpGroupRobotMessage() .setMsgType(MARKDOWN) - .setContent(content); - cpService.postWithoutToken(this.getApiUrl(), message.toJson()); + .setContent(content) + .toJson()); } @Override - public void sendImage(String base64, String md5) throws WxErrorException { - WxCpGroupRobotMessage message = new WxCpGroupRobotMessage() + public void sendImage(String webhookUrl, String base64, String md5) throws WxErrorException { + this.cpService.postWithoutToken(this.getWebhookUrl(), new WxCpGroupRobotMessage() .setMsgType(GroupRobotMsgType.IMAGE) .setBase64(base64) - .setMd5(md5); - cpService.postWithoutToken(this.getApiUrl(), message.toJson()); + .setMd5(md5).toJson()); } @Override - public void sendNews(List articleList) throws WxErrorException { - WxCpGroupRobotMessage message = new WxCpGroupRobotMessage() + public void sendNews(String webhookUrl, List articleList) throws WxErrorException { + this.cpService.postWithoutToken(this.getWebhookUrl(), new WxCpGroupRobotMessage() .setMsgType(GroupRobotMsgType.NEWS) - .setArticles(articleList); - cpService.postWithoutToken(this.getApiUrl(), message.toJson()); + .setArticles(articleList).toJson()); } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaCalendarServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaCalendarServiceImpl.java new file mode 100644 index 0000000000..c5b0a4aac3 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaCalendarServiceImpl.java @@ -0,0 +1,25 @@ +package me.chanjar.weixin.cp.api.impl; + +import lombok.RequiredArgsConstructor; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.api.WxCpOaCalendarService; +import me.chanjar.weixin.cp.api.WxCpService; +import me.chanjar.weixin.cp.bean.oa.calendar.WxCpOaCalendar; + +import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.CALENDAR_ADD; + +/** + * . + * + * @author Binary Wang + * @date 2020-09-20 + */ +@RequiredArgsConstructor +public class WxCpOaCalendarServiceImpl implements WxCpOaCalendarService { + private final WxCpService wxCpService; + + @Override + public String add(WxCpOaCalendar calendar) throws WxErrorException { + return this.wxCpService.post(this.wxCpService.getWxCpConfigStorage().getApiUrl(CALENDAR_ADD),calendar.toJson()); + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java index 17a2ba274d..c5dc8faf34 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java @@ -7,6 +7,7 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.cp.api.WxCpOaService; import me.chanjar.weixin.cp.api.WxCpService; @@ -42,18 +43,18 @@ public String apply(WxCpOaApplyEventRequest request) throws WxErrorException { public List getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime, List userIdList) throws WxErrorException { if (startTime == null || endTime == null) { - throw new RuntimeException("starttime and endtime can't be null"); + throw new WxRuntimeException("starttime and endtime can't be null"); } if (userIdList == null || userIdList.size() > USER_IDS_LIMIT) { - throw new RuntimeException("用户列表不能为空,不超过 " + USER_IDS_LIMIT + " 个,若用户超过 " + USER_IDS_LIMIT + " 个,请分批获取"); + throw new WxRuntimeException("用户列表不能为空,不超过 " + USER_IDS_LIMIT + " 个,若用户超过 " + USER_IDS_LIMIT + " 个,请分批获取"); } long endTimestamp = endTime.getTime() / 1000L; long startTimestamp = startTime.getTime() / 1000L; if (endTimestamp - startTimestamp < 0 || endTimestamp - startTimestamp >= MONTH_SECONDS) { - throw new RuntimeException("获取记录时间跨度不超过一个月"); + throw new WxRuntimeException("获取记录时间跨度不超过一个月"); } JsonObject jsonObject = new JsonObject(); @@ -83,11 +84,11 @@ public List getCheckinData(Integer openCheckinDataType, Date st @Override public List getCheckinOption(Date datetime, List userIdList) throws WxErrorException { if (datetime == null) { - throw new RuntimeException("datetime can't be null"); + throw new WxRuntimeException("datetime can't be null"); } if (userIdList == null || userIdList.size() > USER_IDS_LIMIT) { - throw new RuntimeException("用户列表不能为空,不超过 " + USER_IDS_LIMIT + " 个,若用户超过 " + USER_IDS_LIMIT + " 个,请分批获取"); + throw new WxRuntimeException("用户列表不能为空,不超过 " + USER_IDS_LIMIT + " 个,若用户超过 " + USER_IDS_LIMIT + " 个,请分批获取"); } JsonArray jsonArray = new JsonArray(); @@ -186,7 +187,7 @@ public List getDialRecord(Date startTime, Date endTime, Integer long starttimestamp = startTime.getTime() / 1000L; if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= MONTH_SECONDS) { - throw new RuntimeException("受限于网络传输,起止时间的最大跨度为30天,如超过30天,则以结束时间为基准向前取30天进行查询"); + throw new WxRuntimeException("受限于网络传输,起止时间的最大跨度为30天,如超过30天,则以结束时间为基准向前取30天进行查询"); } jsonObject.addProperty("start_time", starttimestamp); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java index 076d0205a5..b428bc34aa 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java @@ -5,6 +5,7 @@ import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; @@ -72,7 +73,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); this.configStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn()); } catch (IOException e) { - throw new RuntimeException(e); + throw new WxRuntimeException(e); } } return this.configStorage.getAccessToken(); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceImpl.java index e78432b5a2..6f74702f68 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceImpl.java @@ -5,6 +5,7 @@ import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.cp.constant.WxCpApiPathConsts; import org.apache.http.client.config.RequestConfig; @@ -68,7 +69,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); getWxCpConfigStorage().updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn()); } catch (IOException e) { - throw new RuntimeException(e); + throw new WxRuntimeException(e); } } finally { lock.unlock(); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOnTpImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOnTpImpl.java index 35eab626a7..aa30385d6c 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOnTpImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOnTpImpl.java @@ -3,7 +3,7 @@ import lombok.RequiredArgsConstructor; import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.error.WxErrorException; -import me.chanjar.weixin.cp.api.WxCpTpService; +import me.chanjar.weixin.cp.tp.service.WxCpTpService; /** *
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequest.java
new file mode 100644
index 0000000000..678995590b
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequest.java
@@ -0,0 +1,101 @@
+package me.chanjar.weixin.cp.bean.external;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+
+import java.io.Serializable;
+
+/**
+ * 修改客户备注信息请求.
+ *
+ * @author Binary Wang
+ * @date 2020-09-19
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@Accessors(chain = true)
+public class WxCpUpdateRemarkRequest implements Serializable {
+  private static final long serialVersionUID = -4960239393895754138L;
+
+  public String toJson() {
+    return WxCpGsonBuilder.create().toJson(this);
+  }
+
+  /**
+   * 
+   * 字段名:userid
+   * 是否必须:是
+   * 描述:企业成员的userid
+   * 
+ */ + @SerializedName("userid") + private String userId; + + /** + *
+   * 字段名:external_userid
+   * 是否必须:是
+   * 描述:外部联系人userid
+   * 
+ */ + @SerializedName("external_userid") + private String externalUserId; + + /** + *
+   * 字段名:remark
+   * 是否必须:否
+   * 描述:此用户对外部联系人的备注,最多20个字符
+   * 
+ */ + @SerializedName("remark") + private String remark; + + /** + *
+   * 字段名:description
+   * 是否必须:否
+   * 描述:此用户对外部联系人的描述,最多150个字符
+   * 
+ */ + @SerializedName("description") + private String description; + + /** + *
+   * 字段名:remark_company
+   * 是否必须:否
+   * 描述:此用户对外部联系人备注的所属公司名称,最多20个字符
+   * 
+ */ + @SerializedName("remark_company") + private String remarkCompany; + + /** + *
+   * 字段名:remark_mobiles
+   * 是否必须:否
+   * 描述:此用户对外部联系人备注的手机号
+   * 
+ */ + @SerializedName("remark_mobiles") + private String[] remarkMobiles; + + /** + *
+   * 字段名:remark_pic_mediaid
+   * 是否必须:否
+   * 描述:备注图片的mediaid,
+   * 
+ */ + @SerializedName("remark_pic_mediaid") + private String remarkPicMediaId; + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessage.java index a035f1d54d..36ea3fc3fb 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessage.java @@ -6,6 +6,7 @@ import lombok.Data; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.XmlUtils; import me.chanjar.weixin.common.util.xml.IntegerArrayConverter; import me.chanjar.weixin.common.util.xml.LongArrayConverter; @@ -294,6 +295,20 @@ public class WxCpXmlMessage implements Serializable { @XStreamConverter(value = XStreamCDataConverter.class) private String address; + /** + * 日程ID. + */ + @XStreamAlias("ScheduleId") + @XStreamConverter(value = XStreamCDataConverter.class) + private String scheduleId; + + /** + * 日历ID. + */ + @XStreamAlias("CalId") + @XStreamConverter(value = XStreamCDataConverter.class) + private String calId; + /** * 扩展属性. */ @@ -436,7 +451,7 @@ public static WxCpXmlMessage fromEncryptedXml(InputStream is, WxCpConfigStorage try { return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8), wxCpConfigStorage, timestamp, nonce, msgSignature); } catch (IOException e) { - throw new RuntimeException(e); + throw new WxRuntimeException(e); } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/calendar/WxCpOaCalendar.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/calendar/WxCpOaCalendar.java new file mode 100644 index 0000000000..d4d9fd7f7a --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/calendar/WxCpOaCalendar.java @@ -0,0 +1,105 @@ +package me.chanjar.weixin.cp.bean.oa.calendar; + +import com.google.common.collect.ImmutableMap; +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 日历. + * + * @author Binary Wang + * @date 2020-09-20 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +public class WxCpOaCalendar implements Serializable { + private static final long serialVersionUID = -817988838579546989L; + + /** + * 变量名:organizer + * 是否必须:是 + * 描述:指定的组织者userid。注意该字段指定后不可更新 + */ + @SerializedName("organizer") + private String organizer; + + /** + * 变量名:readonly + * 是否必须:否 + * 描述:日历组织者对日历是否只读权限(即不可编辑日历,不可在日历上添加日程,仅可作为组织者删除日历)。0-否;1-是。默认为1,即只读 + */ + @SerializedName("readonly") + private Integer readonly; + + /** + * 变量名:set_as_default + * 是否必须:否 + * 描述:是否将该日历设置为组织者的默认日历。0-否;1-是。默认为0,即不设为默认日历 + */ + @SerializedName("set_as_default") + private Integer setAsDefault; + + /** + * 变量名:summary + * 是否必须:是 + * 描述:日历标题。1 ~ 128 字符 + */ + @SerializedName("summary") + private String summary; + + /** + * 变量名:color + * 是否必须:是 + * 描述:日历在终端上显示的颜色,RGB颜色编码16进制表示,例如:”#0000FF” 表示纯蓝色 + */ + @SerializedName("color") + private String color; + + /** + * 变量名:description + * 是否必须:否 + * 描述:日历描述。0 ~ 512 字符 + */ + @SerializedName("description") + private String description; + + /** + * 变量名:shares + * 是否必须:否 + * 描述:日历共享成员列表。最多2000人 + */ + @SerializedName("shares") + private List shares; + + @Data + @AllArgsConstructor + public static class ShareInfo implements Serializable { + private static final long serialVersionUID = -4882781114860754679L; + + /** + * 日历共享成员的id + */ + private String userid; + + /** + * 共享成员对日历是否只读权限(即不可编辑日历,不可在日历上添加日程,仅可以退出日历)。 + * 0-否;1-是。默认为1,即只读 + */ + private Integer readonly; + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(ImmutableMap.of("calendar",this)); + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index 6fd219ff06..66132553b1 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -101,6 +101,11 @@ public static class Oa { public static final String GET_DIAL_RECORD = "/cgi-bin/dial/get_dial_record"; public static final String GET_TEMPLATE_DETAIL = "/cgi-bin/oa/gettemplatedetail"; public static final String APPLY_EVENT = "/cgi-bin/oa/applyevent"; + + public static final String CALENDAR_ADD = "/cgi-bin/oa/calendar/add"; + public static final String CALENDAR_UPDATE = "/cgi-bin/oa/calendar/update"; + public static final String CALENDAR_GET = "/cgi-bin/oa/calendar/get"; + public static final String CALENDAR_DEL = "/cgi-bin/oa/calendar/del"; } @UtilityClass @@ -159,6 +164,7 @@ public static class ExternalContact { public static final String CLOSE_TEMP_CHAT = "/cgi-bin/externalcontact/close_temp_chat"; public static final String GET_FOLLOW_USER_LIST = "/cgi-bin/externalcontact/get_follow_user_list"; public static final String GET_CONTACT_DETAIL = "/cgi-bin/externalcontact/get?external_userid="; + public static final String UPDATE_REMARK = "/cgi-bin/externalcontact/remark"; public static final String LIST_EXTERNAL_CONTACT = "/cgi-bin/externalcontact/list?userid="; public static final String LIST_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/get_unassigned_list"; public static final String TRANSFER_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/transfer"; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java index 98bfd90ba0..8da4ce43de 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java @@ -99,10 +99,39 @@ public static class EventType { public static final String CHANGE_EXTERNAL_CONTACT = "change_external_contact"; /** - * 企业微信审批事件推送 + * 企业微信审批事件推送(自建应用审批) */ public static final String OPEN_APPROVAL_CHANGE = "open_approval_change"; + /** + * 企业微信审批事件推送(系统审批) + */ + public static final String SYS_APPROVAL_CHANGE = "sys_approval_change"; + + /** + * 修改日历事件 + */ + public static final String MODIFY_CALENDAR = "modify_calendar"; + + /** + * 删除日历事件 + */ + public static final String DELETE_CALENDAR = "delete_calendar"; + + /** + * 添加日程事件 + */ + public static final String ADD_SCHEDULE = "add_schedule"; + + /** + * 修改日程事件 + */ + public static final String MODIFY_SCHEDULE = "modify_schedule"; + + /** + * 删除日程事件 + */ + public static final String DELETE_SCHEDULE = "delete_schedule"; } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageHandler.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageHandler.java index 68e38d3bb5..5d77444dd2 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageHandler.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageHandler.java @@ -16,11 +16,14 @@ public interface WxCpMessageHandler { /** - * @param wxMessage + * Handle wx cp xml out message. + * + * @param wxMessage the wx message * @param context 上下文,如果handler或interceptor之间有信息要传递,可以用这个 - * @param wxCpService - * @param sessionManager - * @return xml格式的消息,如果在异步规则里处理的话,可以返回null + * @param wxCpService the wx cp service + * @param sessionManager the session manager + * @return xml格式的消息 ,如果在异步规则里处理的话,可以返回null + * @throws WxErrorException the wx error exception */ WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map context, diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageInterceptor.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageInterceptor.java index 5bcca55ee8..45d3976b79 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageInterceptor.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageInterceptor.java @@ -17,11 +17,12 @@ public interface WxCpMessageInterceptor { /** * 拦截微信消息 * - * @param wxMessage + * @param wxMessage the wx message * @param context 上下文,如果handler或interceptor之间有信息要传递,可以用这个 - * @param wxCpService - * @param sessionManager - * @return true代表OK,false代表不OK + * @param wxCpService the wx cp service + * @param sessionManager the session manager + * @return true代表OK ,false代表不OK + * @throws WxErrorException the wx error exception */ boolean intercept(WxCpXmlMessage wxMessage, Map context, diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageMatcher.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageMatcher.java index 42db8f5dd4..7fc7581171 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageMatcher.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageMatcher.java @@ -4,11 +4,16 @@ /** * 消息匹配器,用在消息路由的时候 + * + * @author Daniel Qian */ public interface WxCpMessageMatcher { /** * 消息是否匹配某种模式 + * + * @param message the message + * @return the boolean */ boolean match(WxCpXmlMessage message); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouter.java index bf1ad6e5fe..92de0c238a 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouter.java @@ -1,15 +1,7 @@ package me.chanjar.weixin.cp.message; -import java.util.*; -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 com.google.common.util.concurrent.ThreadFactoryBuilder; +import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.api.WxErrorExceptionHandler; import me.chanjar.weixin.common.api.WxMessageDuplicateChecker; import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker; @@ -20,6 +12,13 @@ import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage; import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.*; /** *
@@ -49,9 +48,9 @@
  *
  * @author Daniel Qian
  */
+@Slf4j
 public class WxCpMessageRouter {
   private static final int DEFAULT_THREAD_POOL_SIZE = 100;
-  private final Logger log = LoggerFactory.getLogger(WxCpMessageRouter.class);
   private final List rules = new ArrayList<>();
 
   private final WxCpService wxCpService;
@@ -69,7 +68,9 @@ public class WxCpMessageRouter {
    */
   public WxCpMessageRouter(WxCpService wxCpService) {
     this.wxCpService = wxCpService;
-    this.executorService = Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE);
+    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("WxCpMessageRouter-pool-%d").build();
+    this.executorService = new ThreadPoolExecutor(DEFAULT_THREAD_POOL_SIZE, DEFAULT_THREAD_POOL_SIZE,
+      0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), namedThreadFactory);
     this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker();
     this.sessionManager = wxCpService.getSessionManager();
     this.exceptionHandler = new LogExceptionHandler();
@@ -156,37 +157,31 @@ public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage, final Map {
+            rule.service(wxMessage, context, WxCpMessageRouter.this.wxCpService, WxCpMessageRouter.this.sessionManager, WxCpMessageRouter.this.exceptionHandler);
           })
         );
       } else {
         res = rule.service(wxMessage, context, this.wxCpService, this.sessionManager, this.exceptionHandler);
         // 在同步操作结束,session访问结束
-        this.log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUserName());
+        log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUserName());
         sessionEndAccess(wxMessage);
       }
     }
 
     if (futures.size() > 0) {
-      this.executorService.submit(new Runnable() {
-        @Override
-        public void run() {
-          for (Future future : futures) {
-            try {
-              future.get();
-              WxCpMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUserName());
-              // 异步操作结束,session访问结束
-              sessionEndAccess(wxMessage);
-            } catch (InterruptedException e) {
-              WxCpMessageRouter.this.log.error("Error happened when wait task finish", e);
-              Thread.currentThread().interrupt();
-            } catch (ExecutionException e) {
-              WxCpMessageRouter.this.log.error("Error happened when wait task finish", e);
-            }
+      this.executorService.submit(() -> {
+        for (Future future : futures) {
+          try {
+            future.get();
+            log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUserName());
+            // 异步操作结束,session访问结束
+            sessionEndAccess(wxMessage);
+          } catch (InterruptedException e) {
+            log.error("Error happened when wait task finish", e);
+            Thread.currentThread().interrupt();
+          } catch (ExecutionException e) {
+            log.error("Error happened when wait task finish", e);
           }
         }
       });
@@ -198,7 +193,7 @@ public void run() {
    * 处理微信消息.
    */
   public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) {
-    return this.route(wxMessage, new HashMap(2));
+    return this.route(wxMessage, new HashMap<>(2));
   }
 
   private boolean isMsgDuplicated(WxCpXmlMessage wxMessage) {
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouterRule.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouterRule.java
index 3c7b5c66f5..739bb0330f 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouterRule.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouterRule.java
@@ -1,5 +1,6 @@
 package me.chanjar.weixin.cp.message;
 
+import lombok.Data;
 import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
 import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.common.session.WxSessionManager;
@@ -8,14 +9,16 @@
 import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
 import org.apache.commons.lang3.StringUtils;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.regex.Pattern;
 
+/**
+ * The type Wx cp message router rule.
+ *
+ * @author Daniel Qian
+ */
+@Data
 public class WxCpMessageRouterRule {
-
   private final WxCpMessageRouter routerBuilder;
 
   private boolean async = true;
@@ -44,6 +47,11 @@ public class WxCpMessageRouterRule {
 
   private List interceptors = new ArrayList<>();
 
+  /**
+   * Instantiates a new Wx cp message router rule.
+   *
+   * @param routerBuilder the router builder
+   */
   protected WxCpMessageRouterRule(WxCpMessageRouter routerBuilder) {
     this.routerBuilder = routerBuilder;
   }
@@ -51,7 +59,8 @@ protected WxCpMessageRouterRule(WxCpMessageRouter routerBuilder) {
   /**
    * 设置是否异步执行,默认是true
    *
-   * @param async
+   * @param async the async
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule async(boolean async) {
     this.async = async;
@@ -61,7 +70,8 @@ public WxCpMessageRouterRule async(boolean async) {
   /**
    * 如果agentId匹配
    *
-   * @param agentId
+   * @param agentId the agent id
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule agentId(Integer agentId) {
     this.agentId = agentId;
@@ -71,7 +81,8 @@ public WxCpMessageRouterRule agentId(Integer agentId) {
   /**
    * 如果msgType等于某值
    *
-   * @param msgType
+   * @param msgType the msg type
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule msgType(String msgType) {
     this.msgType = msgType;
@@ -81,7 +92,8 @@ public WxCpMessageRouterRule msgType(String msgType) {
   /**
    * 如果event等于某值
    *
-   * @param event
+   * @param event the event
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule event(String event) {
     this.event = event;
@@ -91,7 +103,8 @@ public WxCpMessageRouterRule event(String event) {
   /**
    * 如果eventKey等于某值
    *
-   * @param eventKey
+   * @param eventKey the event key
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule eventKey(String eventKey) {
     this.eventKey = eventKey;
@@ -100,6 +113,9 @@ public WxCpMessageRouterRule eventKey(String eventKey) {
 
   /**
    * 如果eventKey匹配该正则表达式
+   *
+   * @param regex the regex
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule eventKeyRegex(String regex) {
     this.eventKeyRegex = regex;
@@ -109,7 +125,8 @@ public WxCpMessageRouterRule eventKeyRegex(String regex) {
   /**
    * 如果content等于某值
    *
-   * @param content
+   * @param content the content
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule content(String content) {
     this.content = content;
@@ -119,7 +136,8 @@ public WxCpMessageRouterRule content(String content) {
   /**
    * 如果content匹配该正则表达式
    *
-   * @param regex
+   * @param regex the regex
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule rContent(String regex) {
     this.rContent = regex;
@@ -129,7 +147,8 @@ public WxCpMessageRouterRule rContent(String regex) {
   /**
    * 如果fromUser等于某值
    *
-   * @param fromUser
+   * @param fromUser the from user
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule fromUser(String fromUser) {
     this.fromUser = fromUser;
@@ -139,7 +158,8 @@ public WxCpMessageRouterRule fromUser(String fromUser) {
   /**
    * 如果消息匹配某个matcher,用在用户需要自定义更复杂的匹配规则的时候
    *
-   * @param matcher
+   * @param matcher the matcher
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule matcher(WxCpMessageMatcher matcher) {
     this.matcher = matcher;
@@ -149,7 +169,8 @@ public WxCpMessageRouterRule matcher(WxCpMessageMatcher matcher) {
   /**
    * 设置微信消息拦截器
    *
-   * @param interceptor
+   * @param interceptor the interceptor
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule interceptor(WxCpMessageInterceptor interceptor) {
     return interceptor(interceptor, (WxCpMessageInterceptor[]) null);
@@ -158,15 +179,14 @@ public WxCpMessageRouterRule interceptor(WxCpMessageInterceptor interceptor) {
   /**
    * 设置微信消息拦截器
    *
-   * @param interceptor
-   * @param otherInterceptors
+   * @param interceptor       the interceptor
+   * @param otherInterceptors the other interceptors
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule interceptor(WxCpMessageInterceptor interceptor, WxCpMessageInterceptor... otherInterceptors) {
     this.interceptors.add(interceptor);
     if (otherInterceptors != null && otherInterceptors.length > 0) {
-      for (WxCpMessageInterceptor i : otherInterceptors) {
-        this.interceptors.add(i);
-      }
+      Collections.addAll(this.interceptors, otherInterceptors);
     }
     return this;
   }
@@ -174,7 +194,8 @@ public WxCpMessageRouterRule interceptor(WxCpMessageInterceptor interceptor, WxC
   /**
    * 设置微信消息处理器
    *
-   * @param handler
+   * @param handler the handler
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule handler(WxCpMessageHandler handler) {
     return handler(handler, (WxCpMessageHandler[]) null);
@@ -183,21 +204,22 @@ public WxCpMessageRouterRule handler(WxCpMessageHandler handler) {
   /**
    * 设置微信消息处理器
    *
-   * @param handler
-   * @param otherHandlers
+   * @param handler       the handler
+   * @param otherHandlers the other handlers
+   * @return the wx cp message router rule
    */
   public WxCpMessageRouterRule handler(WxCpMessageHandler handler, WxCpMessageHandler... otherHandlers) {
     this.handlers.add(handler);
     if (otherHandlers != null && otherHandlers.length > 0) {
-      for (WxCpMessageHandler i : otherHandlers) {
-        this.handlers.add(i);
-      }
+      Collections.addAll(this.handlers, otherHandlers);
     }
     return this;
   }
 
   /**
    * 规则结束,代表如果一个消息匹配该规则,那么它将不再会进入其他规则
+   *
+   * @return the wx cp message router
    */
   public WxCpMessageRouter end() {
     this.routerBuilder.getRules().add(this);
@@ -206,12 +228,20 @@ public WxCpMessageRouter end() {
 
   /**
    * 规则结束,但是消息还会进入其他规则
+   *
+   * @return the wx cp message router
    */
   public WxCpMessageRouter next() {
     this.reEnter = true;
     return end();
   }
 
+  /**
+   * Test boolean.
+   *
+   * @param wxMessage the wx message
+   * @return the boolean
+   */
   protected boolean test(WxCpXmlMessage wxMessage) {
     return
       (this.fromUser == null || this.fromUser.equals(wxMessage.getFromUserName()))
@@ -237,7 +267,11 @@ protected boolean test(WxCpXmlMessage wxMessage) {
   /**
    * 处理微信推送过来的消息
    *
-   * @param wxMessage
+   * @param wxMessage        the wx message
+   * @param context          the context
+   * @param wxCpService      the wx cp service
+   * @param sessionManager   the session manager
+   * @param exceptionHandler the exception handler
    * @return true 代表继续执行别的router,false 代表停止执行别的router
    */
   protected WxCpXmlOutMessage service(WxCpXmlMessage wxMessage,
@@ -274,60 +308,5 @@ protected WxCpXmlOutMessage service(WxCpXmlMessage wxMessage,
 
   }
 
-  public void setFromUser(String fromUser) {
-    this.fromUser = fromUser;
-  }
-
-  public void setMsgType(String msgType) {
-    this.msgType = msgType;
-  }
-
-  public void setEvent(String event) {
-    this.event = event;
-  }
-
-  public void setEventKey(String eventKey) {
-    this.eventKey = eventKey;
-  }
-
-  public void setContent(String content) {
-    this.content = content;
-  }
-
-  public void setrContent(String rContent) {
-    this.rContent = rContent;
-  }
-
-  public void setMatcher(WxCpMessageMatcher matcher) {
-    this.matcher = matcher;
-  }
-
-  public void setAgentId(Integer agentId) {
-    this.agentId = agentId;
-  }
-
-  public void setHandlers(List handlers) {
-    this.handlers = handlers;
-  }
-
-  public void setInterceptors(List interceptors) {
-    this.interceptors = interceptors;
-  }
-
-  public boolean isAsync() {
-    return this.async;
-  }
-
-  public void setAsync(boolean async) {
-    this.async = async;
-  }
-
-  public boolean isReEnter() {
-    return this.reEnter;
-  }
-
-  public void setReEnter(boolean reEnter) {
-    this.reEnter = reEnter;
-  }
 
 }
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageHandler.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageHandler.java
new file mode 100644
index 0000000000..9ab718180c
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageHandler.java
@@ -0,0 +1,33 @@
+package me.chanjar.weixin.cp.tp.message;
+
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.session.WxSessionManager;
+import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
+import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
+import me.chanjar.weixin.cp.tp.service.WxCpTpService;
+
+import java.util.Map;
+
+/**
+ * 处理微信推送消息的处理器接口
+ *
+ * @author Daniel Qian
+ */
+public interface WxCpTpMessageHandler {
+
+  /**
+   * Handle wx cp xml out message.
+   *
+   * @param wxMessage      the wx message
+   * @param context        上下文,如果handler或interceptor之间有信息要传递,可以用这个
+   * @param wxCpService    the wx cp service
+   * @param sessionManager the session manager
+   * @return xml格式的消息 ,如果在异步规则里处理的话,可以返回null
+   * @throws WxErrorException the wx error exception
+   */
+  WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage,
+                           Map context,
+                           WxCpTpService wxCpService,
+                           WxSessionManager sessionManager) throws WxErrorException;
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageInterceptor.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageInterceptor.java
new file mode 100644
index 0000000000..fe5ceefa0f
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageInterceptor.java
@@ -0,0 +1,32 @@
+package me.chanjar.weixin.cp.tp.message;
+
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.session.WxSessionManager;
+import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
+import me.chanjar.weixin.cp.tp.service.WxCpTpService;
+
+import java.util.Map;
+
+/**
+ * 微信消息拦截器,可以用来做验证
+ *
+ * @author Daniel Qian
+ */
+public interface WxCpTpMessageInterceptor {
+
+  /**
+   * 拦截微信消息
+   *
+   * @param wxMessage      the wx message
+   * @param context        上下文,如果handler或interceptor之间有信息要传递,可以用这个
+   * @param wxCpService    the wx cp service
+   * @param sessionManager the session manager
+   * @return true代表OK ,false代表不OK
+   * @throws WxErrorException the wx error exception
+   */
+  boolean intercept(WxCpXmlMessage wxMessage,
+                    Map context,
+                    WxCpTpService wxCpService,
+                    WxSessionManager sessionManager) throws WxErrorException;
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageMatcher.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageMatcher.java
new file mode 100644
index 0000000000..8f7decf4b3
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageMatcher.java
@@ -0,0 +1,20 @@
+package me.chanjar.weixin.cp.tp.message;
+
+import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
+
+/**
+ * 消息匹配器,用在消息路由的时候
+ *
+ * @author Daniel Qian
+ */
+public interface WxCpTpMessageMatcher {
+
+  /**
+   * 消息是否匹配某种模式
+   *
+   * @param message the message
+   * @return the boolean
+   */
+  boolean match(WxCpXmlMessage message);
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageRouter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageRouter.java
new file mode 100644
index 0000000000..147f324dba
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageRouter.java
@@ -0,0 +1,235 @@
+package me.chanjar.weixin.cp.tp.message;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
+import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
+import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
+import me.chanjar.weixin.common.session.InternalSession;
+import me.chanjar.weixin.common.session.InternalSessionManager;
+import me.chanjar.weixin.common.session.WxSessionManager;
+import me.chanjar.weixin.common.util.LogExceptionHandler;
+import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
+import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
+import me.chanjar.weixin.cp.message.WxCpMessageRouterRule;
+import me.chanjar.weixin.cp.tp.service.WxCpTpService;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.*;
+
+/**
+ * 
+ * 微信消息路由器,通过代码化的配置,把来自微信的消息交给handler处理
+ *
+ * 说明:
+ * 1. 配置路由规则时要按照从细到粗的原则,否则可能消息可能会被提前处理
+ * 2. 默认情况下消息只会被处理一次,除非使用 {@link WxCpMessageRouterRule#next()}
+ * 3. 规则的结束必须用{@link WxCpMessageRouterRule#end()}或者{@link WxCpMessageRouterRule#next()},否则不会生效
+ *
+ * 使用方法:
+ * WxCpMessageRouter router = new WxCpMessageRouter();
+ * router
+ *   .rule()
+ *       .msgType("MSG_TYPE").event("EVENT").eventKey("EVENT_KEY").content("CONTENT")
+ *       .interceptor(interceptor, ...).handler(handler, ...)
+ *   .end()
+ *   .rule()
+ *       // 另外一个匹配规则
+ *   .end()
+ * ;
+ *
+ * // 将WxXmlMessage交给消息路由器
+ * router.route(message);
+ *
+ * 
+ * + * @author Daniel Qian + */ +@Slf4j +public class WxCpTpMessageRouter { + private static final int DEFAULT_THREAD_POOL_SIZE = 100; + private final List rules = new ArrayList<>(); + + private final WxCpTpService wxCpService; + + private ExecutorService executorService; + + private WxMessageDuplicateChecker messageDuplicateChecker; + + private WxSessionManager sessionManager; + + private WxErrorExceptionHandler exceptionHandler; + + /** + * 构造方法. + */ + public WxCpTpMessageRouter(WxCpTpService wxCpService) { + this.wxCpService = wxCpService; + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("WxCpTpMessageRouter-pool-%d").build(); + this.executorService = new ThreadPoolExecutor(DEFAULT_THREAD_POOL_SIZE, DEFAULT_THREAD_POOL_SIZE, + 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), namedThreadFactory); + this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker(); + this.sessionManager = wxCpService.getSessionManager(); + this.exceptionHandler = new LogExceptionHandler(); + } + + /** + *
+   * 设置自定义的 {@link ExecutorService}
+   * 如果不调用该方法,默认使用 Executors.newFixedThreadPool(100)
+   * 
+ */ + public void setExecutorService(ExecutorService executorService) { + this.executorService = executorService; + } + + /** + *
+   * 设置自定义的 {@link WxMessageDuplicateChecker}
+   * 如果不调用该方法,默认使用 {@link WxMessageInMemoryDuplicateChecker}
+   * 
+ */ + public void setMessageDuplicateChecker(WxMessageDuplicateChecker messageDuplicateChecker) { + this.messageDuplicateChecker = messageDuplicateChecker; + } + + /** + *
+   * 设置自定义的{@link WxSessionManager}
+   * 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.session.StandardSessionManager}
+   * 
+ */ + public void setSessionManager(WxSessionManager sessionManager) { + this.sessionManager = sessionManager; + } + + /** + *
+   * 设置自定义的{@link WxErrorExceptionHandler}
+   * 如果不调用该方法,默认使用 {@link LogExceptionHandler}
+   * 
+ */ + public void setExceptionHandler(WxErrorExceptionHandler exceptionHandler) { + this.exceptionHandler = exceptionHandler; + } + + List getRules() { + return this.rules; + } + + /** + * 开始一个新的Route规则. + */ + public WxCpTpMessageRouterRule rule() { + return new WxCpTpMessageRouterRule(this); + } + + /** + * 处理微信消息. + */ + public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage, final Map context) { + if (isMsgDuplicated(wxMessage)) { + // 如果是重复消息,那么就不做处理 + return null; + } + + final List matchRules = new ArrayList<>(); + // 收集匹配的规则 + for (final WxCpTpMessageRouterRule rule : this.rules) { + if (rule.test(wxMessage)) { + matchRules.add(rule); + if (!rule.isReEnter()) { + break; + } + } + } + + if (matchRules.size() == 0) { + return null; + } + + WxCpXmlOutMessage res = null; + final List futures = new ArrayList<>(); + for (final WxCpTpMessageRouterRule rule : matchRules) { + // 返回最后一个非异步的rule的执行结果 + if (rule.isAsync()) { + futures.add( + this.executorService.submit(() -> { + rule.service(wxMessage, context, WxCpTpMessageRouter.this.wxCpService, WxCpTpMessageRouter.this.sessionManager, WxCpTpMessageRouter.this.exceptionHandler); + }) + ); + } else { + res = rule.service(wxMessage, context, this.wxCpService, this.sessionManager, this.exceptionHandler); + // 在同步操作结束,session访问结束 + log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUserName()); + sessionEndAccess(wxMessage); + } + } + + if (futures.size() > 0) { + this.executorService.submit(() -> { + for (Future future : futures) { + try { + future.get(); + log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUserName()); + // 异步操作结束,session访问结束 + sessionEndAccess(wxMessage); + } catch (InterruptedException e) { + log.error("Error happened when wait task finish", e); + Thread.currentThread().interrupt(); + } catch (ExecutionException e) { + log.error("Error happened when wait task finish", e); + } + } + }); + } + return res; + } + + /** + * 处理微信消息. + */ + public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) { + return this.route(wxMessage, new HashMap<>(2)); + } + + private boolean isMsgDuplicated(WxCpXmlMessage wxMessage) { + StringBuilder messageId = new StringBuilder(); + if (wxMessage.getMsgId() == null) { + messageId.append(wxMessage.getCreateTime()) + .append("-").append(StringUtils.trimToEmpty(String.valueOf(wxMessage.getAgentId()))) + .append("-").append(wxMessage.getFromUserName()) + .append("-").append(StringUtils.trimToEmpty(wxMessage.getEventKey())) + .append("-").append(StringUtils.trimToEmpty(wxMessage.getEvent())); + } else { + messageId.append(wxMessage.getMsgId()) + .append("-").append(wxMessage.getCreateTime()) + .append("-").append(wxMessage.getFromUserName()); + } + + if (StringUtils.isNotEmpty(wxMessage.getUserId())) { + messageId.append("-").append(wxMessage.getUserId()); + } + + if (StringUtils.isNotEmpty(wxMessage.getChangeType())) { + messageId.append("-").append(wxMessage.getChangeType()); + } + + return this.messageDuplicateChecker.isDuplicate(messageId.toString()); + } + + /** + * 对session的访问结束. + */ + private void sessionEndAccess(WxCpXmlMessage wxMessage) { + InternalSession session = ((InternalSessionManager) this.sessionManager).findSession(wxMessage.getFromUserName()); + if (session != null) { + session.endAccess(); + } + + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageRouterRule.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageRouterRule.java new file mode 100644 index 0000000000..8494978e28 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageRouterRule.java @@ -0,0 +1,313 @@ +package me.chanjar.weixin.cp.tp.message; + +import lombok.Data; +import me.chanjar.weixin.common.api.WxErrorExceptionHandler; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage; +import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage; +import me.chanjar.weixin.cp.message.WxCpMessageMatcher; +import me.chanjar.weixin.cp.tp.service.WxCpTpService; +import org.apache.commons.lang3.StringUtils; + +import java.util.*; +import java.util.regex.Pattern; + +/** + * The type Wx cp message router rule. + * + * @author Daniel Qian + */ +@Data +public class WxCpTpMessageRouterRule { + private final WxCpTpMessageRouter routerBuilder; + + private boolean async = true; + + private String fromUser; + + private String msgType; + + private String event; + + private String eventKey; + + private String eventKeyRegex; + + private String content; + + private String rContent; + + private WxCpMessageMatcher matcher; + + private boolean reEnter = false; + + private Integer agentId; + + private List handlers = new ArrayList<>(); + + private List interceptors = new ArrayList<>(); + + /** + * Instantiates a new Wx cp message router rule. + * + * @param routerBuilder the router builder + */ + protected WxCpTpMessageRouterRule(WxCpTpMessageRouter routerBuilder) { + this.routerBuilder = routerBuilder; + } + + /** + * 设置是否异步执行,默认是true + * + * @param async the async + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule async(boolean async) { + this.async = async; + return this; + } + + /** + * 如果agentId匹配 + * + * @param agentId the agent id + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule agentId(Integer agentId) { + this.agentId = agentId; + return this; + } + + /** + * 如果msgType等于某值 + * + * @param msgType the msg type + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule msgType(String msgType) { + this.msgType = msgType; + return this; + } + + /** + * 如果event等于某值 + * + * @param event the event + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule event(String event) { + this.event = event; + return this; + } + + /** + * 如果eventKey等于某值 + * + * @param eventKey the event key + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule eventKey(String eventKey) { + this.eventKey = eventKey; + return this; + } + + /** + * 如果eventKey匹配该正则表达式 + * + * @param regex the regex + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule eventKeyRegex(String regex) { + this.eventKeyRegex = regex; + return this; + } + + /** + * 如果content等于某值 + * + * @param content the content + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule content(String content) { + this.content = content; + return this; + } + + /** + * 如果content匹配该正则表达式 + * + * @param regex the regex + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule rContent(String regex) { + this.rContent = regex; + return this; + } + + /** + * 如果fromUser等于某值 + * + * @param fromUser the from user + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule fromUser(String fromUser) { + this.fromUser = fromUser; + return this; + } + + /** + * 如果消息匹配某个matcher,用在用户需要自定义更复杂的匹配规则的时候 + * + * @param matcher the matcher + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule matcher(WxCpMessageMatcher matcher) { + this.matcher = matcher; + return this; + } + + /** + * 设置微信消息拦截器 + * + * @param interceptor the interceptor + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule interceptor(WxCpTpMessageInterceptor interceptor) { + return interceptor(interceptor, (WxCpTpMessageInterceptor[]) null); + } + + /** + * 设置微信消息拦截器 + * + * @param interceptor the interceptor + * @param otherInterceptors the other interceptors + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule interceptor(WxCpTpMessageInterceptor interceptor, WxCpTpMessageInterceptor... otherInterceptors) { + this.interceptors.add(interceptor); + if (otherInterceptors != null && otherInterceptors.length > 0) { + Collections.addAll(this.interceptors, otherInterceptors); + } + return this; + } + + /** + * 设置微信消息处理器 + * + * @param handler the handler + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule handler(WxCpTpMessageHandler handler) { + return handler(handler, (WxCpTpMessageHandler[]) null); + } + + /** + * 设置微信消息处理器 + * + * @param handler the handler + * @param otherHandlers the other handlers + * @return the wx cp message router rule + */ + public WxCpTpMessageRouterRule handler(WxCpTpMessageHandler handler, WxCpTpMessageHandler... otherHandlers) { + this.handlers.add(handler); + if (otherHandlers != null && otherHandlers.length > 0) { + Collections.addAll(this.handlers, otherHandlers); + } + return this; + } + + /** + * 规则结束,代表如果一个消息匹配该规则,那么它将不再会进入其他规则 + * + * @return the wx cp message router + */ + public WxCpTpMessageRouter end() { + this.routerBuilder.getRules().add(this); + return this.routerBuilder; + } + + /** + * 规则结束,但是消息还会进入其他规则 + * + * @return the wx cp message router + */ + public WxCpTpMessageRouter next() { + this.reEnter = true; + return end(); + } + + /** + * Test boolean. + * + * @param wxMessage the wx message + * @return the boolean + */ + protected boolean test(WxCpXmlMessage wxMessage) { + return + (this.fromUser == null || this.fromUser.equals(wxMessage.getFromUserName())) + && + (this.agentId == null || this.agentId.equals(wxMessage.getAgentId())) + && + (this.msgType == null || this.msgType.equalsIgnoreCase(wxMessage.getMsgType())) + && + (this.event == null || this.event.equalsIgnoreCase(wxMessage.getEvent())) + && + (this.eventKey == null || this.eventKey.equalsIgnoreCase(wxMessage.getEventKey())) + && + (this.eventKeyRegex == null || Pattern.matches(this.eventKeyRegex, StringUtils.trimToEmpty(wxMessage.getEventKey()))) + && + (this.content == null || this.content.equals(StringUtils.trimToNull(wxMessage.getContent()))) + && + (this.rContent == null || Pattern.matches(this.rContent, StringUtils.trimToEmpty(wxMessage.getContent()))) + && + (this.matcher == null || this.matcher.match(wxMessage)) + ; + } + + /** + * 处理微信推送过来的消息 + * + * @param wxMessage the wx message + * @param context the context + * @param wxCpService the wx cp service + * @param sessionManager the session manager + * @param exceptionHandler the exception handler + * @return true 代表继续执行别的router,false 代表停止执行别的router + */ + protected WxCpXmlOutMessage service(WxCpXmlMessage wxMessage, + Map context, + WxCpTpService wxCpService, + WxSessionManager sessionManager, + WxErrorExceptionHandler exceptionHandler) { + + if (context == null) { + context = new HashMap<>(2); + } + + try { + // 如果拦截器不通过 + for (WxCpTpMessageInterceptor interceptor : this.interceptors) { + if (!interceptor.intercept(wxMessage, context, wxCpService, sessionManager)) { + return null; + } + } + + // 交给handler处理 + WxCpXmlOutMessage res = null; + for (WxCpTpMessageHandler handler : this.handlers) { + // 返回最后handler的结果 + res = handler.handle(wxMessage, context, wxCpService, sessionManager); + } + return res; + + } catch (WxErrorException e) { + exceptionHandler.handle(e); + } + + return null; + + } + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java similarity index 72% rename from weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java index ad2f403af6..26da1ddd48 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java @@ -1,7 +1,8 @@ -package me.chanjar.weixin.cp.api; +package me.chanjar.weixin.cp.tp.service; import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; @@ -12,7 +13,7 @@ import me.chanjar.weixin.cp.config.WxCpTpConfigStorage; /** - * 微信第三方应用API的Service. + * 企业微信第三方应用API的Service. * * @author zhenjun cai */ @@ -27,13 +28,16 @@ public interface WxCpTpService { * @param timestamp 时间戳 * @param nonce 随机数 * @param data 微信传输过来的数据,有可能是echoStr,有可能是xml消息 + * @return the boolean */ boolean checkSignature(String msgSignature, String timestamp, String nonce, String data); /** * 获取suite_access_token, 不强制刷新suite_access_token * - * @see #getSuiteAccessToken(boolean) + * @return the suite access token + * @throws WxErrorException the wx error exception + * @see #getSuiteAccessToken(boolean) #getSuiteAccessToken(boolean) */ String getSuiteAccessToken() throws WxErrorException; @@ -47,13 +51,17 @@ public interface WxCpTpService { *
* * @param forceRefresh 强制刷新 + * @return the suite access token + * @throws WxErrorException the wx error exception */ String getSuiteAccessToken(boolean forceRefresh) throws WxErrorException; /** * 获得suite_ticket,不强制刷新suite_ticket * - * @see #getSuiteTicket(boolean) + * @return the suite ticket + * @throws WxErrorException the wx error exception + * @see #getSuiteTicket(boolean) #getSuiteTicket(boolean) */ String getSuiteTicket() throws WxErrorException; @@ -66,6 +74,8 @@ public interface WxCpTpService { *
* * @param forceRefresh 强制刷新 + * @return the suite ticket + * @throws WxErrorException the wx error exception */ String getSuiteTicket(boolean forceRefresh) throws WxErrorException; @@ -73,6 +83,8 @@ public interface WxCpTpService { * 小程序登录凭证校验 * * @param jsCode 登录时获取的 code + * @return the wx cp ma js code 2 session result + * @throws WxErrorException the wx error exception */ WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException; @@ -81,6 +93,8 @@ public interface WxCpTpService { * * @param authCorpid 授权方corpid * @param permanentCode 永久授权码,通过get_permanent_code获取 + * @return the corp token + * @throws WxErrorException the wx error exception */ WxAccessToken getCorpToken(String authCorpid, String permanentCode) throws WxErrorException; @@ -88,7 +102,8 @@ public interface WxCpTpService { * 获取企业永久授权码 . * * @param authCode . - * @return . + * @return . permanent code + * @throws WxErrorException the wx error exception */ @Deprecated WxCpTpCorp getPermanentCode(String authCode) throws WxErrorException; @@ -99,13 +114,11 @@ public interface WxCpTpService { * 原来的方法实现不全 *
* - * @param authCode - * @return - * + * @param authCode the auth code + * @return permanent code info + * @throws WxErrorException the wx error exception * @author yuan - * @since 2020-03-18 - * - * @throws WxErrorException + * @since 2020 -03-18 */ WxCpTpPermanentCodeInfo getPermanentCodeInfo(String authCode) throws WxErrorException; @@ -113,28 +126,31 @@ public interface WxCpTpService { *
    *   获取预授权链接
    * 
+ * * @param redirectUri 授权完成后的回调网址 - * @param state a-zA-Z0-9的参数值(不超过128个字节),用于第三方自行校验session,防止跨域攻击 - * @return - * @throws WxErrorException + * @param state a-zA-Z0-9的参数值(不超过128个字节),用于第三方自行校验session,防止跨域攻击 + * @return pre auth url + * @throws WxErrorException the wx error exception */ - String getPreAuthUrl(String redirectUri,String state) throws WxErrorException; + String getPreAuthUrl(String redirectUri, String state) throws WxErrorException; /** * 获取企业的授权信息 * - * @param authCorpId 授权企业的corpId + * @param authCorpId 授权企业的corpId * @param permanentCode 授权企业的永久授权码 - * @return - * @throws WxErrorException + * @return auth info + * @throws WxErrorException the wx error exception */ - WxCpTpAuthInfo getAuthInfo(String authCorpId,String permanentCode) throws WxErrorException; + WxCpTpAuthInfo getAuthInfo(String authCorpId, String permanentCode) throws WxErrorException; /** * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求. * * @param url 接口地址 * @param queryParam 请求参数 + * @return the string + * @throws WxErrorException the wx error exception */ String get(String url, String queryParam) throws WxErrorException; @@ -143,6 +159,8 @@ public interface WxCpTpService { * * @param url 接口地址 * @param postData 请求body字符串 + * @return the string + * @throws WxErrorException the wx error exception */ String post(String url, String postData) throws WxErrorException; @@ -153,11 +171,13 @@ public interface WxCpTpService { * 可以参考,{@link MediaUploadRequestExecutor}的实现方法 * * + * @param 请求值类型 + * @param 返回值类型 * @param executor 执行器 * @param uri 请求地址 * @param data 参数 - * @param 请求值类型 - * @param 返回值类型 + * @return the t + * @throws WxErrorException the wx error exception */ T execute(RequestExecutor executor, String uri, E data) throws WxErrorException; @@ -189,7 +209,7 @@ public interface WxCpTpService { /** * 获取WxMpConfigStorage 对象. * - * @return WxMpConfigStorage + * @return WxMpConfigStorage wx cp tp config storage */ WxCpTpConfigStorage getWxCpTpConfigStorage(); @@ -202,7 +222,15 @@ public interface WxCpTpService { /** * http请求对象. + * + * @return the request http */ RequestHttp getRequestHttp(); + /** + * 获取WxSessionManager 对象 + * + * @return WxSessionManager session manager + */ + WxSessionManager getSessionManager(); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java similarity index 89% rename from weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java index 191bfec0d8..a0c0b26495 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java @@ -1,14 +1,17 @@ -package me.chanjar.weixin.cp.api.impl; +package me.chanjar.weixin.cp.tp.service.impl; import com.google.common.base.Joiner; import com.google.gson.JsonObject; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.bean.WxAccessToken; +import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.error.WxCpErrorMsgEnum; import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.error.WxRuntimeException; +import me.chanjar.weixin.common.session.StandardSessionManager; +import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.util.DataUtils; import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.common.util.http.RequestExecutor; @@ -16,9 +19,9 @@ import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; import me.chanjar.weixin.common.util.json.GsonParser; -import me.chanjar.weixin.cp.api.WxCpTpService; import me.chanjar.weixin.cp.bean.*; import me.chanjar.weixin.cp.config.WxCpTpConfigStorage; +import me.chanjar.weixin.cp.tp.service.WxCpTpService; import org.apache.commons.lang3.StringUtils; import java.io.File; @@ -49,6 +52,8 @@ public abstract class BaseWxCpTpServiceImpl implements WxCpTpService, Requ protected WxCpTpConfigStorage configStorage; + private WxSessionManager sessionManager = new StandardSessionManager(); + /** * 临时文件目录. */ @@ -127,7 +132,7 @@ public WxCpTpCorp getPermanentCode(String authCode) throws WxErrorException { } @Override - public WxCpTpPermanentCodeInfo getPermanentCodeInfo(String authCode) throws WxErrorException{ + public WxCpTpPermanentCodeInfo getPermanentCodeInfo(String authCode) throws WxErrorException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("auth_code", authCode); String result = post(configStorage.getApiUrl(GET_PERMANENT_CODE), jsonObject.toString()); @@ -136,18 +141,19 @@ public WxCpTpPermanentCodeInfo getPermanentCodeInfo(String authCode) throws WxEr @Override @SneakyThrows - public String getPreAuthUrl(String redirectUri,String state) throws WxErrorException{ - String result = get(configStorage.getApiUrl(GET_PREAUTH_CODE),null); - WxCpTpPreauthCode preauthCode = WxCpTpPreauthCode.fromJson(result); - String preAuthUrl = "https://open.work.weixin.qq.com/3rdapp/install?suite_id="+configStorage.getSuiteId()+ - "&pre_auth_code="+preauthCode.getPreAuthCode()+"&redirect_uri="+ URLEncoder.encode(redirectUri,"utf-8"); - if(StringUtils.isNotBlank(state)) - preAuthUrl += "&state="+state; + public String getPreAuthUrl(String redirectUri, String state) throws WxErrorException { + String result = get(configStorage.getApiUrl(GET_PREAUTH_CODE), null); + WxCpTpPreauthCode preAuthCode = WxCpTpPreauthCode.fromJson(result); + String preAuthUrl = "https://open.work.weixin.qq.com/3rdapp/install?suite_id=" + configStorage.getSuiteId() + + "&pre_auth_code=" + preAuthCode.getPreAuthCode() + "&redirect_uri=" + URLEncoder.encode(redirectUri, "utf-8"); + if (StringUtils.isNotBlank(state)) { + preAuthUrl += "&state=" + state; + } return preAuthUrl; } @Override - public WxCpTpAuthInfo getAuthInfo(String authCorpId, String permanentCode) throws WxErrorException{ + public WxCpTpAuthInfo getAuthInfo(String authCorpId, String permanentCode) throws WxErrorException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("auth_corpid", authCorpId); jsonObject.addProperty("permanent_code", permanentCode); @@ -178,7 +184,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro if (retryTimes + 1 > this.maxRetryTimes) { log.warn("重试达到最大次数【{}】", this.maxRetryTimes); //最后一次重试失败后,直接抛出异常,不再等待 - throw new RuntimeException("微信服务端异常,超出重试次数"); + throw new WxRuntimeException("微信服务端异常,超出重试次数"); } WxError error = e.getError(); @@ -200,7 +206,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro } while (retryTimes++ < this.maxRetryTimes); log.warn("重试达到最大次数【{}】", this.maxRetryTimes); - throw new RuntimeException("微信服务端异常,超出重试次数"); + throw new WxRuntimeException("微信服务端异常,超出重试次数"); } protected T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { @@ -239,7 +245,7 @@ protected T executeInternal(RequestExecutor executor, String uri, E return null; } catch (IOException e) { log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage()); - throw new RuntimeException(e); + throw new WxRuntimeException(e); } } @@ -273,4 +279,9 @@ public void setTmpDirFile(File tmpDirFile) { return this; } + @Override + public WxSessionManager getSessionManager() { + return this.sessionManager; + } + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceApacheHttpClientImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceApacheHttpClientImpl.java similarity index 96% rename from weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceApacheHttpClientImpl.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceApacheHttpClientImpl.java index cdc6b2cfc0..22962d933b 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceApacheHttpClientImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceApacheHttpClientImpl.java @@ -1,10 +1,11 @@ -package me.chanjar.weixin.cp.api.impl; +package me.chanjar.weixin.cp.tp.service.impl; import com.google.gson.JsonObject; import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; @@ -81,7 +82,7 @@ public String getSuiteAccessToken(boolean forceRefresh) throws WxErrorException Integer expiresIn = jsonObject.get("expires_in").getAsInt(); this.configStorage.updateSuiteAccessToken(suiteAccussToken, expiresIn); } catch (IOException e) { - throw new RuntimeException(e); + throw new WxRuntimeException(e); } } return this.configStorage.getSuiteAccessToken(); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceImpl.java similarity index 82% rename from weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceImpl.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceImpl.java index f5582021e7..58fb09cf97 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceImpl.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.cp.api.impl; +package me.chanjar.weixin.cp.tp.service.impl; /** *
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java
index 5ec9d14824..835f89cc50 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java
@@ -16,6 +16,8 @@
 
 import java.lang.reflect.Type;
 
+import static me.chanjar.weixin.cp.bean.WxCpUser.*;
+
 /**
  * cp user gson adapter.
  *
@@ -104,7 +106,7 @@ private void buildExtraAttrs(JsonObject o, WxCpUser user) {
     JsonArray attrJsonElements = o.get(EXTRA_ATTR).getAsJsonObject().get("attrs").getAsJsonArray();
     for (JsonElement attrJsonElement : attrJsonElements) {
       final Integer type = GsonHelper.getInteger(attrJsonElement.getAsJsonObject(), "type");
-      final WxCpUser.Attr attr = new WxCpUser.Attr().setType(type)
+      final Attr attr = new Attr().setType(type)
         .setName(GsonHelper.getString(attrJsonElement.getAsJsonObject(), "name"));
       user.getExtAttrs().add(attr);
 
@@ -142,7 +144,7 @@ private void buildExternalAttrs(JsonObject o, WxCpUser user) {
       switch (type) {
         case 0: {
           user.getExternalAttrs()
-            .add(WxCpUser.ExternalAttribute.builder()
+            .add(ExternalAttribute.builder()
               .type(type)
               .name(name)
               .value(GsonHelper.getString(element.getAsJsonObject().get("text").getAsJsonObject(), "value"))
@@ -153,7 +155,7 @@ private void buildExternalAttrs(JsonObject o, WxCpUser user) {
         case 1: {
           final JsonObject web = element.getAsJsonObject().get("web").getAsJsonObject();
           user.getExternalAttrs()
-            .add(WxCpUser.ExternalAttribute.builder()
+            .add(ExternalAttribute.builder()
               .type(type)
               .name(name)
               .url(GsonHelper.getString(web, "url"))
@@ -165,7 +167,7 @@ private void buildExternalAttrs(JsonObject o, WxCpUser user) {
         case 2: {
           final JsonObject miniprogram = element.getAsJsonObject().get("miniprogram").getAsJsonObject();
           user.getExternalAttrs()
-            .add(WxCpUser.ExternalAttribute.builder()
+            .add(ExternalAttribute.builder()
               .type(type)
               .name(name)
               .appid(GsonHelper.getString(miniprogram, "appid"))
@@ -278,7 +280,7 @@ public JsonElement serialize(WxCpUser user, Type typeOfSrc, JsonSerializationCon
 
     if (!user.getExtAttrs().isEmpty()) {
       JsonArray attrsJsonArray = new JsonArray();
-      for (WxCpUser.Attr attr : user.getExtAttrs()) {
+      for (Attr attr : user.getExtAttrs()) {
         JsonObject attrJson = GsonHelper.buildJsonObject("type", attr.getType(),
           "name", attr.getName());
         attrsJsonArray.add(attrJson);
@@ -317,7 +319,7 @@ public JsonElement serialize(WxCpUser user, Type typeOfSrc, JsonSerializationCon
 
     if (!user.getExternalAttrs().isEmpty()) {
       JsonArray attrsJsonArray = new JsonArray();
-      for (WxCpUser.ExternalAttribute attr : user.getExternalAttrs()) {
+      for (ExternalAttribute attr : user.getExternalAttrs()) {
         JsonObject attrJson = GsonHelper.buildJsonObject("type", attr.getType(),
           "name", attr.getName());
 
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java
index e5aa151933..9d89892f4f 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java
@@ -7,6 +7,7 @@
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.xml.XStreamInitializer;
 import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
 import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
@@ -30,7 +31,7 @@ private static  T fromXml(Class clazz, InputStream is) {
   public void configure(Binder binder) {
     try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) {
       if (inputStream == null) {
-        throw new RuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成");
+        throw new WxRuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成");
       }
 
       config = fromXml(WxXmlCpInMemoryConfigStorage.class, inputStream);
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java
index 0bd8a24de3..b8a72add12 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBusyRetryTest.java
@@ -1,8 +1,8 @@
 package me.chanjar.weixin.cp.api;
 
 import lombok.extern.slf4j.Slf4j;
-import me.chanjar.weixin.common.error.WxError;
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.http.RequestExecutor;
 import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
 import org.testng.annotations.DataProvider;
@@ -25,7 +25,7 @@ public synchronized  T executeInternal(
         RequestExecutor executor, String uri, E data)
         throws WxErrorException {
         log.info("Executed");
-        throw new WxErrorException(WxError.builder().errorCode(-1).build());
+        throw new WxErrorException("something");
       }
     };
 
@@ -45,18 +45,15 @@ public void testRetry(WxCpService service) throws WxErrorException {
   public void testRetryInThreadPool(final WxCpService service) throws InterruptedException, ExecutionException {
     // 当线程池中的线程复用的时候,还是能保证相同的重试次数
     ExecutorService executorService = Executors.newFixedThreadPool(1);
-    Runnable runnable = new Runnable() {
-      @Override
-      public void run() {
-        try {
-          System.out.println("=====================");
-          System.out.println(Thread.currentThread().getName() + ": testRetry");
-          service.execute(null, null, null);
-        } catch (WxErrorException e) {
-          throw new RuntimeException(e);
-        } catch (RuntimeException e) {
-          // OK
-        }
+    Runnable runnable = () -> {
+      try {
+        System.out.println("=====================");
+        System.out.println(Thread.currentThread().getName() + ": testRetry");
+        service.execute(null, null, null);
+      } catch (WxErrorException e) {
+        throw new WxRuntimeException(e);
+      } catch (RuntimeException e) {
+        // OK
       }
     };
     Future submit1 = executorService.submit(runnable);
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java
index 112e9f8c38..5e3f665c35 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java
@@ -84,14 +84,11 @@ public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map co
     }).end();
 
     final WxCpXmlMessage m = new WxCpXmlMessage();
-    Runnable r = new Runnable() {
-      @Override
-      public void run() {
-        router.route(m);
-        try {
-          Thread.sleep(1000);
-        } catch (InterruptedException e) {
-        }
+    Runnable r = () -> {
+      router.route(m);
+      try {
+        Thread.sleep(1000);
+      } catch (InterruptedException e) {
       }
     };
     for (int i = 0; i < 10; i++) {
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java
index 9a0fbdbd3d..8cace0fe3e 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java
@@ -217,4 +217,17 @@ public void testSendWelcomeMsg() throws WxErrorException {
       .welcomeCode("abc")
       .build());
   }
+
+  @Test
+  public void testUpdateRemark() throws WxErrorException {
+    this.wxCpService.getExternalContactService().updateRemark(WxCpUpdateRemarkRequest.builder()
+      .description("abc")
+      .userId("aaa")
+      .externalUserId("aaa")
+      .remark("aa")
+      .remarkCompany("aaa")
+      .remarkMobiles(new String[]{"111","222"})
+      .remarkPicMediaId("aaa")
+      .build());
+  }
 }
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImplTest.java
index 40597fa24c..57bd9b750d 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImplTest.java
@@ -46,7 +46,7 @@ public void testSendMarkDown() throws WxErrorException {
       ">类型:用户反馈 \n" +
       ">普通用户反馈:117例 \n" +
       ">VIP用户反馈:15例";
-    robotService.sendMarkDown(content);
+    robotService.sendMarkdown(content);
   }
 
   @Test
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaCalendarServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaCalendarServiceImplTest.java
new file mode 100644
index 0000000000..905dc4995b
--- /dev/null
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaCalendarServiceImplTest.java
@@ -0,0 +1,39 @@
+package me.chanjar.weixin.cp.api.impl;
+
+import com.google.inject.Inject;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.api.ApiTestModule;
+import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.bean.oa.calendar.WxCpOaCalendar;
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
+
+import java.util.Arrays;
+
+/**
+ * 单元测试.
+ *
+ * @author Binary Wang
+ * @date 2020-09-20
+ */
+
+@Test
+@Guice(modules = ApiTestModule.class)
+public class WxCpOaCalendarServiceImplTest {
+  @Inject
+  protected WxCpService wxService;
+
+  @Test
+  public void testAdd() throws WxErrorException {
+    this.wxService.getOaCalendarService().add(WxCpOaCalendar.builder()
+      .organizer("userid1")
+      .readonly(1)
+      .setAsDefault(1)
+      .summary("test_summary")
+      .color("#FF3030")
+      .description("test_describe")
+      .shares(Arrays.asList(new WxCpOaCalendar.ShareInfo("userid2", null),
+        new WxCpOaCalendar.ShareInfo("userid3", 1)))
+      .build());
+  }
+}
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java
index 6f3a76b0ab..758f77970e 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java
@@ -37,7 +37,7 @@ public void testGetCheckinData() throws ParseException, WxErrorException {
     Date startTime = DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.parse("2019-04-11");
     Date endTime = DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.parse("2019-05-10");
 
-    List results = wxService.getOAService()
+    List results = wxService.getOaService()
       .getCheckinData(1, startTime, endTime, Lists.newArrayList("binary"));
 
     assertThat(results).isNotNull();
@@ -51,7 +51,7 @@ public void testGetCheckinData() throws ParseException, WxErrorException {
   public void testGetCheckinOption() throws WxErrorException {
 
     Date now = new Date();
-    List results = wxService.getOAService().getCheckinOption(now, Lists.newArrayList("binary"));
+    List results = wxService.getOaService().getCheckinOption(now, Lists.newArrayList("binary"));
     assertThat(results).isNotNull();
     System.out.println("results ");
     System.out.println(gson.toJson(results));
@@ -61,7 +61,7 @@ public void testGetCheckinOption() throws WxErrorException {
   public void testGetApprovalInfo() throws WxErrorException, ParseException {
     Date startTime = DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.parse("2019-12-01");
     Date endTime = DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.parse("2019-12-31");
-    WxCpApprovalInfo result = wxService.getOAService().getApprovalInfo(startTime, endTime);
+    WxCpApprovalInfo result = wxService.getOaService().getApprovalInfo(startTime, endTime);
 
     assertThat(result).isNotNull();
 
@@ -72,7 +72,7 @@ public void testGetApprovalInfo() throws WxErrorException, ParseException {
   @Test
   public void testGetApprovalDetail() throws WxErrorException {
     String spNo = "201912020001";
-    WxCpApprovalDetailResult result = wxService.getOAService().getApprovalDetail(spNo);
+    WxCpApprovalDetailResult result = wxService.getOaService().getApprovalDetail(spNo);
 
     assertThat(result).isNotNull();
 
@@ -83,7 +83,7 @@ public void testGetApprovalDetail() throws WxErrorException {
   @Test
   public void testGetTemplateDetail() throws WxErrorException {
     String templateId = "3TkZjxugodbqpEMk9j7X6h6zKqYkc7MxQrrFmT7H";
-    WxCpTemplateResult result = wxService.getOAService().getTemplateDetail(templateId);
+    WxCpTemplateResult result = wxService.getOaService().getTemplateDetail(templateId);
     assertThat(result).isNotNull();
     System.out.println("result ");
     System.out.println(gson.toJson(result));
@@ -91,7 +91,7 @@ public void testGetTemplateDetail() throws WxErrorException {
 
   @Test
   public void testApply() throws WxErrorException {
-    this.wxService.getOAService().apply(new WxCpOaApplyEventRequest().setCreatorUserId("123"));
+    this.wxService.getOaService().apply(new WxCpOaApplyEventRequest().setCreatorUserId("123"));
   }
 
   @Test
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequestTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequestTest.java
new file mode 100644
index 0000000000..9564cdf9bc
--- /dev/null
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/external/WxCpUpdateRemarkRequestTest.java
@@ -0,0 +1,42 @@
+package me.chanjar.weixin.cp.bean.external;
+
+import me.chanjar.weixin.common.util.json.GsonParser;
+import org.testng.annotations.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * 单元测试.
+ *
+ * @author Binary Wang
+ * @date 2020-09-20
+ */
+public class WxCpUpdateRemarkRequestTest {
+
+  @Test
+  public void testToJson() {
+    String json = "{\n" +
+      "   \"userid\":\"zhangsan\",\n" +
+      "   \"external_userid\":\"woAJ2GCAAAd1asdasdjO4wKmE8Aabj9AAA\",\n" +
+      "   \"remark\":\"备注信息\",\n" +
+      "   \"description\":\"描述信息\",\n" +
+      "   \"remark_company\":\"腾讯科技\",\n" +
+      "   \"remark_mobiles\":[\n" +
+      "        \"13800000001\",\n" +
+      "        \"13800000002\"\n" +
+      "   ],\n" +
+      "   \"remark_pic_mediaid\":\"MEDIAID\"\n" +
+      "}\n";
+
+    WxCpUpdateRemarkRequest request = WxCpUpdateRemarkRequest.builder()
+      .description("描述信息")
+      .userId("zhangsan")
+      .externalUserId("woAJ2GCAAAd1asdasdjO4wKmE8Aabj9AAA")
+      .remark("备注信息")
+      .remarkCompany("腾讯科技")
+      .remarkMobiles(new String[]{"13800000001","13800000002"})
+      .remarkPicMediaId("MEDIAID")
+      .build();
+    assertThat(request.toJson()).isEqualTo(GsonParser.parse(json).toString());
+  }
+}
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/oa/calendar/WxCpOaCalendarTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/oa/calendar/WxCpOaCalendarTest.java
new file mode 100644
index 0000000000..761b0f8f9a
--- /dev/null
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/oa/calendar/WxCpOaCalendarTest.java
@@ -0,0 +1,52 @@
+package me.chanjar.weixin.cp.bean.oa.calendar;
+
+import me.chanjar.weixin.common.util.json.GsonParser;
+import org.testng.annotations.Test;
+
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * 单元测试.
+ *
+ * @author Binary Wang
+ * @date 2020-09-20
+ */
+public class WxCpOaCalendarTest {
+
+  @Test
+  public void testToJson() {
+    String json = "{\n" +
+      "    \"calendar\" : {\n" +
+      "        \"organizer\" : \"userid1\",\n" +
+      "        \"readonly\" : 1,\n" +
+      "        \"set_as_default\" : 1,\n" +
+      "        \"summary\" : \"test_summary\",\n" +
+      "        \"color\" : \"#FF3030\",\n" +
+      "        \"description\" : \"test_describe\",\n" +
+      "        \"shares\" : [\n" +
+      "            {\n" +
+      "                \"userid\" : \"userid2\"\n" +
+      "            },\n" +
+      "            {\n" +
+      "                \"userid\" : \"userid3\",\n" +
+      "                \"readonly\" : 1\n" +
+      "            }\n" +
+      "        ]\n" +
+      "    }\n" +
+      "}\n";
+
+    assertThat(WxCpOaCalendar.builder()
+      .organizer("userid1")
+      .readonly(1)
+      .setAsDefault(1)
+      .summary("test_summary")
+      .color("#FF3030")
+      .description("test_describe")
+      .shares(Arrays.asList(new WxCpOaCalendar.ShareInfo("userid2", null),
+        new WxCpOaCalendar.ShareInfo("userid3", 1)))
+      .build().toJson())
+      .isEqualTo(GsonParser.parse(json).toString());
+  }
+}
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java
index 2067e03eb9..52bc8e2ab7 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java
@@ -1,24 +1,19 @@
 package me.chanjar.weixin.cp.demo;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
-
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.servlet.ServletHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.common.session.WxSessionManager;
-import me.chanjar.weixin.cp.constant.WxCpConsts;
 import me.chanjar.weixin.cp.api.WxCpService;
 import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
-import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
 import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
 import me.chanjar.weixin.cp.bean.message.WxCpXmlOutTextMessage;
 import me.chanjar.weixin.cp.config.WxCpConfigStorage;
+import me.chanjar.weixin.cp.constant.WxCpConsts;
 import me.chanjar.weixin.cp.message.WxCpMessageHandler;
 import me.chanjar.weixin.cp.message.WxCpMessageRouter;
+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 WxCpDemoServer {
 
@@ -54,30 +49,20 @@ private static void initWeixin() throws IOException {
       wxCpService = new WxCpServiceImpl();
       wxCpService.setWxCpConfigStorage(config);
 
-      WxCpMessageHandler handler = new WxCpMessageHandler() {
-        @Override
-        public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage,
-                                        Map context, WxCpService wxService,
-                                        WxSessionManager sessionManager) {
-          WxCpXmlOutTextMessage m = WxCpXmlOutMessage.TEXT().content("测试加密消息")
-            .fromUser(wxMessage.getToUserName())
-            .toUser(wxMessage.getFromUserName()).build();
-          return m;
-        }
+      WxCpMessageHandler handler = (wxMessage, context, wxService, sessionManager) -> {
+        WxCpXmlOutTextMessage m = WxCpXmlOutMessage.TEXT().content("测试加密消息")
+          .fromUser(wxMessage.getToUserName())
+          .toUser(wxMessage.getFromUserName()).build();
+        return m;
       };
 
-      WxCpMessageHandler oauth2handler = new WxCpMessageHandler() {
-        @Override
-        public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage,
-                                        Map context, WxCpService wxService,
-                                        WxSessionManager sessionManager) {
-          String href = "测试oauth2";
-          return WxCpXmlOutMessage.TEXT().content(href)
-            .fromUser(wxMessage.getToUserName())
-            .toUser(wxMessage.getFromUserName()).build();
-        }
+      WxCpMessageHandler oauth2handler = (wxMessage, context, wxService, sessionManager) -> {
+        String href = "测试oauth2";
+        return WxCpXmlOutMessage.TEXT().content(href)
+          .fromUser(wxMessage.getToUserName())
+          .toUser(wxMessage.getFromUserName()).build();
       };
 
       wxCpMessageRouter = new WxCpMessageRouter(wxCpService);
@@ -93,12 +78,9 @@ public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage,
         .end()
         .rule()
         .event(WxCpConsts.EventType.CHANGE_CONTACT)
-        .handler(new WxCpMessageHandler() {
-          @Override
-          public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map context, WxCpService wxCpService, WxSessionManager sessionManager) throws WxErrorException {
-            System.out.println("通讯录发生变更");
-            return null;
-          }
+        .handler((wxMessage, context, wxCpService, sessionManager) -> {
+          System.out.println("通讯录发生变更");
+          return null;
         })
         .end();
 
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java
index 3f48c32130..a5e785ffdf 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java
@@ -61,7 +61,6 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
       response.getWriter().write(outMessage.toEncryptedXml(this.wxCpConfigStorage));
     }
 
-    return;
   }
 
 }
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImplTest.java
similarity index 91%
rename from weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImplTest.java
rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImplTest.java
index 9f79735612..83ace79f3c 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImplTest.java
@@ -1,20 +1,20 @@
-package me.chanjar.weixin.cp.api.impl;
+package me.chanjar.weixin.cp.tp.service.impl;
 
 import com.google.gson.JsonObject;
 import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.cp.api.WxCpTpService;
 import me.chanjar.weixin.cp.bean.WxCpTpAuthInfo;
 import me.chanjar.weixin.cp.bean.WxCpTpCorp;
 import me.chanjar.weixin.cp.bean.WxCpTpPermanentCodeInfo;
 import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
 import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
+import me.chanjar.weixin.cp.tp.service.WxCpTpService;
+import org.mockito.Mockito;
+import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Tp.GET_AUTH_INFO;
 import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Tp.GET_PERMANENT_CODE;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
-import static org.testng.Assert.*;
 
 /**
  * 测试代码.
@@ -23,7 +23,7 @@
  * @date 2019-08-18
  */
 public class BaseWxCpTpServiceImplTest {
-  private WxCpTpService tpService = spy(new WxCpTpServiceImpl());
+  private final WxCpTpService tpService = Mockito.spy(new WxCpTpServiceImpl());
 
   @Test
   public void testCheckSignature() {
@@ -123,7 +123,7 @@ public void testGetPermanentCode() throws WxErrorException {
     JsonObject jsonObject = new JsonObject();
     String authCode = "";
     jsonObject.addProperty("auth_code", authCode);
-    doReturn(returnJson).when(tpService).post(configStorage.getApiUrl(GET_PERMANENT_CODE), jsonObject.toString());
+    Mockito.doReturn(returnJson).when(tpService).post(configStorage.getApiUrl(GET_PERMANENT_CODE), jsonObject.toString());
 
     final WxCpTpCorp tpCorp = tpService.getPermanentCode(authCode);
     assertThat(tpCorp.getPermanentCode()).isEqualTo("xxxx");
@@ -134,7 +134,7 @@ public void testGetPermanentCode() throws WxErrorException {
   }
 
   @Test
-  public void testGetPermanentCodeInfo() throws WxErrorException{
+  public void testGetPermanentCodeInfo() throws WxErrorException {
     String returnJson = "{\n" +
       "  \"access_token\": \"u6SoEWyrEmworJ1uNzddbiXh42mCLNU_mdd6b01Afo2LKmyi-WdaaYqhEGFZjB1RGZ-rhjLcAJ86ger7b7Q0gowSw9iIDR8dm49aVH_MztzmQttP3XFG7np1Dxs_VQkVwhhRmfRpEonAmK1_JWIFqayJXXiPUS3LsFd3tWpE7rxmsRa7Ev2ml2htbRp_qGUjtFTErKoDsnNGSka6_RqFPA\", \n" +
       "  \"expires_in\": 7200, \n" +
@@ -187,15 +187,15 @@ public void testGetPermanentCodeInfo() throws WxErrorException{
     JsonObject jsonObject = new JsonObject();
     String authCode = "";
     jsonObject.addProperty("auth_code", authCode);
-    doReturn(returnJson).when(tpService).post(configStorage.getApiUrl(GET_PERMANENT_CODE), jsonObject.toString());
+    Mockito.doReturn(returnJson).when(tpService).post(configStorage.getApiUrl(GET_PERMANENT_CODE), jsonObject.toString());
     final WxCpTpPermanentCodeInfo tpPermanentCodeInfo = tpService.getPermanentCodeInfo(authCode);
     assertThat(tpPermanentCodeInfo.getAuthInfo().getAgents().get(0).getAgentId()).isEqualTo(1000012);
-    assertNotNull(tpPermanentCodeInfo.getAuthInfo().getAgents().get(0).getSquareLogoUrl());
-    assertNotNull(tpPermanentCodeInfo.getAuthCorpInfo().getCorpSquareLogoUrl());
+    Assert.assertNotNull(tpPermanentCodeInfo.getAuthInfo().getAgents().get(0).getSquareLogoUrl());
+    Assert.assertNotNull(tpPermanentCodeInfo.getAuthCorpInfo().getCorpSquareLogoUrl());
   }
 
   @Test
-  public void testGetAuthInfo() throws WxErrorException{
+  public void testGetAuthInfo() throws WxErrorException {
     String returnJson = "{\n" +
       "    \"errcode\":0 ,\n" +
       "    \"errmsg\":\"ok\" ,\n" +
@@ -260,9 +260,9 @@ public void testGetAuthInfo() throws WxErrorException{
     String permanentCode = "xxxxx";
     jsonObject.addProperty("auth_corpid", authCorpId);
     jsonObject.addProperty("permanent_code", permanentCode);
-    doReturn(returnJson).when(tpService).post(configStorage.getApiUrl(GET_AUTH_INFO), jsonObject.toString());
-    WxCpTpAuthInfo authInfo = tpService.getAuthInfo(authCorpId,permanentCode);
-    assertNotNull(authInfo.getAuthCorpInfo().getCorpId());
+    Mockito.doReturn(returnJson).when(tpService).post(configStorage.getApiUrl(GET_AUTH_INFO), jsonObject.toString());
+    WxCpTpAuthInfo authInfo = tpService.getAuthInfo(authCorpId, permanentCode);
+    Assert.assertNotNull(authInfo.getAuthCorpInfo().getCorpId());
   }
 
   @Test
diff --git a/weixin-java-miniapp/pom.xml b/weixin-java-miniapp/pom.xml
index 41ddb0a636..43f460ceed 100644
--- a/weixin-java-miniapp/pom.xml
+++ b/weixin-java-miniapp/pom.xml
@@ -7,7 +7,7 @@
   
     com.github.binarywang
     wx-java
-    3.9.2.B
+    3.9.4.B
   
 
   weixin-java-miniapp
@@ -126,7 +126,7 @@
             3.5.1
             
               
-                cn.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor
+                com.github.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor
               
               
                 
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java
index 7bd1eec748..e155fea0dc 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java
@@ -17,6 +17,7 @@
 import me.chanjar.weixin.common.enums.WxType;
 import me.chanjar.weixin.common.error.WxError;
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.DataUtils;
 import me.chanjar.weixin.common.util.crypto.SHA1;
 import me.chanjar.weixin.common.util.http.RequestExecutor;
@@ -155,7 +156,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
       String response = doGetAccessTokenRequest();
       return extractAccessToken(response);
     } catch (IOException | InterruptedException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     } finally {
       if (locked) {
         lock.unlock();
@@ -222,7 +223,7 @@ public  T execute(RequestExecutor executor, String uri, E data) thro
     } while (retryTimes++ < this.maxRetryTimes);
 
     log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
-    throw new RuntimeException("微信服务端异常,超出重试次数");
+    throw new WxRuntimeException("微信服务端异常,超出重试次数");
   }
 
   private  T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException {
@@ -267,7 +268,7 @@ private  T executeInternal(RequestExecutor executor, String uri, E d
       return null;
     } catch (IOException e) {
       log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage());
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     }
   }
 
@@ -354,7 +355,7 @@ public WxMaService switchoverTo(String miniappId) {
       return this;
     }
 
-    throw new RuntimeException(String.format("无法找到对应【%s】的小程序配置信息,请核实!", miniappId));
+    throw new WxRuntimeException(String.format("无法找到对应【%s】的小程序配置信息,请核实!", miniappId));
   }
 
   @Override
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaMessage.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaMessage.java
index 4e06e42394..08a2e5794c 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaMessage.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaMessage.java
@@ -8,6 +8,7 @@
 import com.thoughtworks.xstream.annotations.XStreamAlias;
 import com.thoughtworks.xstream.annotations.XStreamConverter;
 import lombok.Data;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
 import org.apache.commons.io.IOUtils;
 
@@ -174,7 +175,7 @@ public static WxMaMessage fromEncryptedXml(InputStream is, WxMaConfig wxMaConfig
       return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8), wxMaConfig,
         timestamp, nonce, msgSignature);
     } catch (IOException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     }
   }
 
@@ -188,7 +189,7 @@ public static WxMaMessage fromEncryptedJson(String encryptedJson, WxMaConfig con
       String plainText = new WxMaCryptUtils(config).decrypt(encryptedMessage.getEncrypt());
       return fromJson(plainText);
     } catch (Exception e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     }
   }
 
@@ -196,7 +197,7 @@ public static WxMaMessage fromEncryptedJson(InputStream inputStream, WxMaConfig
     try {
       return fromEncryptedJson(IOUtils.toString(inputStream, StandardCharsets.UTF_8), config);
     } catch (IOException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     }
   }
 
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/AbstractWxMaRedisConfig.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/AbstractWxMaRedisConfig.java
index ac75b3697d..9b94a04bbb 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/AbstractWxMaRedisConfig.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/AbstractWxMaRedisConfig.java
@@ -1,6 +1,7 @@
 package cn.binarywang.wx.miniapp.config.impl;
 
 import com.github.jedis.lock.JedisLock;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import redis.clients.jedis.Jedis;
 
 import java.io.File;
@@ -232,10 +233,10 @@ private DistributedLock(String key) {
     public void lock() {
       try (Jedis jedis = getConfiguredJedis()) {
         if (!lock.acquire(jedis)) {
-          throw new RuntimeException("acquire timeouted");
+          throw new WxRuntimeException("acquire timeouted");
         }
       } catch (InterruptedException e) {
-        throw new RuntimeException("lock failed", e);
+        throw new WxRuntimeException("lock failed", e);
       }
     }
 
@@ -243,7 +244,7 @@ public void lock() {
     public void lockInterruptibly() throws InterruptedException {
       try (Jedis jedis = getConfiguredJedis()) {
         if (!lock.acquire(jedis)) {
-          throw new RuntimeException("acquire timeouted");
+          throw new WxRuntimeException("acquire timeouted");
         }
       }
     }
@@ -253,7 +254,7 @@ public boolean tryLock() {
       try (Jedis jedis = getConfiguredJedis()) {
         return lock.acquire(jedis);
       } catch (InterruptedException e) {
-        throw new RuntimeException("lock failed", e);
+        throw new WxRuntimeException("lock failed", e);
       }
     }
 
@@ -273,7 +274,7 @@ public void unlock() {
 
     @Override
     public Condition newCondition() {
-      throw new RuntimeException("unsupported method");
+      throw new WxRuntimeException("unsupported method");
     }
 
   }
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java
index e932da641d..031c688c52 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java
@@ -45,7 +45,7 @@ public WxMaMessageRouter(WxMaService wxMaService) {
     this.wxMaService = wxMaService;
     ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("WxMaMessageRouter-pool-%d").build();
     this.executorService = new ThreadPoolExecutor(DEFAULT_THREAD_POOL_SIZE, DEFAULT_THREAD_POOL_SIZE,
-      0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), namedThreadFactory);
+      0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), namedThreadFactory);
     this.sessionManager = new StandardSessionManager();
     this.exceptionHandler = new LogExceptionHandler();
     this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker();
@@ -88,11 +88,8 @@ private WxMaXmlOutMessage route(final WxMaMessage wxMessage, final Map {
+            rule.service(wxMessage, context, WxMaMessageRouter.this.wxMaService, WxMaMessageRouter.this.sessionManager, WxMaMessageRouter.this.exceptionHandler);
           })
         );
       } else {
@@ -104,18 +101,15 @@ public void run() {
     }
 
     if (futures.size() > 0) {
-      this.executorService.submit(new Runnable() {
-        @Override
-        public void run() {
-          for (Future future : futures) {
-            try {
-              future.get();
-              WxMaMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUser());
-              // 异步操作结束,session访问结束
-              sessionEndAccess(wxMessage);
-            } catch (InterruptedException | ExecutionException e) {
-              WxMaMessageRouter.this.log.error("Error happened when wait task finish", e);
-            }
+      this.executorService.submit(() -> {
+        for (Future future : futures) {
+          try {
+            future.get();
+            WxMaMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUser());
+            // 异步操作结束,session访问结束
+            sessionEndAccess(wxMessage);
+          } catch (InterruptedException | ExecutionException e) {
+            WxMaMessageRouter.this.log.error("Error happened when wait task finish", e);
           }
         }
       });
@@ -124,7 +118,7 @@ public void run() {
   }
 
   public WxMaXmlOutMessage route(final WxMaMessage wxMessage) {
-    return this.route(wxMessage, new HashMap(2));
+    return this.route(wxMessage, new HashMap<>(2));
   }
 
   private boolean isMsgDuplicated(WxMaMessage wxMessage) {
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouterRule.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouterRule.java
index 41f3e99574..99181e0434 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouterRule.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouterRule.java
@@ -6,10 +6,7 @@
 import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.common.session.WxSessionManager;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.regex.Pattern;
 
 /**
@@ -135,9 +132,7 @@ public WxMaMessageRouterRule interceptor(WxMaMessageInterceptor interceptor) {
   public WxMaMessageRouterRule interceptor(WxMaMessageInterceptor interceptor, WxMaMessageInterceptor... otherInterceptors) {
     this.interceptors.add(interceptor);
     if (otherInterceptors != null && otherInterceptors.length > 0) {
-      for (WxMaMessageInterceptor i : otherInterceptors) {
-        this.interceptors.add(i);
-      }
+      Collections.addAll(this.interceptors, otherInterceptors);
     }
     return this;
   }
@@ -155,9 +150,7 @@ public WxMaMessageRouterRule handler(WxMaMessageHandler handler) {
   public WxMaMessageRouterRule handler(WxMaMessageHandler handler, WxMaMessageHandler... otherHandlers) {
     this.handlers.add(handler);
     if (otherHandlers != null && otherHandlers.length > 0) {
-      for (WxMaMessageHandler i : otherHandlers) {
-        this.handlers.add(i);
-      }
+      Collections.addAll(this.handlers, otherHandlers);
     }
     return this;
   }
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/crypt/WxMaCryptUtils.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/crypt/WxMaCryptUtils.java
index 6913541de7..f1a05d001a 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/crypt/WxMaCryptUtils.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/crypt/WxMaCryptUtils.java
@@ -12,6 +12,7 @@
 
 import com.google.common.base.CharMatcher;
 import com.google.common.io.BaseEncoding;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import org.apache.commons.codec.binary.Base64;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 
@@ -47,7 +48,7 @@ public static String decrypt(String sessionKey, String encryptedData, String ivS
 
       return new String(PKCS7Encoder.decode(cipher.doFinal(Base64.decodeBase64(encryptedData))), UTF_8);
     } catch (Exception e) {
-      throw new RuntimeException("AES解密失败!", e);
+      throw new WxRuntimeException("AES解密失败!", e);
     }
   }
 
@@ -78,7 +79,7 @@ public static String decryptAnotherWay(String sessionKey, String encryptedData,
       cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(Base64.decodeBase64(ivStr.getBytes(UTF_8))));
       return new String(cipher.doFinal(Base64.decodeBase64(encryptedData.getBytes(UTF_8))), UTF_8);
     } catch (Exception e) {
-      throw new RuntimeException("AES解密失败!", e);
+      throw new WxRuntimeException("AES解密失败!", e);
     }
   }
 
diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/test/ApiTestModule.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/test/ApiTestModule.java
index 267eb70ca3..a9f5def789 100644
--- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/test/ApiTestModule.java
+++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/test/ApiTestModule.java
@@ -4,6 +4,7 @@
 import java.io.InputStream;
 import java.util.concurrent.locks.ReentrantLock;
 
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -23,7 +24,7 @@ public class ApiTestModule implements Module {
   public void configure(Binder binder) {
     try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) {
       if (inputStream == null) {
-        throw new RuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成");
+        throw new WxRuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成");
       }
       TestConfig config = TestConfig.fromXml(inputStream);
       config.setAccessTokenLock(new ReentrantLock());
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index d1f1ac0fd0..89efb9869d 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -7,7 +7,7 @@
   
     com.github.binarywang
     wx-java
-    3.9.2.B
+    3.9.4.B
   
 
   weixin-java-mp
@@ -115,7 +115,7 @@
             3.5.1
             
               
-                cn.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor
+                com.github.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor
               
               
                 
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 9b2ca03fe9..263305c0d0 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,5 +1,8 @@
 package me.chanjar.weixin.mp.api;
 
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
 import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
 import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
@@ -18,10 +21,7 @@
 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 java.util.concurrent.*;
 
 /**
  * 
@@ -51,9 +51,10 @@
  *
  * @author Daniel Qian
  */
+@Slf4j
+@AllArgsConstructor
 public class WxMpMessageRouter {
   private static final int DEFAULT_THREAD_POOL_SIZE = 100;
-  protected final Logger log = LoggerFactory.getLogger(WxMpMessageRouter.class);
   private final List rules = new ArrayList<>();
 
   private final WxMpService wxMpService;
@@ -68,7 +69,9 @@ public class WxMpMessageRouter {
 
   public WxMpMessageRouter(WxMpService wxMpService) {
     this.wxMpService = wxMpService;
-    this.executorService = Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE);
+    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("WxMpMessageRouter-pool-%d").build();
+    this.executorService = new ThreadPoolExecutor(DEFAULT_THREAD_POOL_SIZE, DEFAULT_THREAD_POOL_SIZE,
+      0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), namedThreadFactory);
     this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker();
     this.sessionManager = new StandardSessionManager();
     this.exceptionHandler = new LogExceptionHandler();
@@ -199,7 +202,7 @@ public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage, final Map future : futures) {
         try {
           future.get();
-          WxMpMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUser());
+          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);
+          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);
+          log.error("Error happened when wait task finish", e);
         }
       }
     });
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java
index ad11e81b41..a742c196c9 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java
@@ -7,10 +7,7 @@
 import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
 import org.apache.commons.lang3.StringUtils;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.regex.Pattern;
 
 public class WxMpMessageRouterRule {
@@ -130,9 +127,7 @@ public WxMpMessageRouterRule interceptor(WxMpMessageInterceptor interceptor) {
   public WxMpMessageRouterRule interceptor(WxMpMessageInterceptor interceptor, WxMpMessageInterceptor... otherInterceptors) {
     this.interceptors.add(interceptor);
     if (otherInterceptors != null && otherInterceptors.length > 0) {
-      for (WxMpMessageInterceptor i : otherInterceptors) {
-        this.interceptors.add(i);
-      }
+      Collections.addAll(this.interceptors, otherInterceptors);
     }
     return this;
   }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
index aa7a872f39..958e7f7309 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
@@ -12,9 +12,7 @@
 import me.chanjar.weixin.common.util.http.RequestHttp;
 import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
 import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo;
-import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
 import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
-import me.chanjar.weixin.mp.bean.result.WxMpUser;
 import me.chanjar.weixin.mp.config.WxMpConfigStorage;
 import me.chanjar.weixin.mp.enums.WxMpApiUrl;
 
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java
index f836cebaa6..966ddc4c05 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java
@@ -17,6 +17,7 @@
 import me.chanjar.weixin.common.enums.WxType;
 import me.chanjar.weixin.common.error.WxError;
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.session.StandardSessionManager;
 import me.chanjar.weixin.common.session.WxSessionManager;
 import me.chanjar.weixin.common.util.DataUtils;
@@ -28,9 +29,7 @@
 import me.chanjar.weixin.mp.api.*;
 import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
 import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo;
-import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
 import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
-import me.chanjar.weixin.mp.bean.result.WxMpUser;
 import me.chanjar.weixin.mp.config.WxMpConfigStorage;
 import me.chanjar.weixin.mp.enums.WxMpApiUrl;
 import me.chanjar.weixin.mp.util.WxMpConfigStorageHolder;
@@ -203,9 +202,8 @@ public String getAccessToken() throws WxErrorException {
   @Override
   public String shortUrl(String longUrl) throws WxErrorException {
     if (longUrl.contains("&access_token=")) {
-      throw new WxErrorException(WxError.builder().errorCode(-1)
-        .errorMsg("要转换的网址中存在非法字符{&access_token=},会导致微信接口报错,属于微信bug,请调整地址,否则不建议使用此方法!")
-        .build());
+      throw new WxErrorException("要转换的网址中存在非法字符{&access_token=}," +
+        "会导致微信接口报错,属于微信bug,请调整地址,否则不建议使用此方法!");
     }
 
     JsonObject o = new JsonObject();
@@ -303,7 +301,7 @@ public  T execute(RequestExecutor executor, String uri, E data) thro
         if (retryTimes + 1 > this.maxRetryTimes) {
           log.warn("重试达到最大次数【{}】", maxRetryTimes);
           //最后一次重试失败后,直接抛出异常,不再等待
-          throw new RuntimeException("微信服务端异常,超出重试次数");
+          throw new WxRuntimeException("微信服务端异常,超出重试次数");
         }
 
         WxError error = e.getError();
@@ -314,7 +312,7 @@ public  T execute(RequestExecutor executor, String uri, E data) thro
             log.warn("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
             Thread.sleep(sleepMillis);
           } catch (InterruptedException e1) {
-            throw new RuntimeException(e1);
+            throw new WxRuntimeException(e1);
           }
         } else {
           throw e;
@@ -323,7 +321,7 @@ public  T execute(RequestExecutor executor, String uri, E data) thro
     } while (retryTimes++ < this.maxRetryTimes);
 
     log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
-    throw new RuntimeException("微信服务端异常,超出重试次数");
+    throw new WxRuntimeException("微信服务端异常,超出重试次数");
   }
 
   protected  T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException {
@@ -448,7 +446,7 @@ public WxMpService switchoverTo(String mpId) {
       return this;
     }
 
-    throw new RuntimeException(String.format("无法找到对应【%s】的公众号配置信息,请核实!", mpId));
+    throw new WxRuntimeException(String.format("无法找到对应【%s】的公众号配置信息,请核实!", mpId));
   }
 
   @Override
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java
index a131e3a9f3..1ed957aae5 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java
@@ -115,11 +115,11 @@ public WxMpKfSessionWaitCaseList kfSessionGetWaitCase() throws WxErrorException
   @Override
   public WxMpKfMsgList kfMsgList(Date startTime, Date endTime, Long msgId, Integer number) throws WxErrorException {
     if (number > 10000) {
-      throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("非法参数请求,每次最多查询10000条记录!").build());
+      throw new WxErrorException("非法参数请求,每次最多查询10000条记录!");
     }
 
     if (startTime.after(endTime)) {
-      throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("起始时间不能晚于结束时间!").build());
+      throw new WxErrorException("起始时间不能晚于结束时间!");
     }
 
     JsonObject param = new JsonObject();
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 a654afb769..7bad648cb5 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
@@ -29,7 +29,7 @@ public class WxMpQrcodeServiceImpl implements WxMpQrcodeService {
   @Override
   public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException {
     if (sceneId == 0) {
-      throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为0!").build());
+      throw new WxErrorException("临时二维码场景值不能为0!");
     }
 
     return this.createQrCode("QR_SCENE", null, sceneId, expireSeconds);
@@ -38,7 +38,7 @@ public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds
   @Override
   public WxMpQrCodeTicket qrCodeCreateTmpTicket(String sceneStr, Integer expireSeconds) throws WxErrorException {
     if (StringUtils.isBlank(sceneStr)) {
-      throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("临时二维码场景值不能为空!").build());
+      throw new WxErrorException("临时二维码场景值不能为空!");
     }
 
     return this.createQrCode("QR_STR_SCENE", sceneStr, null, expireSeconds);
@@ -48,8 +48,7 @@ private WxMpQrCodeTicket createQrCode(String actionName, String sceneStr, Intege
     throws WxErrorException {
     //expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。
     if (expireSeconds != null && expireSeconds > 2592000) {
-      throw new WxErrorException(WxError.builder().errorCode(-1)
-        .errorMsg("临时二维码有效时间最大不能超过2592000(即30天)!").build());
+      throw new WxErrorException("临时二维码有效时间最大不能超过2592000(即30天)!");
     }
 
     if (expireSeconds == null) {
@@ -84,9 +83,7 @@ private WxMpQrCodeTicket getQrCodeTicket(String actionName, String sceneStr, Int
   @Override
   public WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException {
     if (sceneId < 1 || sceneId > 100000) {
-      throw new WxErrorException(WxError.builder().errorCode(-1)
-        .errorMsg("永久二维码的场景值目前只支持1--100000!")
-        .build());
+      throw new WxErrorException("永久二维码的场景值目前只支持1--100000!");
     }
 
     return this.getQrCodeTicket("QR_LIMIT_SCENE", null, sceneId, null);
@@ -113,7 +110,7 @@ public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErr
 
       return resultUrl;
     } catch (UnsupportedEncodingException e) {
-      throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg(e.getMessage()).build());
+      throw new WxErrorException(e.getMessage());
     }
   }
 
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceHttpClientImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceHttpClientImpl.java
index 6e7ee376c7..8b5e029104 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceHttpClientImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceHttpClientImpl.java
@@ -1,6 +1,7 @@
 package me.chanjar.weixin.mp.api.impl;
 
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.http.HttpType;
 import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
 import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
@@ -92,10 +93,10 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
           httpGet.releaseConnection();
         }
       } catch (IOException e) {
-        throw new RuntimeException(e);
+        throw new WxRuntimeException(e);
       }
     } catch (InterruptedException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     } finally {
       if (locked) {
         lock.unlock();
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceJoddHttpImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceJoddHttpImpl.java
index 56b8eb12eb..eb75f1ff62 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceJoddHttpImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceJoddHttpImpl.java
@@ -5,6 +5,7 @@
 import jodd.http.ProxyInfo;
 import jodd.http.net.SocketHttpConnectionProvider;
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.http.HttpType;
 import me.chanjar.weixin.mp.config.WxMpConfigStorage;
 
@@ -77,7 +78,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
 
       return this.extractAccessToken(request.send().bodyText());
     } catch (InterruptedException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     } finally {
       if (locked) {
         lock.unlock();
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java
index 6d6708349f..3639d1bc06 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java
@@ -1,6 +1,7 @@
 package me.chanjar.weixin.mp.api.impl;
 
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.http.HttpType;
 import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
 import me.chanjar.weixin.mp.config.WxMpConfigStorage;
@@ -59,9 +60,9 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
       Response response = getRequestHttpClient().newCall(request).execute();
       return this.extractAccessToken(Objects.requireNonNull(response.body()).string());
     } catch (IOException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     } catch (InterruptedException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     } finally {
       if (locked) {
         lock.unlock();
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxOAuth2ServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxOAuth2ServiceImpl.java
index 3c6287b7dd..7ad8ed2c4a 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxOAuth2ServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxOAuth2ServiceImpl.java
@@ -5,6 +5,7 @@
 import me.chanjar.weixin.common.enums.WxType;
 import me.chanjar.weixin.common.error.WxError;
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.http.RequestExecutor;
 import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
 import me.chanjar.weixin.common.util.http.URIUtil;
@@ -75,7 +76,7 @@ public WxMpUser getUserInfo(WxMpOAuth2AccessToken token, String lang) throws WxE
       String responseText = executor.execute(url, null, WxType.MP);
       return WxMpUser.fromJson(responseText);
     } catch (IOException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     }
   }
 
@@ -86,7 +87,7 @@ public boolean validateAccessToken(WxMpOAuth2AccessToken token) {
     try {
       SimpleGetRequestExecutor.create(this.wxMpService.getRequestHttp()).execute(url, null, WxType.MP);
     } catch (IOException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     } catch (WxErrorException e) {
       return false;
     }
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 f6b54a20b2..adee564f96 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
@@ -5,6 +5,7 @@
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.api.WxConsts;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.XmlUtils;
 import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
 import me.chanjar.weixin.mp.config.WxMpConfigStorage;
@@ -716,7 +717,7 @@ public static WxMpXmlMessage fromEncryptedXml(InputStream is, WxMpConfigStorage
     try {
       return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8), wxMpConfigStorage, timestamp, nonce, msgSignature);
     } catch (IOException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     }
   }
 
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java
index e9e5112d31..679f8db1ac 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java
@@ -2,6 +2,7 @@
 
 import com.google.gson.*;
 import me.chanjar.weixin.common.api.WxConsts.KefuMsgType;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
 import org.apache.commons.lang3.StringUtils;
 
@@ -96,7 +97,7 @@ public JsonElement serialize(WxMpKefuMessage message, Type typeOfSrc, JsonSerial
         break;
       }
       default: {
-        throw new RuntimeException("非法消息类型,暂不支持");
+        throw new WxRuntimeException("非法消息类型,暂不支持");
       }
     }
 
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteJoddHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteJoddHttpRequestExecutor.java
index afc99d62c0..318299bb34 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteJoddHttpRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialDeleteJoddHttpRequestExecutor.java
@@ -12,6 +12,7 @@
 import me.chanjar.weixin.common.util.http.RequestHttp;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 /**
  * Created by ecoolper on 2017/5/5.
@@ -31,7 +32,7 @@ public Boolean execute(String uri, String materialId, WxType wxType) throws WxEr
 
     request.query("media_id", materialId);
     HttpResponse response = request.send();
-    response.charset(StringPool.UTF_8);
+    response.charset(StandardCharsets.UTF_8.name());
     String responseContent = response.bodyText();
     WxError error = WxError.fromJson(responseContent, WxType.MP);
     if (error.getErrorCode() != 0) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialNewsInfoJoddHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialNewsInfoJoddHttpRequestExecutor.java
index 59f0710692..780c0734e1 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialNewsInfoJoddHttpRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialNewsInfoJoddHttpRequestExecutor.java
@@ -7,6 +7,7 @@
 import jodd.http.ProxyInfo;
 import jodd.util.StringPool;
 
+import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.enums.WxType;
 import me.chanjar.weixin.common.error.WxError;
 import me.chanjar.weixin.common.error.WxErrorException;
@@ -18,12 +19,13 @@
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 /**
  * Created by ecoolper on 2017/5/5.
  */
+@Slf4j
 public class MaterialNewsInfoJoddHttpRequestExecutor extends MaterialNewsInfoRequestExecutor {
-  private final Logger logger = LoggerFactory.getLogger(this.getClass());
   public MaterialNewsInfoJoddHttpRequestExecutor(RequestHttp requestHttp) {
     super(requestHttp);
   }
@@ -38,10 +40,10 @@ public WxMpMaterialNews execute(String uri, String materialId, WxType wxType) th
       .withConnectionProvider(requestHttp.getRequestHttpClient())
       .body(WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId)));
     HttpResponse response = request.send();
-    response.charset(StringPool.UTF_8);
+    response.charset(StandardCharsets.UTF_8.name());
 
     String responseContent = response.bodyText();
-    this.logger.debug("响应原始数据:{}", responseContent);
+    log.debug("响应原始数据:{}", responseContent);
     WxError error = WxError.fromJson(responseContent, WxType.MP);
     if (error.getErrorCode() != 0) {
       throw new WxErrorException(error);
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java
index a89687cd22..053ff16cba 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java
@@ -41,7 +41,7 @@ public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material, WxTyp
     }
 
     if (material == null) {
-      throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("非法请求,material参数为空").build());
+      throw new WxErrorException("非法请求,material参数为空");
     }
 
     File file = material.getFile();
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadJoddHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadJoddHttpRequestExecutor.java
index 7699f2f202..d4c4dfbf89 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadJoddHttpRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadJoddHttpRequestExecutor.java
@@ -17,6 +17,7 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.Map;
 
 /**
@@ -36,7 +37,7 @@ public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material, WxTyp
     request.withConnectionProvider(requestHttp.getRequestHttpClient());
 
     if (material == null) {
-      throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("非法请求,material参数为空").build());
+      throw new WxErrorException("非法请求,material参数为空");
     }
 
     File file = material.getFile();
@@ -50,7 +51,7 @@ public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material, WxTyp
     }
 
     HttpResponse response = request.send();
-    response.charset(StringPool.UTF_8);
+    response.charset(StandardCharsets.UTF_8.name());
     String responseContent = response.bodyText();
     WxError error = WxError.fromJson(responseContent, WxType.MP);
     if (error.getErrorCode() != 0) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadOkhttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadOkhttpRequestExecutor.java
index f4654f9fb1..7416f94f0e 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadOkhttpRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadOkhttpRequestExecutor.java
@@ -31,7 +31,7 @@ public MaterialUploadOkhttpRequestExecutor(RequestHttp requestHttp) {
   public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material, WxType wxType) throws WxErrorException, IOException {
     logger.debug("MaterialUploadOkhttpRequestExecutor is running");
     if (material == null) {
-      throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("非法请求,material参数为空").build());
+      throw new WxErrorException("非法请求,material参数为空");
     }
     File file = material.getFile();
     if (file == null || !file.exists()) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoJoddHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoJoddHttpRequestExecutor.java
index f142c21788..9149d46794 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoJoddHttpRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVideoInfoJoddHttpRequestExecutor.java
@@ -13,6 +13,7 @@
 import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 /**
  * Created by ecoolper on 2017/5/5.
@@ -32,7 +33,7 @@ public WxMpMaterialVideoInfoResult execute(String uri, String materialId, WxType
 
     request.query("media_id", materialId);
     HttpResponse response = request.send();
-    response.charset(StringPool.UTF_8);
+    response.charset(StandardCharsets.UTF_8.name());
     String responseContent = response.bodyText();
     WxError error = WxError.fromJson(responseContent, WxType.MP);
     if (error.getErrorCode() != 0) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadJoddHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadJoddHttpRequestExecutor.java
index 1a4c25590c..e4da2004ec 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadJoddHttpRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialVoiceAndImageDownloadJoddHttpRequestExecutor.java
@@ -37,7 +37,7 @@ public InputStream execute(String uri, String materialId, WxType wxType) throws
 
     request.query("media_id", materialId);
     HttpResponse response = request.send();
-    response.charset(StringPool.UTF_8);
+    response.charset(StandardCharsets.UTF_8.name());
     try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
       // 下载媒体文件出错
       byte[] responseContent = IOUtils.toByteArray(inputStream);
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadApacheHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadApacheHttpRequestExecutor.java
index 989e388632..b570a1c43b 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadApacheHttpRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadApacheHttpRequestExecutor.java
@@ -32,7 +32,7 @@ public MediaImgUploadApacheHttpRequestExecutor(RequestHttp requestHttp) {
   @Override
   public WxMediaImgUploadResult execute(String uri, File data, WxType wxType) throws WxErrorException, IOException {
     if (data == null) {
-      throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("文件对象为空").build());
+      throw new WxErrorException("文件对象为空");
     }
 
     HttpPost httpPost = new HttpPost(uri);
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadHttpRequestExecutor.java
index 76c625141e..1ca4c7c8bf 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadHttpRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadHttpRequestExecutor.java
@@ -14,6 +14,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 /**
  * Created by ecoolper on 2017/5/5.
@@ -28,7 +29,7 @@ public MediaImgUploadHttpRequestExecutor(RequestHttp requestHttp) {
   @Override
   public WxMediaImgUploadResult execute(String uri, File data, WxType wxType) throws WxErrorException, IOException {
     if (data == null) {
-      throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("文件对象为空").build());
+      throw new WxErrorException("文件对象为空");
     }
 
     HttpRequest request = HttpRequest.post(uri);
@@ -39,7 +40,7 @@ public WxMediaImgUploadResult execute(String uri, File data, WxType wxType) thro
 
     request.form("media", data);
     HttpResponse response = request.send();
-    response.charset(StringPool.UTF_8);
+    response.charset(StandardCharsets.UTF_8.name());
     String responseContent = response.bodyText();
     WxError error = WxError.fromJson(responseContent, WxType.MP);
     if (error.getErrorCode() != 0) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeJoddHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeJoddHttpRequestExecutor.java
index 99621843db..32d3d3ca75 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeJoddHttpRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeJoddHttpRequestExecutor.java
@@ -19,6 +19,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.UUID;
 
 /**
@@ -47,7 +48,7 @@ public File execute(String uri, WxMpQrCodeTicket ticket, WxType wxType) throws W
     request.withConnectionProvider(requestHttp.getRequestHttpClient());
 
     HttpResponse response = request.send();
-    response.charset(StringPool.UTF_8);
+    response.charset(StandardCharsets.UTF_8.name());
     String contentTypeHeader = response.header("Content-Type");
     if (MimeTypes.MIME_TEXT_PLAIN.equals(contentTypeHeader)) {
       String responseContent = response.bodyText();
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeRequestExecutor.java
index 0a65d2abc7..4ca5dbc0c1 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/qrcode/QrCodeRequestExecutor.java
@@ -37,7 +37,7 @@ public static RequestExecutor create(RequestHttp request
       case OK_HTTP:
         return new QrCodeOkhttpRequestExecutor(requestHttp);
       default:
-        throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("不支持的http框架").build());
+        throw new WxErrorException("不支持的http框架");
     }
   }
 
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/voice/VoiceUploadApacheHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/voice/VoiceUploadApacheHttpRequestExecutor.java
index 3c733a126f..07af44b340 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/voice/VoiceUploadApacheHttpRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/voice/VoiceUploadApacheHttpRequestExecutor.java
@@ -33,7 +33,7 @@ public VoiceUploadApacheHttpRequestExecutor(RequestHttp requestHttp) {
   @Override
   public Boolean execute(String uri, File data, WxType wxType) throws WxErrorException, IOException {
     if (data == null) {
-      throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("文件对象为空").build());
+      throw new WxErrorException("文件对象为空");
     }
 
     HttpPost httpPost = new HttpPost(uri);
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 1f0a01b46e..938eb5c032 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
@@ -3,6 +3,7 @@
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxError;
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.http.RequestExecutor;
 import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
 import org.testng.annotations.*;
@@ -25,7 +26,7 @@ public synchronized  T executeInternal(
         RequestExecutor executor, String uri, E data)
         throws WxErrorException {
         log.info("Executed");
-        throw new WxErrorException(WxError.builder().errorCode(-1).build());
+        throw new WxErrorException("something");
       }
     };
 
@@ -43,18 +44,15 @@ public void testRetry(WxMpService service) throws WxErrorException {
   public void testRetryInThreadPool(final WxMpService service) throws InterruptedException, ExecutionException {
     // 当线程池中的线程复用的时候,还是能保证相同的重试次数
     ExecutorService executorService = Executors.newFixedThreadPool(1);
-    Runnable runnable = new Runnable() {
-      @Override
-      public void run() {
-        try {
-          System.out.println("=====================");
-          System.out.println(Thread.currentThread().getName() + ": testRetry");
-          service.execute(null, (String)null, null);
-        } catch (WxErrorException e) {
-          throw new RuntimeException(e);
-        } catch (RuntimeException e) {
-          // OK
-        }
+    Runnable runnable = () -> {
+      try {
+        System.out.println("=====================");
+        System.out.println(Thread.currentThread().getName() + ": testRetry");
+        service.execute(null, (String)null, null);
+      } catch (WxErrorException e) {
+        throw new WxRuntimeException(e);
+      } catch (RuntimeException e) {
+        // OK
       }
     };
     Future submit1 = executorService.submit(runnable);
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 b9424eb023..93f47a70f5 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
@@ -97,14 +97,11 @@ public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map co
     }).end();
 
     final WxMpXmlMessage m = new WxMpXmlMessage();
-    Runnable r = new Runnable() {
-      @Override
-      public void run() {
-        router.route(m);
-        try {
-          Thread.sleep(1000);
-        } catch (InterruptedException e) {
-        }
+    Runnable r = () -> {
+      router.route(m);
+      try {
+        Thread.sleep(1000);
+      } catch (InterruptedException e) {
       }
     };
     for (int i = 0; i < 10; i++) {
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImplTest.java
index b20d3fe142..1bb8922271 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImplTest.java
@@ -82,15 +82,12 @@ public void refreshAccessTokenDuplicatelyTest() throws InterruptedException {
     // 测试多线程刷新accessToken时是否重复刷新
     wxService.getWxMpConfigStorage().expireAccessToken();
     final Set set = Sets.newConcurrentHashSet();
-    Runnable r = new Runnable() {
-      @Override
-      public void run() {
-        try {
-          String accessToken = wxService.getAccessToken();
-          set.add(accessToken);
-        } catch (WxErrorException e) {
-          e.printStackTrace();
-        }
+    Runnable r = () -> {
+      try {
+        String accessToken = wxService.getAccessToken();
+        set.add(accessToken);
+      } catch (WxErrorException e) {
+        e.printStackTrace();
       }
     };
 
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java
index cc964e80fd..204515934b 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java
@@ -4,6 +4,7 @@
 import java.io.InputStream;
 import java.util.concurrent.locks.ReentrantLock;
 
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -23,7 +24,7 @@ public class ApiTestModule implements Module {
   public void configure(Binder binder) {
     try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) {
       if (inputStream == null) {
-        throw new RuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成");
+        throw new WxRuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成");
       }
 
       TestConfigStorage config = this.fromXml(TestConfigStorage.class, inputStream);
diff --git a/weixin-java-open/pom.xml b/weixin-java-open/pom.xml
index 19d188ac16..03f4e2c00d 100644
--- a/weixin-java-open/pom.xml
+++ b/weixin-java-open/pom.xml
@@ -7,7 +7,7 @@
   
     com.github.binarywang
     wx-java
-    3.9.2.B
+    3.9.4.B
   
 
   weixin-java-open
@@ -122,7 +122,7 @@
             3.5.1
             
               
-                cn.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor
+                com.github.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor
               
               
                 
diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java
index d460152dfa..91b412f883 100644
--- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java
+++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java
@@ -8,6 +8,7 @@
 import me.chanjar.weixin.common.api.WxConsts;
 import me.chanjar.weixin.common.error.WxError;
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.crypto.SHA1;
 import me.chanjar.weixin.common.util.http.URIUtil;
 import me.chanjar.weixin.common.util.json.GsonParser;
@@ -384,7 +385,7 @@ public String getAuthorizerAccessToken(String appId, boolean forceRefresh) throw
       config.updateAuthorizerRefreshToken(appId,wxOpenAuthorizerAccessToken.getAuthorizerRefreshToken());
       return config.getAuthorizerAccessToken(appId);
     } catch (InterruptedException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     } finally {
       if (locked) {
         lock.unlock();
@@ -488,7 +489,7 @@ private String openAccountServicePost(String appId, String appIdType, String req
         result = maService.post(requestUrl, param.toString());
         return result;
       default:
-        throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("appIdType类型异常").build());
+        throw new WxErrorException("appIdType类型异常");
     }
   }
 
diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMpServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMpServiceImpl.java
index 5efa429ade..ab0a9055be 100644
--- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMpServiceImpl.java
+++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMpServiceImpl.java
@@ -1,9 +1,8 @@
 package me.chanjar.weixin.open.api.impl;
 
 import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.mp.config.WxMpConfigStorage;
 import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
-import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
+import me.chanjar.weixin.mp.config.WxMpConfigStorage;
 import me.chanjar.weixin.open.api.WxOpenComponentService;
 
 /**
diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceAbstractImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceAbstractImpl.java
index eb4ffbfb2b..fa89d09377 100644
--- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceAbstractImpl.java
+++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceAbstractImpl.java
@@ -3,6 +3,7 @@
 import me.chanjar.weixin.common.enums.WxType;
 import me.chanjar.weixin.common.error.WxError;
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.http.RequestExecutor;
 import me.chanjar.weixin.common.util.http.RequestHttp;
 import me.chanjar.weixin.open.api.WxOpenComponentService;
@@ -56,7 +57,7 @@ protected  T execute(RequestExecutor executor, String uri, E data) t
       return null;
     } catch (IOException e) {
       this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uri, data, e.getMessage());
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     }
   }
 }
diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/message/WxOpenXmlMessage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/message/WxOpenXmlMessage.java
index bef7d16d26..7a41355920 100644
--- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/message/WxOpenXmlMessage.java
+++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/message/WxOpenXmlMessage.java
@@ -4,6 +4,7 @@
 import com.thoughtworks.xstream.annotations.XStreamConverter;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.error.WxRuntimeException;
 import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
@@ -149,7 +150,7 @@ public static WxOpenXmlMessage fromEncryptedXml(InputStream is, WxOpenConfigStor
       return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8),
         wxOpenConfigStorage, timestamp, nonce, msgSignature);
     } catch (IOException e) {
-      throw new RuntimeException(e);
+      throw new WxRuntimeException(e);
     }
   }
 }
diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/executor/MaQrCodeJoddHttpRequestExecutor.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/executor/MaQrCodeJoddHttpRequestExecutor.java
index 7f24674d9f..fc664483e6 100644
--- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/executor/MaQrCodeJoddHttpRequestExecutor.java
+++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/executor/MaQrCodeJoddHttpRequestExecutor.java
@@ -19,6 +19,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.UUID;
 
 /**
@@ -49,7 +50,7 @@ public File execute(String uri, WxMaQrcodeParam qrcodeParam, WxType wxType) thro
     request.withConnectionProvider(requestHttp.getRequestHttpClient());
 
     HttpResponse response = request.send();
-    response.charset(StringPool.UTF_8);
+    response.charset(StandardCharsets.UTF_8.name());
     String contentTypeHeader = response.header("Content-Type");
     if (MimeTypes.MIME_TEXT_PLAIN.equals(contentTypeHeader)) {
       String responseContent = response.bodyText();
diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/executor/MaQrCodeRequestExecutor.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/executor/MaQrCodeRequestExecutor.java
index dfaec08565..ac02c1ec3d 100644
--- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/executor/MaQrCodeRequestExecutor.java
+++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/executor/MaQrCodeRequestExecutor.java
@@ -38,7 +38,7 @@ public static RequestExecutor create(RequestHttp requestH
       case OK_HTTP:
         return new MaQrCodeOkhttpRequestExecutor(requestHttp);
       default:
-        throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("不支持的http框架").build());
+        throw new WxErrorException("不支持的http框架");
     }
   }
 
diff --git a/weixin-java-pay/pom.xml b/weixin-java-pay/pom.xml
index 629c6fc654..d84db0f466 100644
--- a/weixin-java-pay/pom.xml
+++ b/weixin-java-pay/pom.xml
@@ -5,7 +5,7 @@
   
     com.github.binarywang
     wx-java
-    3.9.2.B
+    3.9.4.B
   
   4.0.0
 
@@ -102,7 +102,7 @@
             3.5.1
             
               
-                cn.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor
+                com.github.binarywang.wx.graal.GraalProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor,lombok.launch.AnnotationProcessorHider$ClaimingProcessor
               
               
                 
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsNotifyResult.java
index 0f0196a8ce..dcfae88247 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsNotifyResult.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsNotifyResult.java
@@ -1,11 +1,9 @@
 package com.github.binarywang.wxpay.bean.ecommerce;
 
-import com.google.gson.annotations.SerializedName;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
-import java.util.List;
 
 /**
  * 合单支付 通知结果
@@ -24,337 +22,8 @@ public class CombineTransactionsNotifyResult implements Serializable {
   private NotifyResponse rawData;
 
   /**
-     * 
-     * 字段名:合单商户appid
-     * 变量名:combine_appid
-     * 是否必填:是
-     * 类型:string(32)
-     * 描述:
-     *  合单发起方的appid。(即电商平台appid)
-     *  示例值:wxd678efh567hg6787
-     * 
- */ - @SerializedName(value = "combine_appid") - private String combineAppid; - - /** - *
-     * 字段名:合单商户号
-     * 变量名:combine_mchid
-     * 是否必填:是
-     * 类型:string(32)
-     * 描述:
-     *  合单发起方商户号。(即电商平台mchid)
-     *  示例值:1900000109
-     * 
- */ - @SerializedName(value = "combine_mchid") - private String combineMchid; - - /** - *
-     * 字段名:合单商户订单号
-     * 变量名:combine_out_trade_no
-     * 是否必填:是
-     * 类型:string(32)
-     * 描述:
-     *  合单支付总订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
-     *  示例值:P20150806125346
-     * 
- */ - @SerializedName(value = "combine_out_trade_no") - private String combineOutTradeNo; - - /** - *
-     * 字段名:+场景信息
-     * 变量名:scene_info
-     * 是否必填:否
-     * 类型:object
-     * 描述:支付场景信息描述
-     * 
- */ - @SerializedName(value = "scene_info") - private SceneInfo sceneInfo; - - /** - *
-     * 字段名:+子单信息
-     * 变量名:sub_orders
-     * 是否必填:是
-     * 类型:array
-     * 描述:
-     *  最多支持子单条数:50
-     *
-     * 
- */ - @SerializedName(value = "sub_orders") - private List subOrders; - - /** - *
-     * 字段名:+支付者
-     * 变量名:combine_payer_info
-     * 是否必填:否
-     * 类型:object
-     * 描述:示例值:见请求示例
-     * 
- */ - @SerializedName(value = "combine_payer_info") - private CombinePayerInfo combinePayerInfo; - - @Data - @NoArgsConstructor - public static class SubOrders implements Serializable { - /** - *
-     * 字段名:子单商户号
-     * 变量名:mchid
-     * 是否必填:是
-     * 类型:string(32)
-     * 描述:
-     *  子单发起方商户号,必须与发起方Appid有绑定关系。(即电商平台mchid)
-     *  示例值:1900000109
-     * 
- */ - @SerializedName(value = "mchid") - private String mchid; - - /** - *
-     * 字段名:交易类型
-     * 变量名:trade_type
-     * 是否必填:是
-     * 类型:string (16)
-     * 描述:
-     *  枚举值:
-     *  NATIVE:扫码支付
-     *  JSAPI:公众号支付
-     *  APP:APP支付
-     *  MWEB:H5支付
-     *  示例值: JSAPI
-     * 
- */ - @SerializedName(value = "trade_type") - private String tradeType; - - /** - *
-     * 字段名:交易状态
-     * 变量名:trade_state
-     * 是否必填:是
-     * 类型:string (32)
-     * 描述:
-     *  枚举值:
-     *  SUCCESS:支付成功
-     *  REFUND:转入退款
-     *  NOTPAY:未支付
-     *  CLOSED:已关闭
-     *  USERPAYING:用户支付中
-     *  PAYERROR:支付失败(其他原因,如银行返回失败)
-     *  示例值: SUCCESS
-     * 
- */ - @SerializedName(value = "trade_state") - private String tradeState; - - /** - *
-     * 字段名:付款银行
-     * 变量名:bank_type
-     * 是否必填:否
-     * 类型:string(16)
-     * 描述:
-     *  银行类型,采用字符串类型的银行标识。
-     *  示例值:CMC
-     * 
- */ - @SerializedName(value = "bank_type") - private String bankType; - - /** - *
-     * 字段名:附加信息
-     * 变量名:attach
-     * 是否必填:是
-     * 类型:string(128)
-     * 描述:
-     *  附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用。
-     *  示例值:深圳分店
-     * 
- */ - @SerializedName(value = "attach") - private String attach; - - /** - *
-     * 字段名:支付完成时间
-     * 变量名:success_time
-     * 是否必填:是
-     * 类型:string(16)
-     * 描述:
-     *  订单支付时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss:sss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss:sss表示时分秒毫秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35.120+08:00表示,北京时间2015年5月20日 13点29分35秒。
-     *  示例值:2015-05-20T13:29:35.120+08:00
-     * 
- */ - @SerializedName(value = "success_time") - private String successTime; - - /** - *
-     * 字段名:微信订单号
-     * 变量名:transaction_id
-     * 是否必填:是
-     * 类型:string(32)
-     * 描述:
-     *  微信支付订单号。
-     *  示例值: 1009660380201506130728806387
-     * 
- */ - @SerializedName(value = "transaction_id") - private String transactionId; - - /** - *
-     * 字段名:子单商户订单号
-     * 变量名:out_trade_no
-     * 是否必填:是
-     * 类型:string(32)
-     * 描述:
-     *  商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
-     *  特殊规则:最小字符长度为6
-     *  示例值:20150806125346
-     * 
- */ - @SerializedName(value = "out_trade_no") - private String outTradeNo; - - /** - *
-     * 字段名:二级商户号
-     * 变量名:sub_mchid
-     * 是否必填:是
-     * 类型:string(32)
-     * 描述:
-     *  二级商户商户号,由微信支付生成并下发。
-     *  注意:仅适用于电商平台 服务商
-     *  示例值:1900000109
-     * 
- */ - @SerializedName(value = "sub_mchid") - private String subMchid; - - /** - *
-     * 字段名:+订单金额
-     * 变量名:amount
-     * 是否必填:是
-     * 类型:object
-     * 描述:订单金额信息
-     * 
- */ - @SerializedName(value = "amount") - private Amount amount; - - } - - @Data - @NoArgsConstructor - public static class SceneInfo implements Serializable { - /** - *
-     * 字段名:商户端设备号
-     * 变量名:device_id
-     * 是否必填:否
-     * 类型:string(16)
-     * 描述:
-     *  终端设备号(门店号或收银设备ID)。
-     *  特殊规则:长度最小7个字节
-     *  示例值:POS1:1
-     * 
- */ - @SerializedName(value = "device_id") - private String deviceId; - - } - - @Data - @NoArgsConstructor - public static class CombinePayerInfo implements Serializable { - /** - *
-     * 字段名:用户标识
-     * 变量名:openid
-     * 是否必填:是
-     * 类型:string(128)
-     * 描述:
-     *  使用合单appid获取的对应用户openid。是用户在商户appid下的唯一标识。
-     *  示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
-     * 
- */ - @SerializedName(value = "openid") - private String openid; - - } - - @Data - @NoArgsConstructor - public static class Amount implements Serializable { - /** - *
-     * 字段名:标价金额
-     * 变量名:total_amount
-     * 是否必填:是
-     * 类型:int64
-     * 描述:
-     *  子单金额,单位为分。
-     *  示例值:100
-     * 
- */ - @SerializedName(value = "total_amount") - private Integer totalAmount; - - /** - *
-     * 字段名:标价币种
-     * 变量名:currency
-     * 是否必填:是
-     * 类型:string(8)
-     * 描述:
-     *  符合ISO 4217标准的三位字母代码,人民币:CNY。
-     *  示例值:CNY
-     * 
- */ - @SerializedName(value = "currency") - private String currency; - - /** - *
-     * 字段名:现金支付金额
-     * 变量名:payer_amount
-     * 是否必填:是
-     * 类型:int64
-     * 描述:
-     *  订单现金支付金额。
-     *  示例值:10
-     * 
- */ - @SerializedName(value = "payer_amount") - private Integer payerAmount; - - /** - *
-     * 字段名:现金支付币种
-     * 变量名:payer_currency
-     * 是否必填:是
-     * 类型:string(8)
-     * 描述:
-     *  货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY。
-     *  示例值: CNY
-     * 
- */ - @SerializedName(value = "payer_currency") - private String payerCurrency; - } + * 解密后的数据 + */ + private CombineTransactionsResult result; } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsResult.java new file mode 100644 index 0000000000..f8d13db88d --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsResult.java @@ -0,0 +1,353 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +/** + * 合单支付 查询结果 + *
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/combine/chapter3_3.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class CombineTransactionsResult implements Serializable { + + /** + *
+   * 字段名:合单商户appid
+   * 变量名:combine_appid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  合单发起方的appid。(即电商平台appid)
+   *  示例值:wxd678efh567hg6787
+   * 
+ */ + @SerializedName(value = "combine_appid") + private String combineAppid; + + /** + *
+   * 字段名:合单商户号
+   * 变量名:combine_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  合单发起方商户号。(即电商平台mchid)
+   *  示例值:1900000109
+   * 
+ */ + @SerializedName(value = "combine_mchid") + private String combineMchid; + + /** + *
+   * 字段名:合单商户订单号
+   * 变量名:combine_out_trade_no
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  合单支付总订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
+   *  示例值:P20150806125346
+   * 
+ */ + @SerializedName(value = "combine_out_trade_no") + private String combineOutTradeNo; + + /** + *
+   * 字段名:+场景信息
+   * 变量名:scene_info
+   * 是否必填:否
+   * 类型:object
+   * 描述:支付场景信息描述
+   * 
+ */ + @SerializedName(value = "scene_info") + private SceneInfo sceneInfo; + + /** + *
+   * 字段名:+子单信息
+   * 变量名:sub_orders
+   * 是否必填:是
+   * 类型:array
+   * 描述:
+   *  最多支持子单条数:50
+   *
+   * 
+ */ + @SerializedName(value = "sub_orders") + private List subOrders; + + /** + *
+   * 字段名:+支付者
+   * 变量名:combine_payer_info
+   * 是否必填:否
+   * 类型:object
+   * 描述:示例值:见请求示例
+   * 
+ */ + @SerializedName(value = "combine_payer_info") + private CombinePayerInfo combinePayerInfo; + + @Data + @NoArgsConstructor + public static class SubOrders implements Serializable { + /** + *
+     * 字段名:子单商户号
+     * 变量名:mchid
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  子单发起方商户号,必须与发起方Appid有绑定关系。(即电商平台mchid)
+     *  示例值:1900000109
+     * 
+ */ + @SerializedName(value = "mchid") + private String mchid; + + /** + *
+     * 字段名:交易类型
+     * 变量名:trade_type
+     * 是否必填:是
+     * 类型:string (16)
+     * 描述:
+     *  枚举值:
+     *  NATIVE:扫码支付
+     *  JSAPI:公众号支付
+     *  APP:APP支付
+     *  MWEB:H5支付
+     *  示例值: JSAPI
+     * 
+ */ + @SerializedName(value = "trade_type") + private String tradeType; + + /** + *
+     * 字段名:交易状态
+     * 变量名:trade_state
+     * 是否必填:是
+     * 类型:string (32)
+     * 描述:
+     *  枚举值:
+     *  SUCCESS:支付成功
+     *  REFUND:转入退款
+     *  NOTPAY:未支付
+     *  CLOSED:已关闭
+     *  USERPAYING:用户支付中
+     *  PAYERROR:支付失败(其他原因,如银行返回失败)
+     *  示例值: SUCCESS
+     * 
+ */ + @SerializedName(value = "trade_state") + private String tradeState; + + /** + *
+     * 字段名:付款银行
+     * 变量名:bank_type
+     * 是否必填:否
+     * 类型:string(16)
+     * 描述:
+     *  银行类型,采用字符串类型的银行标识。
+     *  示例值:CMC
+     * 
+ */ + @SerializedName(value = "bank_type") + private String bankType; + + /** + *
+     * 字段名:附加信息
+     * 变量名:attach
+     * 是否必填:是
+     * 类型:string(128)
+     * 描述:
+     *  附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用。
+     *  示例值:深圳分店
+     * 
+ */ + @SerializedName(value = "attach") + private String attach; + + /** + *
+     * 字段名:支付完成时间
+     * 变量名:success_time
+     * 是否必填:是
+     * 类型:string(16)
+     * 描述:
+     *  订单支付时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss:sss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss:sss表示时分秒毫秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35.120+08:00表示,北京时间2015年5月20日 13点29分35秒。
+     *  示例值:2015-05-20T13:29:35.120+08:00
+     * 
+ */ + @SerializedName(value = "success_time") + private String successTime; + + /** + *
+     * 字段名:微信订单号
+     * 变量名:transaction_id
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  微信支付订单号。
+     *  示例值: 1009660380201506130728806387
+     * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + + /** + *
+     * 字段名:子单商户订单号
+     * 变量名:out_trade_no
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
+     *  特殊规则:最小字符长度为6
+     *  示例值:20150806125346
+     * 
+ */ + @SerializedName(value = "out_trade_no") + private String outTradeNo; + + /** + *
+     * 字段名:二级商户号
+     * 变量名:sub_mchid
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  二级商户商户号,由微信支付生成并下发。
+     *  注意:仅适用于电商平台 服务商
+     *  示例值:1900000109
+     * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+     * 字段名:+订单金额
+     * 变量名:amount
+     * 是否必填:是
+     * 类型:object
+     * 描述:订单金额信息
+     * 
+ */ + @SerializedName(value = "amount") + private Amount amount; + + } + + @Data + @NoArgsConstructor + public static class SceneInfo implements Serializable { + /** + *
+     * 字段名:商户端设备号
+     * 变量名:device_id
+     * 是否必填:否
+     * 类型:string(16)
+     * 描述:
+     *  终端设备号(门店号或收银设备ID)。
+     *  特殊规则:长度最小7个字节
+     *  示例值:POS1:1
+     * 
+ */ + @SerializedName(value = "device_id") + private String deviceId; + + } + + @Data + @NoArgsConstructor + public static class CombinePayerInfo implements Serializable { + /** + *
+     * 字段名:用户标识
+     * 变量名:openid
+     * 是否必填:是
+     * 类型:string(128)
+     * 描述:
+     *  使用合单appid获取的对应用户openid。是用户在商户appid下的唯一标识。
+     *  示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
+     * 
+ */ + @SerializedName(value = "openid") + private String openid; + + } + + @Data + @NoArgsConstructor + public static class Amount implements Serializable { + /** + *
+     * 字段名:标价金额
+     * 变量名:total_amount
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  子单金额,单位为分。
+     *  示例值:100
+     * 
+ */ + @SerializedName(value = "total_amount") + private Integer totalAmount; + + /** + *
+     * 字段名:标价币种
+     * 变量名:currency
+     * 是否必填:是
+     * 类型:string(8)
+     * 描述:
+     *  符合ISO 4217标准的三位字母代码,人民币:CNY。
+     *  示例值:CNY
+     * 
+ */ + @SerializedName(value = "currency") + private String currency; + + /** + *
+     * 字段名:现金支付金额
+     * 变量名:payer_amount
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  订单现金支付金额。
+     *  示例值:10
+     * 
+ */ + @SerializedName(value = "payer_amount") + private Integer payerAmount; + + /** + *
+     * 字段名:现金支付币种
+     * 变量名:payer_currency
+     * 是否必填:是
+     * 类型:string(8)
+     * 描述:
+     *  货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY。
+     *  示例值: CNY
+     * 
+ */ + @SerializedName(value = "payer_currency") + private String payerCurrency; + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/FinishOrderRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/FinishOrderRequest.java new file mode 100644 index 0000000000..1b09ba6ffc --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/FinishOrderRequest.java @@ -0,0 +1,81 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.*; + +import java.io.Serializable; + +/** + * 完结分账 对象 + *
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_5.shtml
+ * 
+ * @author: f00lish + * @date: 2020/09/12 + */ +@Data +@Builder +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class FinishOrderRequest implements Serializable { + + private static final long serialVersionUID = -8662837652326828377L; + + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  分账出资的电商平台二级商户,填写微信支付分配的商户号。
+   *  示例值:1900000109
+   * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:微信订单号
+   * 变量名:transaction_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信支付订单号。
+   *  示例值:4208450740201411110007820472
+   * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + + /** + *
+   * 字段名:商户分账单号
+   * 变量名:out_order_no
+   * 是否必填:是
+   * 类型:string(64)
+   * 描述:
+   *  商户系统内部的分账单号,在商户系统内部唯一(单次分账、多次分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次。
+   *  示例值:P20150806125346
+   * 
+ */ + @SerializedName(value = "out_order_no") + private String outOrderNo; + + /** + *
+   * 字段名:分账描述
+   * 变量名:description
+   * 是否必填:是
+   * 类型:string(80)
+   * 描述:
+   *  分账的原因描述,分账账单中需要体现。
+   *  示例值:分给商户1900000109
+   * 
+ */ + @SerializedName(value = "description") + private String description; + + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsNotifyResult.java index abb4bfe735..03d9535fa8 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsNotifyResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsNotifyResult.java @@ -1,11 +1,9 @@ package com.github.binarywang.wxpay.bean.ecommerce; -import com.google.gson.annotations.SerializedName; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; -import java.util.List; /** * 普通支付 通知结果 @@ -23,570 +21,7 @@ public class PartnerTransactionsNotifyResult implements Serializable { private NotifyResponse rawData; /** - *
-   * 字段名:服务商公众号ID
-   * 变量名:sp_appid
-   * 是否必填:是
-   * 类型:string(32)
-   * 描述:
-   *  服务商申请的公众号或移动应用appid。
-   *  示例值:wx8888888888888888
-   * 
+ * 解密后的数据 */ - @SerializedName(value = "sp_appid") - private String spAppid; - - /** - *
-   * 字段名:服务商户号
-   * 变量名:sp_mchid
-   * 是否必填:是
-   * 类型:string(32)
-   * 描述:
-   *  服务商户号,由微信支付生成并下发
-   *  示例值:1230000109
-   * 
- */ - @SerializedName(value = "sp_mchid") - private String spMchid; - - /** - *
-   * 字段名:二级商户公众号ID
-   * 变量名:sub_appid
-   * 是否必填:否
-   * 类型:string(32)
-   * 描述:
-   *  二级商户申请的公众号或移动应用appid。
-   *  示例值:wxd678efh567hg6999
-   * 
- */ - @SerializedName(value = "sub_appid") - private String subAppid; - - /** - *
-   * 字段名:二级商户号
-   * 变量名:sub_mchid
-   * 是否必填:是
-   * 类型:string(32)
-   * 描述:
-   *  二级商户的商户号,有微信支付生成并下发。
-   *  示例值:1900000109
-   * 
- */ - @SerializedName(value = "sub_mchid") - private String subMchid; - - /** - *
-   * 字段名:+商户订单号
-   * 变量名:out_trade_no
-   * 是否必填:是
-   * 类型:string(32)
-   * 描述:商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一,详见【商户订单号】。
-   * 特殊规则:最小字符长度为6
-   * 示例值:1217752501201407033233368018
-   * 
- */ - @SerializedName(value = "out_trade_no") - private String outTradeNo; - - /** - *
-   * 字段名:微信支付订单号
-   * 变量名:transaction_id
-   * 是否必填:否
-   * 类型:string(32)
-   * 描述:微信支付系统生成的订单号。
-   * 示例值:1217752501201407033233368018
-   * 
- */ - @SerializedName(value = "transaction_id") - private String transactionId; - - /** - *
-   * 字段名:交易类型
-   * 变量名:trade_type
-   * 是否必填:否
-   * 类型:string(16)
-   * 描述:交易类型,枚举值:
-   *  JSAPI:公众号支付
-   *  NATIVE:扫码支付
-   *  APP:APP支付
-   *  MICROPAY:付款码支付
-   *  MWEB:H5支付
-   *  FACEPAY:刷脸支付
-   *
-   * 示例值: MICROPAY
-   * 
- */ - @SerializedName(value = "trade_type") - private String tradeType; - - /** - *
-   * 字段名:交易状态
-   * 变量名:trade_state
-   * 是否必填:是
-   * 类型:string(32)
-   * 描述:交易状态,枚举值:
-   *  SUCCESS:支付成功
-   *  REFUND:转入退款
-   *  NOTPAY:未支付
-   *  CLOSED:已关闭
-   *  REVOKED:已撤销(付款码支付)
-   *  USERPAYING:用户支付中(付款码支付)
-   *  PAYERROR:支付失败(其他原因,如银行返回失败)
-   *
-   * 示例值:SUCCESS
-   * 
- */ - @SerializedName(value = "trade_state") - private String tradeState; - - /** - *
-   * 字段名:交易状态描述
-   * 变量名:trade_state_desc
-   * 是否必填:是
-   * 类型:string(256)
-   * 描述:交易状态描述
-   * 示例值:支付失败,请重新下单支付
-   * 
- */ - @SerializedName(value = "trade_state_desc") - private String tradeStateDesc; - - /** - *
-   * 字段名:付款银行
-   * 变量名:bank_type
-   * 是否必填:否
-   * 类型:string(16)
-   * 描述:银行类型,采用字符串类型的银行标识。
-   * 示例值:CMC
-   * 
- */ - @SerializedName(value = "bank_type") - private String bankType; - - /** - *
-   * 字段名:附加数据
-   * 变量名:attach
-   * 是否必填:否
-   * 类型:string(128)
-   * 描述:附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用
-   * 示例值:自定义数据
-   * 
- */ - @SerializedName(value = "attach") - private String attach; - - /** - *
-   * 字段名:支付完成时间
-   * 变量名:success_time
-   * 是否必填:否
-   * 类型:string(64)
-   * 描述:支付完成时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
-   * 示例值:2018-06-08T10:34:56+08:00
-   * 
- */ - @SerializedName(value = "success_time") - private String successTime; - - /** - *
-   * 字段名:+支付者
-   * 变量名:combine_payer_info
-   * 是否必填:否
-   * 类型:object
-   * 描述:示例值:见请求示例
-   * 
- */ - @SerializedName(value = "combine_payer_info") - private CombinePayerInfo combinePayerInfo; - - /** - *
-   * 字段名:订单金额
-   * 变量名:amount
-   * 是否必填:是
-   * 类型:object
-   * 描述:订单金额信息
-   * 
- */ - @SerializedName(value = "amount") - private Amount amount; - - /** - *
-   * 字段名:场景信息
-   * 变量名:scene_info
-   * 是否必填:否
-   * 类型:object
-   * 描述:支付场景信息描述
-   * 
- */ - @SerializedName(value = "scene_info") - private SceneInfo sceneInfo; - - /** - *
-   * 字段名:优惠功能
-   * 变量名:promotion_detail
-   * 是否必填:否
-   * 类型:array
-   * 描述:优惠功能,享受优惠时返回该字段。
-   * 
- */ - @SerializedName(value = "promotion_detail") - private List promotionDetails; - - @Data - @NoArgsConstructor - public static class SceneInfo implements Serializable { - /** - *
-     * 字段名:商户端设备号
-     * 变量名:device_id
-     * 是否必填:否
-     * 类型:string(16)
-     * 描述:
-     *  终端设备号(门店号或收银设备ID)。
-     *  特殊规则:长度最小7个字节
-     *  示例值:POS1:1
-     * 
- */ - @SerializedName(value = "device_id") - private String deviceId; - - } - - @Data - @NoArgsConstructor - public static class CombinePayerInfo implements Serializable { - /** - *
-     * 字段名:用户标识
-     * 变量名:sp_openid
-     * 是否必填:是
-     * 类型:string(128)
-     * 描述:
-     *  用户在服务商appid下的唯一标识。
-     *  示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
-     * 
- */ - @SerializedName(value = "sp_openid") - private String spOpenid; - - - /** - *
-     * 字段名:二级商户用户标识
-     * 变量名:sub_openid
-     * 是否必填:否
-     * 类型:string(128)
-     * 描述:
-     *  用户在二级商户appid下的唯一标识。
-     *  示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
-     * 
- */ - @SerializedName(value = "sub_openid") - private String subOpenid; - - } - - @Data - @NoArgsConstructor - public static class Amount implements Serializable { - /** - *
-     * 字段名:总金额
-     * 变量名:total
-     * 是否必填:否
-     * 类型:int
-     * 描述:
-     *  订单总金额,单位为分
-     *  示例值:100
-     * 
- */ - @SerializedName(value = "total") - private Integer total; - - - /** - *
-     * 字段名:用户支付金额
-     * 变量名:payer_total
-     * 是否必填:否
-     * 类型:int
-     * 描述:
-     *  用户支付金额,单位为分。
-     *  示例值:100
-     * 
- */ - @SerializedName(value = "payer_total") - private Integer payerTotal; - - - /** - *
-     * 字段名:货币类型
-     * 变量名:currency
-     * 是否必填:否
-     * 类型:string(16)
-     * 描述:
-     *  CNY:人民币,境内商户号仅支持人民币。
-     *  示例值:CNY
-     * 
- */ - @SerializedName(value = "currency") - private String currency; - - - /** - *
-     * 字段名:用户支付币种
-     * 变量名:payer_currency
-     * 是否必填:否
-     * 类型:string(8)
-     * 描述:
-     *  用户支付币种
-     *  示例值: CNY
-     * 
- */ - @SerializedName(value = "payer_currency") - private String payerCurrency; - } - - @Data - @NoArgsConstructor - public static class PromotionDetail implements Serializable { - - /** - *
-     * 字段名:券ID
-     * 变量名:coupon_id
-     * 是否必填:是
-     * 类型:string(32)
-     * 描述: 券ID
-     * 示例值:109519
-     * 
- */ - @SerializedName(value = "coupon_id") - private String couponId; - - /** - *
-     * 字段名:优惠名称
-     * 变量名:name
-     * 是否必填:否
-     * 类型:string(64)
-     * 描述: 优惠名称
-     * 示例值:单品惠-6
-     * 
- */ - @SerializedName(value = "name") - private String name; - /** - *
-     * 字段名:优惠范围
-     * 变量名:scope
-     * 是否必填:否
-     * 类型:string(32)
-     * 描述: 优惠名称
-     * 示例值:
-     *    GLOBAL:全场代金券
-     *    SINGLE:单品优惠
-     * 示例值:GLOBAL
-     * 
- */ - @SerializedName(value = "scope") - private String scope; - - /** - *
-     * 字段名:优惠类型
-     * 变量名:type
-     * 是否必填:否
-     * 类型:string(32)
-     * 描述:
-     *    CASH:充值
-     *    NOCASH:预充值
-     * 示例值:CASH
-     * 
- */ - @SerializedName(value = "type") - private String type; - - /** - *
-     * 字段名:优惠券面额
-     * 变量名:amount
-     * 是否必填:是
-     * 类型:int
-     * 描述: 优惠券面额
-     * 示例值:100
-     * 
- */ - @SerializedName(value = "amount") - private Integer amount; - - /** - *
-     * 字段名:活动ID
-     * 变量名:stock_id
-     * 是否必填:否
-     * 类型:string(32)
-     * 描述:活动ID
-     * 示例值:931386
-     * 
- */ - @SerializedName(value = "stock_id") - private String stockId; - - /** - *
-     * 字段名:微信出资
-     * 变量名:wechatpay_contribute
-     * 是否必填:否
-     * 类型:int
-     * 描述:微信出资,单位为分
-     * 示例值:0
-     * 
- */ - @SerializedName(value = "wechatpay_contribute") - private Integer wechatpayContribute; - - /** - *
-     * 字段名:商户出资
-     * 变量名:merchant_contribute
-     * 是否必填:否
-     * 类型:int
-     * 描述:商户出资,单位为分
-     * 示例值:0
-     * 
- */ - @SerializedName(value = "merchant_contribute") - private Integer merchantContribute; - - /** - *
-     * 字段名:其他出资
-     * 变量名:other_contribute
-     * 是否必填:否
-     * 类型:int
-     * 描述:其他出资,单位为分
-     * 示例值:0
-     * 
- */ - @SerializedName(value = "other_contribute") - private Integer otherContribute; - - /** - *
-     * 字段名:优惠币种
-     * 变量名:currency
-     * 是否必填:否
-     * 类型:String(16)
-     * 描述:
-     *    CNY:人民币,境内商户号仅支持人民币。
-     * 示例值:CNY
-     * 
- */ - @SerializedName(value = "currency") - private String currency; - - /** - *
-     * 字段名:单品列表
-     * 变量名:goods_detail
-     * 是否必填:否
-     * 类型:array
-     * 描述:单品列表信息
-     * 
- */ - @SerializedName(value = "goods_detail") - private List goodsDetails; - - - } - - @Data - @NoArgsConstructor - public static class GoodsDetail implements Serializable { - - /** - *
-     * 字段名:商品编码
-     * 变量名:goods_id
-     * 是否必填:是
-     * 类型:string(32)
-     * 描述:商品编码
-     * 示例值:M1006
-     * 
- */ - @SerializedName(value = "goods_id") - private String goodsId; - - /** - *
-     * 字段名:商品数量
-     * 变量名:quantity
-     * 是否必填:是
-     * 类型:int64
-     * 描述:
-     *  用户购买的数量
-     * 示例值:1
-     * 
- */ - @SerializedName(value = "quantity") - private Integer quantity; - - /** - *
-     * 字段名:商品单价
-     * 变量名:unit_price
-     * 是否必填:是
-     * 类型:int64
-     * 描述:
-     *  商品单价,单位为分
-     * 示例值:100
-     * 
- */ - @SerializedName(value = "unit_price") - private Integer unitPrice; - - /** - *
-     * 字段名:商品优惠金额
-     * 变量名:discount_amount
-     * 是否必填:是
-     * 类型:int
-     * 描述:商品优惠金额
-     * 示例值:0
-     * 
- */ - @SerializedName(value = "discount_amount") - private Integer discountAmount; - - /** - *
-     * 字段名:商品备注
-     * 变量名:goods_remark
-     * 是否必填:否
-     * 类型:string(128)
-     * 描述:商品备注信息
-     * 示例值:商品备注信息
-     * 
- */ - @SerializedName(value = "goods_remark") - private String goodsRemark; - } - + private PartnerTransactionsResult result; } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsQueryRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsQueryRequest.java new file mode 100644 index 0000000000..2b90e432bb --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsQueryRequest.java @@ -0,0 +1,69 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +public class PartnerTransactionsQueryRequest implements Serializable { + + + /** + *
+   * 字段名:服务商户号
+   * 变量名:sp_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  服务商户号,由微信支付生成并下发
+   * 示例值:1230000109
+   * 
+ */ + @SerializedName(value = "sp_mchid") + private String spMchid; + + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  二级商户的商户号,有微信支付生成并下发。
+   * 示例值:1900000109
+   * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:微信支付订单号
+   * 变量名:transaction_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信支付系统生成的订单号
+   * 示例值:1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + /** + *
+   * 字段名:商户订单号
+   * 变量名:out_trade_no
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一,详见【商户订单号】。
+   * 特殊规则:最小字符长度为6
+   * 示例值:1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "out_trade_no") + private String outTradeNo; +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsResult.java new file mode 100644 index 0000000000..9524627d79 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsResult.java @@ -0,0 +1,587 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +/** + * 普通支付 查询结果 + *
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/e_transactions/chapter3_5.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class PartnerTransactionsResult implements Serializable { + + /** + *
+   * 字段名:服务商公众号ID
+   * 变量名:sp_appid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  服务商申请的公众号或移动应用appid。
+   *  示例值:wx8888888888888888
+   * 
+ */ + @SerializedName(value = "sp_appid") + private String spAppid; + + /** + *
+   * 字段名:服务商户号
+   * 变量名:sp_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  服务商户号,由微信支付生成并下发
+   *  示例值:1230000109
+   * 
+ */ + @SerializedName(value = "sp_mchid") + private String spMchid; + + /** + *
+   * 字段名:二级商户公众号ID
+   * 变量名:sub_appid
+   * 是否必填:否
+   * 类型:string(32)
+   * 描述:
+   *  二级商户申请的公众号或移动应用appid。
+   *  示例值:wxd678efh567hg6999
+   * 
+ */ + @SerializedName(value = "sub_appid") + private String subAppid; + + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  二级商户的商户号,有微信支付生成并下发。
+   *  示例值:1900000109
+   * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:+商户订单号
+   * 变量名:out_trade_no
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一,详见【商户订单号】。
+   * 特殊规则:最小字符长度为6
+   * 示例值:1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "out_trade_no") + private String outTradeNo; + + /** + *
+   * 字段名:微信支付订单号
+   * 变量名:transaction_id
+   * 是否必填:否
+   * 类型:string(32)
+   * 描述:微信支付系统生成的订单号。
+   * 示例值:1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + + /** + *
+   * 字段名:交易类型
+   * 变量名:trade_type
+   * 是否必填:否
+   * 类型:string(16)
+   * 描述:交易类型,枚举值:
+   *  JSAPI:公众号支付
+   *  NATIVE:扫码支付
+   *  APP:APP支付
+   *  MICROPAY:付款码支付
+   *  MWEB:H5支付
+   *  FACEPAY:刷脸支付
+   *
+   * 示例值: MICROPAY
+   * 
+ */ + @SerializedName(value = "trade_type") + private String tradeType; + + /** + *
+   * 字段名:交易状态
+   * 变量名:trade_state
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:交易状态,枚举值:
+   *  SUCCESS:支付成功
+   *  REFUND:转入退款
+   *  NOTPAY:未支付
+   *  CLOSED:已关闭
+   *  REVOKED:已撤销(付款码支付)
+   *  USERPAYING:用户支付中(付款码支付)
+   *  PAYERROR:支付失败(其他原因,如银行返回失败)
+   *
+   * 示例值:SUCCESS
+   * 
+ */ + @SerializedName(value = "trade_state") + private String tradeState; + + /** + *
+   * 字段名:交易状态描述
+   * 变量名:trade_state_desc
+   * 是否必填:是
+   * 类型:string(256)
+   * 描述:交易状态描述
+   * 示例值:支付失败,请重新下单支付
+   * 
+ */ + @SerializedName(value = "trade_state_desc") + private String tradeStateDesc; + + /** + *
+   * 字段名:付款银行
+   * 变量名:bank_type
+   * 是否必填:否
+   * 类型:string(16)
+   * 描述:银行类型,采用字符串类型的银行标识。
+   * 示例值:CMC
+   * 
+ */ + @SerializedName(value = "bank_type") + private String bankType; + + /** + *
+   * 字段名:附加数据
+   * 变量名:attach
+   * 是否必填:否
+   * 类型:string(128)
+   * 描述:附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用
+   * 示例值:自定义数据
+   * 
+ */ + @SerializedName(value = "attach") + private String attach; + + /** + *
+   * 字段名:支付完成时间
+   * 变量名:success_time
+   * 是否必填:否
+   * 类型:string(64)
+   * 描述:支付完成时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
+   * 示例值:2018-06-08T10:34:56+08:00
+   * 
+ */ + @SerializedName(value = "success_time") + private String successTime; + + /** + *
+   * 字段名:+支付者
+   * 变量名:combine_payer_info
+   * 是否必填:否
+   * 类型:object
+   * 描述:示例值:见请求示例
+   * 
+ */ + @SerializedName(value = "combine_payer_info") + private CombinePayerInfo combinePayerInfo; + + /** + *
+   * 字段名:订单金额
+   * 变量名:amount
+   * 是否必填:是
+   * 类型:object
+   * 描述:订单金额信息
+   * 
+ */ + @SerializedName(value = "amount") + private Amount amount; + + /** + *
+   * 字段名:场景信息
+   * 变量名:scene_info
+   * 是否必填:否
+   * 类型:object
+   * 描述:支付场景信息描述
+   * 
+ */ + @SerializedName(value = "scene_info") + private SceneInfo sceneInfo; + + /** + *
+   * 字段名:优惠功能
+   * 变量名:promotion_detail
+   * 是否必填:否
+   * 类型:array
+   * 描述:优惠功能,享受优惠时返回该字段。
+   * 
+ */ + @SerializedName(value = "promotion_detail") + private List promotionDetails; + + @Data + @NoArgsConstructor + public static class SceneInfo implements Serializable { + /** + *
+     * 字段名:商户端设备号
+     * 变量名:device_id
+     * 是否必填:否
+     * 类型:string(16)
+     * 描述:
+     *  终端设备号(门店号或收银设备ID)。
+     *  特殊规则:长度最小7个字节
+     *  示例值:POS1:1
+     * 
+ */ + @SerializedName(value = "device_id") + private String deviceId; + + } + + @Data + @NoArgsConstructor + public static class CombinePayerInfo implements Serializable { + /** + *
+     * 字段名:用户标识
+     * 变量名:sp_openid
+     * 是否必填:是
+     * 类型:string(128)
+     * 描述:
+     *  用户在服务商appid下的唯一标识。
+     *  示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
+     * 
+ */ + @SerializedName(value = "sp_openid") + private String spOpenid; + + + /** + *
+     * 字段名:二级商户用户标识
+     * 变量名:sub_openid
+     * 是否必填:否
+     * 类型:string(128)
+     * 描述:
+     *  用户在二级商户appid下的唯一标识。
+     *  示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
+     * 
+ */ + @SerializedName(value = "sub_openid") + private String subOpenid; + + } + + @Data + @NoArgsConstructor + public static class Amount implements Serializable { + /** + *
+     * 字段名:总金额
+     * 变量名:total
+     * 是否必填:否
+     * 类型:int
+     * 描述:
+     *  订单总金额,单位为分
+     *  示例值:100
+     * 
+ */ + @SerializedName(value = "total") + private Integer total; + + + /** + *
+     * 字段名:用户支付金额
+     * 变量名:payer_total
+     * 是否必填:否
+     * 类型:int
+     * 描述:
+     *  用户支付金额,单位为分。
+     *  示例值:100
+     * 
+ */ + @SerializedName(value = "payer_total") + private Integer payerTotal; + + + /** + *
+     * 字段名:货币类型
+     * 变量名:currency
+     * 是否必填:否
+     * 类型:string(16)
+     * 描述:
+     *  CNY:人民币,境内商户号仅支持人民币。
+     *  示例值:CNY
+     * 
+ */ + @SerializedName(value = "currency") + private String currency; + + + /** + *
+     * 字段名:用户支付币种
+     * 变量名:payer_currency
+     * 是否必填:否
+     * 类型:string(8)
+     * 描述:
+     *  用户支付币种
+     *  示例值: CNY
+     * 
+ */ + @SerializedName(value = "payer_currency") + private String payerCurrency; + } + + @Data + @NoArgsConstructor + public static class PromotionDetail implements Serializable { + + /** + *
+     * 字段名:券ID
+     * 变量名:coupon_id
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述: 券ID
+     * 示例值:109519
+     * 
+ */ + @SerializedName(value = "coupon_id") + private String couponId; + + /** + *
+     * 字段名:优惠名称
+     * 变量名:name
+     * 是否必填:否
+     * 类型:string(64)
+     * 描述: 优惠名称
+     * 示例值:单品惠-6
+     * 
+ */ + @SerializedName(value = "name") + private String name; + /** + *
+     * 字段名:优惠范围
+     * 变量名:scope
+     * 是否必填:否
+     * 类型:string(32)
+     * 描述: 优惠名称
+     * 示例值:
+     *    GLOBAL:全场代金券
+     *    SINGLE:单品优惠
+     * 示例值:GLOBAL
+     * 
+ */ + @SerializedName(value = "scope") + private String scope; + + /** + *
+     * 字段名:优惠类型
+     * 变量名:type
+     * 是否必填:否
+     * 类型:string(32)
+     * 描述:
+     *    CASH:充值
+     *    NOCASH:预充值
+     * 示例值:CASH
+     * 
+ */ + @SerializedName(value = "type") + private String type; + + /** + *
+     * 字段名:优惠券面额
+     * 变量名:amount
+     * 是否必填:是
+     * 类型:int
+     * 描述: 优惠券面额
+     * 示例值:100
+     * 
+ */ + @SerializedName(value = "amount") + private Integer amount; + + /** + *
+     * 字段名:活动ID
+     * 变量名:stock_id
+     * 是否必填:否
+     * 类型:string(32)
+     * 描述:活动ID
+     * 示例值:931386
+     * 
+ */ + @SerializedName(value = "stock_id") + private String stockId; + + /** + *
+     * 字段名:微信出资
+     * 变量名:wechatpay_contribute
+     * 是否必填:否
+     * 类型:int
+     * 描述:微信出资,单位为分
+     * 示例值:0
+     * 
+ */ + @SerializedName(value = "wechatpay_contribute") + private Integer wechatpayContribute; + + /** + *
+     * 字段名:商户出资
+     * 变量名:merchant_contribute
+     * 是否必填:否
+     * 类型:int
+     * 描述:商户出资,单位为分
+     * 示例值:0
+     * 
+ */ + @SerializedName(value = "merchant_contribute") + private Integer merchantContribute; + + /** + *
+     * 字段名:其他出资
+     * 变量名:other_contribute
+     * 是否必填:否
+     * 类型:int
+     * 描述:其他出资,单位为分
+     * 示例值:0
+     * 
+ */ + @SerializedName(value = "other_contribute") + private Integer otherContribute; + + /** + *
+     * 字段名:优惠币种
+     * 变量名:currency
+     * 是否必填:否
+     * 类型:String(16)
+     * 描述:
+     *    CNY:人民币,境内商户号仅支持人民币。
+     * 示例值:CNY
+     * 
+ */ + @SerializedName(value = "currency") + private String currency; + + /** + *
+     * 字段名:单品列表
+     * 变量名:goods_detail
+     * 是否必填:否
+     * 类型:array
+     * 描述:单品列表信息
+     * 
+ */ + @SerializedName(value = "goods_detail") + private List goodsDetails; + + + } + + @Data + @NoArgsConstructor + public static class GoodsDetail implements Serializable { + + /** + *
+     * 字段名:商品编码
+     * 变量名:goods_id
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:商品编码
+     * 示例值:M1006
+     * 
+ */ + @SerializedName(value = "goods_id") + private String goodsId; + + /** + *
+     * 字段名:商品数量
+     * 变量名:quantity
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  用户购买的数量
+     * 示例值:1
+     * 
+ */ + @SerializedName(value = "quantity") + private Integer quantity; + + /** + *
+     * 字段名:商品单价
+     * 变量名:unit_price
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  商品单价,单位为分
+     * 示例值:100
+     * 
+ */ + @SerializedName(value = "unit_price") + private Integer unitPrice; + + /** + *
+     * 字段名:商品优惠金额
+     * 变量名:discount_amount
+     * 是否必填:是
+     * 类型:int
+     * 描述:商品优惠金额
+     * 示例值:0
+     * 
+ */ + @SerializedName(value = "discount_amount") + private Integer discountAmount; + + /** + *
+     * 字段名:商品备注
+     * 变量名:goods_remark
+     * 是否必填:否
+     * 类型:string(128)
+     * 描述:商品备注信息
+     * 示例值:商品备注信息
+     * 
+ */ + @SerializedName(value = "goods_remark") + private String goodsRemark; + } + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingQueryRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingQueryRequest.java new file mode 100644 index 0000000000..c9e1aad2e8 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingQueryRequest.java @@ -0,0 +1,54 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +public class ProfitSharingQueryRequest implements Serializable { + + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  分账出资的电商平台二级商户,填写微信支付分配的商户号。
+   *  示例值:1900000109
+   * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:微信订单号
+   * 变量名:transaction_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信支付订单号。
+   * 示例值: 4208450740201411110007820472
+   * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + + /** + *
+   * 字段名:商户分账单号
+   * 变量名:out_order_no
+   * 是否必填:是
+   * 类型:string(64)
+   * 描述:
+   *  商户系统内部的分账单号,在商户系统内部唯一(单次分账、多次分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次。
+   * 示例值:P20150806125346
+   * 
+ */ + @SerializedName(value = "out_order_no") + private String outOrderNo; +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingResult.java index 878311e6e2..37ff86c25a 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingResult.java @@ -5,6 +5,7 @@ import lombok.NoArgsConstructor; import java.io.Serializable; +import java.util.List; /** * 请求分账 结果响应 @@ -72,4 +73,209 @@ public class ProfitSharingResult implements Serializable { @SerializedName(value = "order_id") private String orderId; + /** + *
+   * 字段名:分账单状态
+   * 变量名:status
+   * 是否必填:是
+   * 类型:string (64)
+   * 描述:
+   *  分账单状态,枚举值:
+   *    ACCEPTED:受理成功
+   *    PROCESSING:处理中
+   *    FINISHED:分账成功
+   *    CLOSED:处理失败,已关单
+   *  示例值:FINISHED
+   * 
+ */ + @SerializedName(value = "status") + private String status; + + /** + *
+   * 字段名:分账接收方列表
+   * 变量名:receivers
+   * 是否必填:否
+   * 类型:array
+   * 描述:
+   *  分账接收方列表。当查询分账完结的执行结果时,不返回该字段
+   * 
+ */ + @SerializedName(value = "receivers") + private List receivers; + /** + *
+   * 字段名:关单原因
+   * 变量名:close_reason
+   * 是否必填:否
+   * 类型:string (32)
+   * 描述:
+   *  关单原因描述,当分账单状态status为CLOSED(处理失败,已关单)时,返回该字段。
+   * 枚举值:
+   *    NO_AUTH:分账授权已解除
+   * 示例值:NO_AUTH
+   * 
+ */ + @SerializedName(value = "close_reason") + private String closeReason; + + /** + *
+   * 字段名:分账完结金额
+   * 变量名:finish_amount
+   * 是否必填:否
+   * 类型:int
+   * 描述:
+   *  分账完结的分账金额,单位为分, 仅当查询分账完结的执行结果时,存在本字段。
+   * 示例值:100
+   * 
+ */ + @SerializedName(value = "finish_amount") + private Integer finishAmount; + + /** + *
+   * 字段名:分账完结描述
+   * 变量名:finish_description
+   * 是否必填:否
+   * 类型:string (80)
+   * 描述:
+   *  分账完结的原因描述,仅当查询分账完结的执行结果时,存在本字段。
+   * 示例值:分账完结
+   * 
+ */ + @SerializedName(value = "finish_description") + private String finishDescription; + + @Data + @NoArgsConstructor + public static class Receiver implements Serializable { + + /** + *
+     * 字段名:分账接收商户号
+     * 变量名:receiver_mchid
+     * 是否必填:是
+     * 类型:string (32)
+     * 描述:
+     *  填写微信支付分配的商户号,仅支持通过添加分账接收方接口添加的接收方;电商平台商户已默认添加到分账接收方,无需重复添加。
+     * 示例值:1900000109
+     * 
+ */ + @SerializedName(value = "receiver_mchid") + private String receiverMchid; + + /** + *
+     * 字段名:分账金额
+     * 变量名:amount
+     * 是否必填:否
+     * 类型:int
+     * 描述:
+     *  分账金额,单位为分,只能为整数,不能超过原订单支付金额及最大分账比例金额。
+     * 示例值: 4208450740201411110007820472
+     * 
+ */ + @SerializedName(value = "amount") + private Integer amount; + + /** + *
+     * 字段名:分账描述
+     * 变量名:description
+     * 是否必填:是
+     * 类型:string (80)
+     * 描述:
+     *  分账的原因描述,分账账单中需要体现。
+     * 示例值:分帐1900000110
+     * 
+ */ + @SerializedName(value = "description") + private String description; + + /** + *
+     * 字段名:分账结果
+     * 变量名:result
+     * 是否必填:是
+     * 类型:string (32)
+     * 描述:
+     *  分账结果,枚举值:
+     *    PENDING:待分账
+     *    SUCCESS:分账成功
+     *    ADJUST:分账失败待调账
+     *    RETURNED:已转回分账方
+     *    CLOSED:已关闭
+     * 示例值:SUCCESS
+     * 
+ */ + @SerializedName(value = "result") + private String result; + + /** + *
+     * 字段名:完成时间
+     * 变量名:finish_time
+     * 是否必填:是
+     * 类型:string (64)
+     * 描述:
+     *  分账完成时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss.sss+TIMEZONE,YYYY-MM-DD表示年月日,
+     *  T出现在字符串中,表示time元素的开头,HH:mm:ss.sss表示时分秒毫秒,TIMEZONE表示时区
+     *  (+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35.120+08:00表示,北京时间2015年5月20日 13点29分35秒。
+     * 示例值: 2015-05-20T13:29:35.120+08:00
+     * 
+ */ + @SerializedName(value = "finish_time") + private String finishTime; + + /** + *
+     * 字段名:分账失败原因
+     * 变量名:fail_reason
+     * 是否必填:否
+     * 类型:string (32)
+     * 描述:
+     *  分账失败原因,当分账结果result为RETURNED(已转回分账方)或CLOSED(已关闭)时,返回该字段
+     * 枚举值:
+     *    ACCOUNT_ABNORMAL:分账接收账户异常
+     *    NO_RELATION:分账关系已解除
+     *    RECEIVER_HIGH_RISK:高风险接收方
+     * 示例值:NO_RELATION
+     * 
+ */ + @SerializedName(value = "fail_reason") + private String failReason; + + /** + *
+     * 字段名:分账接收方类型
+     * 变量名:type
+     * 是否必填:是
+     * 类型:string (32)
+     * 描述:
+     *  分账接收方类型,枚举值:
+     *    MERCHANT_ID:商户
+     *    PERSONAL_OPENID:个人
+     * 示例值:MERCHANT_ID
+     * 
+ */ + @SerializedName(value = "type") + private String type; + + /** + *
+     * 字段名:分账接收方类型
+     * 变量名:receiver_account
+     * 是否必填:是
+     * 类型:string (64)
+     * 描述:
+     *  分账接收方账号:
+     * 类型是MERCHANT_ID时,是商户ID
+     * 类型是PERSONAL_OPENID时,是个人openid
+     * 示例值:1900000109
+     * 
+ */ + @SerializedName(value = "receiver_account") + private String receiverAccount; + } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundNotifyResult.java new file mode 100644 index 0000000000..a2452a1bad --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundNotifyResult.java @@ -0,0 +1,233 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 退款结果 查询结果 + *
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_3.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class RefundNotifyResult implements Serializable { + + /** + * 源数据 + */ + private NotifyResponse rawData; + + /** + *
+   * 字段名:电商平台商户号
+   * 变量名:sp_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信支付分配给电商平台的商户号
+   * 示例值:1900000100
+   * 
+ */ + @SerializedName(value = "sp_mchid") + private String spMchid; + + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  分账出资的电商平台二级商户,填写微信支付分配的商户号。
+   *  示例值:1900000109
+   * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:商户订单号
+   * 变量名:out_trade_no
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  返回的商户订单号
+   * 示例值: 1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "out_trade_no") + private String outTradeNo; + + /** + *
+   * 字段名:微信订单号
+   * 变量名:transaction_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信支付订单号
+   * 示例值: 1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + + /** + *
+   * 字段名:商户退款单号
+   * 变量名:out_refund_no
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  商户退款单号
+   * 示例值: 1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "out_refund_no") + private String outRefundNo; + + /** + *
+   * 字段名:微信退款单号
+   * 变量名:refund_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信退款单号
+   * 示例值: 1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "refund_id") + private String refundId; + + /** + *
+   * 字段名:退款状态
+   * 变量名:refund_status
+   * 是否必填:是
+   * 类型:string(16)
+   * 描述:
+   *  退款状态,枚举值:
+   *    SUCCESS:退款成功
+   *    CLOSE:退款关闭
+   *    ABNORMAL:退款异常,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往【服务商平台—>交易中心】,手动处理此笔退款
+   * 示例值:SUCCESS
+   * 
+ */ + @SerializedName(value = "refund_status") + private String refundStatus; + + /** + *
+   * 字段名:退款成功时间
+   * 变量名:success_time
+   * 是否必填:否
+   * 类型:string(64)
+   * 描述:
+   *  1、退款成功时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,
+   *  表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。
+   *  例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日13点29分35秒。
+   * 2、当退款状态为退款成功时返回此参数。
+   * 示例值:2018-06-08T10:34:56+08:00
+   * 
+ */ + @SerializedName(value = "success_time") + private String successTime; + + /** + *
+   * 字段名:退款入账账户
+   * 变量名:user_received_account
+   * 是否必填:是
+   * 类型:string(64)
+   * 描述:
+   *  取当前退款单的退款入账方。
+   *    退回银行卡:{银行名称}{卡类型}{卡尾号}
+   *    退回支付用户零钱: 支付用户零钱
+   *    退还商户: 商户基本账户、商户结算银行账户
+   *    退回支付用户零钱通:支付用户零钱通
+   * 示例值:招商银行信用卡0403
+   * 
+ */ + @SerializedName(value = "user_received_account") + private String userReceivedAccount; + + /** + *
+   * 字段名:金额信息
+   * 变量名:amount
+   * 是否必填:是
+   * 类型:object
+   * 描述:
+   *  金额信息
+   * 
+ */ + @SerializedName(value = "amount") + private Amount amount; + + @Data + @NoArgsConstructor + public static class Amount implements Serializable { + /** + *
+     * 字段名:订单金额
+     * 变量名:total
+     * 是否必填:是
+     * 类型:int
+     * 描述:
+     *  订单总金额,单位为分,只能为整数,详见支付金额
+     * 示例值:999
+     * 
+ */ + @SerializedName(value = "total") + private Integer total; + + /** + *
+     * 字段名:退款金额
+     * 变量名:refund
+     * 是否必填:是
+     * 类型:int
+     * 描述:
+     *  退款金额,币种的最小单位,只能为整数,不能超过原订单支付金额,如果有使用券,后台会按比例退。
+     * 示例值:999
+     * 
+ */ + @SerializedName(value = "refund") + private String refund; + + /** + *
+     * 字段名:用户支付金额
+     * 变量名:payer_total
+     * 是否必填:是
+     * 类型:int
+     * 描述:
+     *  用户支付金额,单位为分。
+     *  示例值:100
+     * 
+ */ + @SerializedName(value = "payer_total") + private Integer payerTotal; + + /** + *
+     * 字段名:用户退款金额
+     * 变量名:payer_refund
+     * 是否必填:是
+     * 类型:int
+     * 描述:
+     *  退款给用户的金额,不包含所有优惠券金额
+     * 示例值:999
+     * 
+ */ + @SerializedName(value = "payer_refund") + private String payerRefund; + } + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundQueryResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundQueryResult.java new file mode 100644 index 0000000000..bbb30ea897 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundQueryResult.java @@ -0,0 +1,325 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +/** + * 查询退款结果 + * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_2.shtml + */ +@Data +@NoArgsConstructor +public class RefundQueryResult implements Serializable { + + /** + *
+   * 字段名:微信退款单号
+   * 变量名:refund_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信退款单号
+   * 示例值: 1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "refund_id") + private String refundId; + + /** + *
+   * 字段名:商户退款单号
+   * 变量名:out_refund_no
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  商户退款单号
+   * 示例值: 1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "out_refund_no") + private String outRefundNo; + + /** + *
+   * 字段名:微信订单号
+   * 变量名:transaction_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信支付订单号
+   * 示例值: 1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + + /** + *
+   * 字段名:商户订单号
+   * 变量名:out_trade_no
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  返回的商户订单号
+   * 示例值: 1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "out_trade_no") + private String outTradeNo; + + /** + *
+   * 字段名:退款渠道
+   * 变量名:channel
+   * 是否必填:否
+   * 类型:string(16)
+   * 描述:
+   *  ORIGINAL:原路退款
+   *  BALANCE:退回到余额
+   *  OTHER_BALANCE:原账户异常退到其他余额账户
+   *  OTHER_BANKCARD:原银行卡异常退到其他银行卡
+   * 示例值: ORIGINAL
+   * 
+ */ + @SerializedName(value = "channel") + private String channel; + + /** + *
+   * 字段名:退款入账账户
+   * 变量名:user_received_account
+   * 是否必填:是
+   * 类型:string(64)
+   * 描述:
+   *  取当前退款单的退款入账方。
+   *    退回银行卡:{银行名称}{卡类型}{卡尾号}
+   *    退回支付用户零钱: 支付用户零钱
+   *    退还商户: 商户基本账户、商户结算银行账户
+   *    退回支付用户零钱通:支付用户零钱通
+   * 示例值:招商银行信用卡0403
+   * 
+ */ + @SerializedName(value = "user_received_account") + private String userReceivedAccount; + + /** + *
+   * 字段名:退款成功时间
+   * 变量名:success_time
+   * 是否必填:否
+   * 类型:string(64)
+   * 描述:
+   *  1、退款成功时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,
+   *  表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。
+   *  例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日13点29分35秒。
+   * 2、当退款状态为退款成功时返回此参数。
+   * 示例值:2018-06-08T10:34:56+08:00
+   * 
+ */ + @SerializedName(value = "success_time") + private String successTime; + + /** + *
+   * 字段名:退款创建时间
+   * 变量名:create_time
+   * 是否必填:是
+   * 类型:string(64)
+   * 描述:
+   *  1、退款受理时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,
+   *  表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。
+   *  例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日13点29分35秒。
+   * 2、当退款状态为退款成功时返回此字段。
+   * 示例值:2018-06-08T10:34:56+08:00
+   * 
+ */ + @SerializedName(value = "create_time") + private String createTime; + + /** + *
+   * 字段名:退款状态
+   * 变量名:status
+   * 是否必填:是
+   * 类型:string(16)
+   * 描述:
+   *  退款状态,枚举值:
+   *    SUCCESS:退款成功
+   *    REFUNDCLOSE:退款关闭
+   *    PROCESSING:退款处理中
+   *    ABNORMAL:退款异常,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往【服务商平台—>交易中心】,手动处理此笔退款
+   * 示例值:SUCCESS
+   * 
+ */ + @SerializedName(value = "status") + private String status; + + /** + *
+   * 字段名:金额信息
+   * 变量名:amount
+   * 是否必填:是
+   * 类型:object
+   * 描述:
+   *  金额信息
+   * 
+ */ + @SerializedName(value = "amount") + private Amount amount; + + /** + *
+   * 字段名:营销详情
+   * 变量名:promotion_detail
+   * 是否必填:否
+   * 类型:array
+   * 描述:
+   *  优惠退款信息
+   * 
+ */ + public List promotionDetails; + + @Data + @NoArgsConstructor + public static class Amount implements Serializable { + + /** + *
+     * 字段名:退款金额
+     * 变量名:refund
+     * 是否必填:是
+     * 类型:int
+     * 描述:
+     *  退款金额,币种的最小单位,只能为整数,不能超过原订单支付金额。
+     * 示例值:888
+     * 
+ */ + @SerializedName(value = "refund") + private String refund; + + /** + *
+     * 字段名:用户退款金额
+     * 变量名:payer_refund
+     * 是否必填:是
+     * 类型:int
+     * 描述:
+     *  退款给用户的金额,不包含所有优惠券金额。
+     * 示例值:888
+     * 
+ */ + @SerializedName(value = "payer_refund") + private String payerRefund; + + /** + *
+     * 字段名:优惠退款金额
+     * 变量名:discount_refund
+     * 是否必填:否
+     * 类型:int
+     * 描述:
+     *  优惠券的退款金额,原支付单的优惠按比例退款。
+     * 示例值:888
+     * 
+ */ + @SerializedName(value = "discount_refund") + private Integer discountRefund; + + + /** + *
+     * 字段名:退款币种
+     * 变量名:currency
+     * 是否必填:否
+     * 类型:string(18)
+     * 描述:
+     *  符合ISO 4217标准的三位字母代码,目前只支持人民币:CNY 。
+     * 示例值: CNY
+     * 
+ */ + @SerializedName(value = "currency") + private String currency; + + } + + @Data + @NoArgsConstructor + public static class PromotionDetail implements Serializable { + + /** + *
+     * 字段名:券ID
+     * 变量名:promotion_id
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:券或者立减优惠id 。
+     * 示例值:109519
+     * 
+ */ + @SerializedName(value = "promotion_id") + private String promotionId; + + /** + *
+     * 字段名:优惠范围
+     * 变量名:scope
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述: 优惠范围
+     * 枚举值:
+     *    GLOBAL:全场代金券
+     *    SINGLE:单品优惠
+     * 示例值:GLOBAL
+     * 
+ */ + @SerializedName(value = "scope") + private String scope; + + /** + *
+     * 字段名:优惠类型
+     * 变量名:type
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *   枚举值:
+     *    COUPON:充值型代金券,商户需要预先充值营销经费
+     *    DISCOUNT:免充值型优惠券,商户不需要预先充值营销经费
+     * 示例值:DISCOUNT
+     * 
+ */ + @SerializedName(value = "type") + private String type; + + /** + *
+     * 字段名:优惠券面额
+     * 变量名:amount
+     * 是否必填:是
+     * 类型:int
+     * 描述: 用户享受优惠的金额(优惠券面额=微信出资金额+商家出资金额+其他出资方金额 )。
+     * 示例值:5
+     * 
+ */ + @SerializedName(value = "amount") + private Integer amount; + + /** + *
+     * 字段名:优惠退款金额
+     * 变量名:refund_amount
+     * 是否必填:是
+     * 类型:int
+     * 描述: 代金券退款金额<=退款金额,退款金额-代金券或立减优惠退款金额为现金,说明详见《代金券或立减优惠》。
+     * 示例值:100
+     * 
+ */ + @SerializedName(value = "refund_amount") + private Integer refundAmount; + + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundsRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundsRequest.java new file mode 100644 index 0000000000..9277b35573 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundsRequest.java @@ -0,0 +1,206 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +/** + * @author: f00lish + * @date: 2020/09/17 + */ + +import com.google.gson.annotations.SerializedName; +import lombok.*; + +import java.io.Serializable; + +/** + * 退款申请 + * *
+ *  *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_1.shtml
+ *  * 
+ * @author: f00lish + * @date: 2020/09/14 + */ +@Data +@Builder +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class RefundsRequest implements Serializable { + private static final long serialVersionUID = -3186851559004865784L; + + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信支付分配二级商户的商户号。
+   *  示例值:1900000109
+   * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:电商平台APPID
+   * 变量名:sp_appid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  电商平台在微信公众平台申请服务号对应的APPID,申请商户功能的时候微信支付会配置绑定关系。
+   *  示例值:wx8888888888888888
+   * 
+ */ + @SerializedName(value = "sp_appid") + private String spAppid; + + /** + *
+   * 字段名:二级商户APPID
+   * 变量名:sub_appid
+   * 是否必填:否
+   * 类型:string(32)
+   * 描述:
+   *  二级商户在微信申请公众号成功后分配的帐号ID,需要电商平台侧配置绑定关系才能传参。
+   *  示例值:wxd678efh567hg6999
+   * 
+ */ + @SerializedName(value = "sub_appid") + private String subAppid; + + /** + *
+   * 字段名:微信订单号
+   * 变量名:transaction_id
+   * 是否必填:与out_order_no二选一
+   * 类型:string(32)
+   * 描述:
+   *  微信支付订单号。
+   *  示例值:4208450740201411110007820472
+   * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + + /** + *
+   * 字段名:商户订单号
+   * 变量名:out_order_no
+   * 是否必填:与transaction_id二选一
+   * 类型:string(64)
+   * 描述:
+   *   原支付交易对应的商户订单号。
+   *   示例值:P20150806125346
+   * 
+ */ + @SerializedName(value = "out_order_no") + private String outOrderNo; + + /** + *
+   * 字段名:商户退款单号
+   * 变量名:out_refund_no
+   * 是否必填:是
+   * 类型:string(64)
+   * 描述:
+   *   商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@,同一退款单号多次请求只退一笔。
+   *   示例值:1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "out_refund_no") + private String outRefundNo; + + /** + *
+   * 字段名:退款原因
+   * 变量名:reason
+   * 是否必填:是
+   * 类型:string(80)
+   * 描述:
+   *   若商户传入,会在下发给用户的退款消息中体现退款原因。
+   *   注意:若订单退款金额≤1元,且属于部分退款,则不会在退款消息中体现退款原因
+   *   示例值:商品已售完
+   * 
+ */ + @SerializedName(value = "reason") + private String reason; + + /** + *
+   * 字段名:订单金额
+   * 变量名:amount
+   * 是否必填:是
+   * 类型:object
+   * 描述:
+   *  订单金额信息
+   * 
+ */ + @SerializedName(value = "amount") + private Amount amount; + + /** + *
+   * 字段名:退款结果回调url
+   * 变量名:notify_url
+   * 是否必填:是
+   * 类型:string(256)
+   * 描述:
+   *   异步接收微信支付退款结果通知的回调地址,通知url必须为外网可访问的url,不能携带参数。 如果参数中传了notify_url,则商户平台上配置的回调地址将不会生效,优先回调当前传的地址。
+   *   示例值:https://weixin.qq.com
+   * 
+ */ + @SerializedName(value = "notify_url") + private String notifyUrl; + + @Data + @Builder + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PRIVATE) + public static class Amount implements Serializable { + + private static final long serialVersionUID = 7383027142329410399L; + + /** + *
+     * 字段名:退款金额
+     * 变量名:refund
+     * 是否必填:是
+     * 类型:int
+     * 描述:
+     *  退款金额,币种的最小单位,只能为整数,不能超过原订单支付金额。
+     *  示例值:888
+     * 
+ */ + @SerializedName(value = "refund") + private Integer refund; + + /** + *
+     * 字段名:原订单金额
+     * 变量名:total
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  订单总金额,单位为分。
+     *  示例值:888
+     * 
+ */ + @SerializedName(value = "total") + private Integer total; + + /** + *
+     * 字段名:币类型
+     * 变量名:currency
+     * 是否必填:否
+     * 类型:string(18)
+     * 描述:
+     *  符合ISO 4217标准的三位字母代码,目前只支持人民币:CNY。
+     *  示例值:CNY
+     * 
+ */ + @SerializedName(value = "currency") + private String currency; + + } + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundsResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundsResult.java new file mode 100644 index 0000000000..9ba480104b --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/RefundsResult.java @@ -0,0 +1,247 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +/** + * @author: f00lish + * @date: 2020/09/17 + */ + +import com.google.gson.annotations.SerializedName; +import lombok.*; + +import java.io.Serializable; +import java.util.Date; + +/** + * 退款结果 + * *
+ *  *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_1.shtml
+ *  * 
+ * @author: f00lish + * @date: 2020/09/14 + */ +@Data +@Builder +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class RefundsResult implements Serializable { + private static final long serialVersionUID = -3186851559004865784L; + + /** + *
+   * 字段名:微信退款单号
+   * 变量名:refund_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  微信支付退款订单号。
+   *  示例值:1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "refund_id") + private String refundId; + + /** + *
+   * 字段名:商户订单号
+   * 变量名:out_order_no
+   * 是否必填:与transaction_id二选一
+   * 类型:string(64)
+   * 描述:
+   *   原支付交易对应的商户订单号。
+   *   示例值:P20150806125346
+   * 
+ */ + @SerializedName(value = "out_order_no") + private String outOrderNo; + + /** + *
+   * 字段名:退款创建时间
+   * 变量名:create_time
+   * 是否必填:是
+   * 类型:string(64)
+   * 描述:
+   *   退款受理时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日13点29分35秒。
+   *   示例值:2018-06-08T10:34:56+08:00
+   * 
+ */ + @SerializedName(value = "create_time") + private Date createTime; + + /** + *
+   * 字段名:订单金额
+   * 变量名:amount
+   * 是否必填:是
+   * 类型:object
+   * 描述:
+   *  订单金额信息
+   * 
+ */ + @SerializedName(value = "amount") + private Amount amount; + + /** + *
+   * 字段名:优惠退款详情
+   * 变量名:promotion_detail
+   * 是否必填:否
+   * 类型:array
+   * 描述:
+   *   优惠退款功能信息
+   * 
+ */ + @SerializedName(value = "promotion_detail") + private PromotionDetail[] promotionDetail; + + @Data + @Builder + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PRIVATE) + public static class Amount implements Serializable { + + private static final long serialVersionUID = 7383027142329410399L; + + /** + *
+     * 字段名:退款金额
+     * 变量名:refund
+     * 是否必填:是
+     * 类型:int
+     * 描述:
+     *  退款金额,币种的最小单位,只能为整数,不能超过原订单支付金额。
+     *  示例值:888
+     * 
+ */ + @SerializedName(value = "refund") + private Integer refund; + + /** + *
+     * 字段名:用户退款金额
+     * 变量名:payer_refund
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  退款给用户的金额,不包含所有优惠券金额。
+     *  示例值:888
+     * 
+ */ + @SerializedName(value = "payer_refund") + private Integer payerRefund; + + /** + *
+     * 字段名:优惠退款金额
+     * 变量名:discount_refund
+     * 是否必填:否
+     * 类型:int64
+     * 描述:
+     *  优惠券的退款金额,原支付单的优惠按比例退款。
+     *  示例值:888
+     * 
+ */ + @SerializedName(value = "discount_refund") + private Integer discountRefund; + + /** + *
+     * 字段名:币类型
+     * 变量名:currency
+     * 是否必填:否
+     * 类型:string(18)
+     * 描述:
+     *  符合ISO 4217标准的三位字母代码,目前只支持人民币:CNY。
+     *  示例值:CNY
+     * 
+ */ + @SerializedName(value = "currency") + private String currency; + + } + + @Data + @Builder + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PRIVATE) + public static class PromotionDetail implements Serializable { + + private static final long serialVersionUID = 7383027142329410399L; + + /** + *
+     * 字段名:券ID
+     * 变量名:promotion_id
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  券或者立减优惠id。
+     *  示例值:109519
+     * 
+ */ + @SerializedName(value = "promotion_id") + private String promotionId; + + /** + *
+     * 字段名:优惠范围
+     * 变量名:scope
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  枚举值:
+     *  GLOBAL:全场代金券
+     *  SINGLE:单品优惠
+     *  示例值:SINGLE
+     * 
+ */ + @SerializedName(value = "scope") + private String scope; + + /** + *
+     * 字段名:优惠类型
+     * 变量名:type
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  枚举值:
+     *  COUPON:充值型代金券,商户需要预先充值营销经费
+     *  DISCOUNT:免充值型优惠券,商户不需要预先充值营销经费
+     *  示例值:DISCOUNT
+     * 
+ */ + @SerializedName(value = "type") + private String type; + + /** + *
+     * 字段名:优惠券面额
+     * 变量名:amount
+     * 是否必填:是
+     * 类型:int
+     * 描述:
+     *  用户享受优惠的金额(优惠券面额=微信出资金额+商家出资金额+其他出资方金额 )。
+     *  示例值:5
+     * 
+ */ + @SerializedName(value = "amount") + private Integer amount; + + /** + *
+     * 字段名:优惠退款金额
+     * 变量名:refund_amount
+     * 是否必填:是
+     * 类型:int
+     * 描述:
+     *  代金券退款金额<=退款金额,退款金额-代金券或立减优惠退款金额为现金,说明详见《代金券或立减优惠》https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_1 。
+     *  示例值:CNY
+     * 
+ */ + @SerializedName(value = "refund_amount") + private Integer refundAmount; + + } + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ReturnOrdersResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ReturnOrdersResult.java index ee78119871..f2110cc5d8 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ReturnOrdersResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ReturnOrdersResult.java @@ -72,7 +72,7 @@ public class ReturnOrdersResult implements Serializable { *
*/ @SerializedName(value = "out_return_no") - private String R20190516001; + private String outReturnNo; /** *
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SettlementRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SettlementRequest.java
new file mode 100644
index 0000000000..81e4bb5cc6
--- /dev/null
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SettlementRequest.java
@@ -0,0 +1,114 @@
+package com.github.binarywang.wxpay.bean.ecommerce;
+
+import com.github.binarywang.wxpay.v3.SpecEncrypt;
+import com.google.gson.annotations.SerializedName;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * 
+ * 普通服务商(支付机构、银行不可用),可使用本接口修改其进件、已签约的特约商户-结算账户信息。
+ * 文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter3_4.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class SettlementRequest implements Serializable { + + /** + *
+   * 字段名:账户类型
+   * 变量名:account_type
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  根据特约商户号的主体类型,可选择的账户类型如下:
+   * 1、小微主体:经营者个人银行卡
+   * 2、个体工商户主体:经营者个人银行卡/ 对公银行账户
+   * 3、企业主体:对公银行账户
+   * 4、党政、机关及事业单位主体:对公银行账户
+   * 5、其他组织主体:对公银行账户
+   * 枚举值:
+   *    ACCOUNT_TYPE_BUSINESS:对公银行账户
+   *    ACCOUNT_TYPE_PRIVATE:经营者个人银行卡
+   * 示例值:ACCOUNT_TYPE_BUSINESS
+   * 
+ */ + @SerializedName(value = "account_type") + private String accountType; + + /** + *
+   * 字段名:开户银行
+   * 变量名:account_bank
+   * 是否必填:是
+   * 类型:string(128)
+   * 描述:
+   *  请填写开户银行名称,详细参见《开户银行对照表》https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter4_1.shtml。
+   * 示例值:工商银行
+   * 
+ */ + @SerializedName(value = "account_bank") + private String accountBank; + + /** + *
+   * 字段名:开户银行省市编码
+   * 变量名:bank_address_code
+   * 是否必填:是
+   * 类型:string(128)
+   * 描述:
+   *  需至少精确到市,详细参见《省市区编号对照表》。
+   * 示例值:110000
+   * 
+ */ + @SerializedName(value = "bank_address_code") + private String bankAddressCode; + + /** + *
+   * 字段名:开户银行全称(含支行)
+   * 变量名:bank_name
+   * 是否必填:否
+   * 类型:string(128)
+   * 描述:
+   *  若开户银行为“其他银行”,则需二选一填写“开户银行全称(含支行)”或“开户银行联行号”。
+   * 填写银行全称,如"深圳农村商业银行XXX支行" ,详细参见开户银行全称(含支行)对照表。
+   * 示例值:施秉县农村信用合作联社城关信用社
+   * 
+ */ + @SerializedName(value = "bank_name") + private String bankName; + + /** + *
+   * 字段名:开户银行联行号
+   * 变量名:bank_branch_id
+   * 是否必填:否
+   * 类型:string(128)
+   * 描述:
+   *  若开户银行为“其他银行”,则需二选一填写“开户银行全称(含支行)”或“开户银行联行号”。
+   * 填写银行联行号,详细参见《开户银行全称(含支行)对照表》。
+   * 示例值:402713354941
+   * 
+ */ + @SerializedName(value = "bank_branch_id") + private String bankBranchId; + + /** + *
+   * 字段名:银行账号
+   * 变量名:account_number
+   * 是否必填:是
+   * 类型:string(128)
+   * 描述:
+   *  1、数字,长度遵循系统支持的对公/对私卡号长度要求
+   * 2、该字段需进行加密处理,加密方法详见《敏感信息加密说明》。(提醒:必须在HTTP头中上送Wechatpay-Serial)
+   * 
+ */ + @SpecEncrypt + @SerializedName(value = "account_number") + private String accountNumber; +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SettlementResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SettlementResult.java new file mode 100644 index 0000000000..50dfbea77b --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SettlementResult.java @@ -0,0 +1,106 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 查询结算账户结果 + *
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter3_5.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class SettlementResult implements Serializable { + /** + *
+   * 字段名:账户类型
+   * 变量名:account_type
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   * 枚举值:
+   *    ACCOUNT_TYPE_BUSINESS:对公银行账户
+   *    ACCOUNT_TYPE_PRIVATE:经营者个人银行卡
+   * 示例值:ACCOUNT_TYPE_BUSINESS
+   * 
+ */ + @SerializedName(value = "account_type") + private String accountType; + + /** + *
+   * 字段名:开户银行
+   * 变量名:account_bank
+   * 是否必填:是
+   * 类型:string(128)
+   * 描述:
+   *  返回特约商户的结算账户-开户银行全称。
+   * 示例值:工商银行
+   * 
+ */ + @SerializedName(value = "account_bank") + private String accountBank; + + /** + *
+   * 字段名:开户银行全称(含支行)
+   * 变量名:bank_name
+   * 是否必填:是
+   * 类型:string(128)
+   * 描述:
+   *  返回特约商户的结算账户-开户银行全称(含支行)。
+   * 示例值:施秉县农村信用合作联社城关信用社
+   * 
+ */ + @SerializedName(value = "bank_name") + private String bankName; + + /** + *
+   * 字段名:开户银行联行号
+   * 变量名:bank_branch_id
+   * 是否必填:是
+   * 类型:string(128)
+   * 描述:
+   *  返回特约商户的结算账户-联行号。
+   * 示例值:402713354941
+   * 
+ */ + @SerializedName(value = "bank_branch_id") + private String bankBranchId; + + /** + *
+   * 字段名:银行账号
+   * 变量名:account_number
+   * 是否必填:是
+   * 类型:string(128)
+   * 描述:
+   *  返回特约商户的结算账户-银行账号,掩码显示。
+   * 示例值:62*************78
+   * 
+ */ + @SerializedName(value = "account_number") + private String accountNumber; + + /** + *
+   * 字段名:汇款验证结果
+   * 变量名:verify_result
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  返回特约商户的结算账户-汇款验证结果。
+   *    VERIFYING:系统汇款验证中,商户可发起提现尝试。
+   *    VERIFY_SUCCESS:系统成功汇款,该账户可正常发起提现。
+   *    VERIFY_FAIL:系统汇款失败,该账户无法发起提现,请检查修改。
+   * 示例值:VERIFY_SUCCESS
+   * 
+ */ + @SerializedName(value = "verify_result") + private String verifyResult; +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SpWithdrawRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SpWithdrawRequest.java new file mode 100644 index 0000000000..0b836366d4 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SpWithdrawRequest.java @@ -0,0 +1,91 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 电商平台提现 + *
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/fund/chapter3_5.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class SpWithdrawRequest implements Serializable { + /** + *
+   * 字段名:商户提现单号
+   * 变量名:out_request_no
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  商户提现单号,由商户自定义生成。
+   * 示例值:20190611222222222200000000012122
+   * 
+ */ + @SerializedName(value = "out_request_no") + private String outRequestNo; + + /** + *
+   * 字段名:提现金额
+   * 变量名:amount
+   * 是否必填:是
+   * 类型:int64
+   * 描述:
+   *  提现金额,单位:分(RMB)
+   * 示例值:1
+   * 
+ */ + @SerializedName(value = "amount") + private Integer amount; + + /** + *
+   * 字段名:备注
+   * 变量名:remark
+   * 是否必填:否
+   * 类型:string(56)
+   * 描述:
+   *  商户对提现单的备注
+   * 示例值:交易提现
+   * 
+ */ + @SerializedName(value = "remark") + private String remark; + + /** + *
+   * 字段名:银行附言
+   * 变量名:bank_memo
+   * 是否必填:否
+   * 类型:string(32)
+   * 描述:
+   *  展示在收款银行系统中的附言,数字、字母最长32个汉字(能否成功展示依赖银行系统支持)。
+   * 示例值:xx平台提现
+   * 
+ */ + @SerializedName(value = "bank_memo") + private String bankMemo; + + /** + *
+   * 字段名:账户类型
+   * 变量名:account_type
+   * 是否必填:是
+   * 类型:string(16)
+   * 描述:
+   *  枚举值:
+   *    BASIC:基本账户
+   *    OPERATION:运营账户
+   *    FEES:手续费账户
+   * 示例值:BASIC
+   * 
+ */ + @SerializedName(value = "account_type") + private String accountType; + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SpWithdrawResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SpWithdrawResult.java new file mode 100644 index 0000000000..b18e246677 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SpWithdrawResult.java @@ -0,0 +1,46 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 电商平台提现 结果 + *
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/fund/chapter3_5.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class SpWithdrawResult implements Serializable { + + /** + *
+   * 字段名:微信支付提现单号
+   * 变量名:withdraw_id
+   * 是否必填:否 (文档里面是【否】,理论上应该都有值)
+   * 类型:string(128)
+   * 描述:
+   *  微信支付系统生成的提现单号。
+   * 示例值:12321937198237912739132791732912793127931279317929791239112123
+   * 
+ */ + @SerializedName(value = "withdraw_id") + private String withdrawId; + + /** + *
+   * 字段名:商户提现单号
+   * 变量名:out_request_no
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  必须是字母数字
+   * 示例值: 20190611222222222200000000012122
+   * 
+ */ + @SerializedName(value = "out_request_no") + private String outRequestNo; +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SubWithdrawRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SubWithdrawRequest.java new file mode 100644 index 0000000000..3c74db24c9 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SubWithdrawRequest.java @@ -0,0 +1,89 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 二级商户账户余额提现 + *
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/combine/chapter3_3.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class SubWithdrawRequest implements Serializable { + + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  电商平台二级商户号,由微信支付生成并下发。
+   * 示例值:1900000109
+   * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:商户提现单号
+   * 变量名:out_request_no
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  必须是字母数字
+   * 示例值: 20190611222222222200000000012122
+   * 
+ */ + @SerializedName(value = "out_request_no") + private String outRequestNo; + + /** + *
+   * 字段名:提现金额
+   * 变量名:amount
+   * 是否必填:是
+   * 类型:int64
+   * 描述:
+   *  提现金额(单位:分)
+   * 示例值:100
+   * 
+ */ + @SerializedName(value = "amount") + private Integer amount; + + /** + *
+   * 字段名:备注
+   * 变量名:remark
+   * 是否必填:否
+   * 类型:string(56)
+   * 描述:
+   *  商户对提现单的备注
+   * 示例值:交易提现
+   * 
+ */ + @SerializedName(value = "remark") + private String remark; + + /** + *
+   * 字段名:银行附言
+   * 变量名:bank_memo
+   * 是否必填:否
+   * 类型:string(32)
+   * 描述:
+   *  展示在收款银行系统中的附言,数字、字母最长32个汉字(能否成功展示依赖银行系统支持)。
+   * 示例值:微信支付提现
+   * 
+ */ + @SerializedName(value = "bank_memo") + private String bankMemo; + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SubWithdrawResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SubWithdrawResult.java new file mode 100644 index 0000000000..21213dd42d --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SubWithdrawResult.java @@ -0,0 +1,60 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 二级商户账户余额提现 结果 + *
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/fund/chapter3_2.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class SubWithdrawResult implements Serializable { + + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  电商平台二级商户号,由微信支付生成并下发。
+   * 示例值:1900000109
+   * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:微信支付提现单号
+   * 变量名:withdraw_id
+   * 是否必填:是
+   * 类型:string(128)
+   * 描述:
+   *  电商平台提交二级商户提现申请后,由微信支付返回的申请单号,作为查询申请状态的唯一标识。
+   * 示例值: 12321937198237912739132791732912793127931279317929791239112123
+   * 
+ */ + @SerializedName(value = "withdraw_id") + private String withdrawId; + + /** + *
+   * 字段名:商户提现单号
+   * 变量名:out_request_no
+   * 是否必填:否
+   * 类型:string(32)
+   * 描述:
+   *  必须是字母数字
+   * 示例值: 20190611222222222200000000012122
+   * 
+ */ + @SerializedName(value = "out_request_no") + private String outRequestNo; +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingReturnQueryRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingReturnQueryRequest.java index 734c805401..d3c7816027 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingReturnQueryRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingReturnQueryRequest.java @@ -72,6 +72,11 @@ protected void checkConstraints() throws WxPayException { this.setSignType(WxPayConstants.SignType.HMAC_SHA256); } + @Override + protected boolean ignoreSubAppId() { + return true; + } + @Override protected void storeMap(Map map) { map.put("order_id", orderId); diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/BaseWxPayRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/BaseWxPayRequest.java index f19935e7e1..394bc8969b 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/BaseWxPayRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/BaseWxPayRequest.java @@ -9,6 +9,7 @@ import lombok.Data; import lombok.experimental.Accessors; import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.BeanUtils; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.common.util.xml.XStreamInitializer; @@ -246,7 +247,7 @@ private String toFastXml() { return document.asXML(); } catch (Exception e) { - throw new RuntimeException("generate xml error", e); + throw new WxRuntimeException("generate xml error", e); } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/BaseWxPayResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/BaseWxPayResult.java index 51865664f4..d83e3d06a5 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/BaseWxPayResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/BaseWxPayResult.java @@ -11,6 +11,7 @@ import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import lombok.Data; +import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import org.apache.commons.lang3.StringUtils; @@ -139,7 +140,7 @@ public static T fromXML(String xmlString, Class c t.loadXml(doc); return (T) t; } catch (Exception e) { - throw new RuntimeException("parse xml error", e); + throw new WxRuntimeException("parse xml error", e); } } XStream xstream = XStreamInitializer.getInstance(); @@ -243,7 +244,7 @@ public String toString() { */ public Map toMap() { if (StringUtils.isBlank(this.xmlString)) { - throw new RuntimeException("xml数据有问题,请核实!"); + throw new WxRuntimeException("xml数据有问题,请核实!"); } Map result = Maps.newHashMap(); @@ -258,7 +259,7 @@ public Map toMap() { result.put(list.item(i).getNodeName(), list.item(i).getTextContent()); } } catch (XPathExpressionException e) { - throw new RuntimeException("非法的xml文本内容:" + xmlString); + throw new WxRuntimeException("非法的xml文本内容:" + xmlString); } return result; @@ -282,7 +283,7 @@ protected Document openXML(String content) { factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); return factory.newDocumentBuilder().parse(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); } catch (Exception e) { - throw new RuntimeException("非法的xml文本内容:\n" + this.xmlString, e); + throw new WxRuntimeException("非法的xml文本内容:\n" + this.xmlString, e); } } @@ -302,7 +303,7 @@ protected String getXmlValue(String... path) { .compile(expression) .evaluate(doc, XPathConstants.STRING); } catch (XPathExpressionException e) { - throw new RuntimeException("未找到相应路径的文本:" + expression); + throw new WxRuntimeException("未找到相应路径的文本:" + expression); } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java index 90997fb375..c0bc6444fe 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java @@ -97,6 +97,18 @@ public interface EcommerceService { */ CombineTransactionsNotifyResult parseCombineNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; + /** + *
+   * 合单查询订单API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/combine/chapter3_3.shtml
+   * 
+ * + * @param outTradeNo 合单商户订单号 + * @return 支付订单信息 + * @throws WxPayException the wx pay exception + */ + CombineTransactionsResult queryCombineTransactions(String outTradeNo) throws WxPayException; + /** *
    *  服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付).
@@ -139,6 +151,18 @@ public interface EcommerceService {
    */
   PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
 
+  /**
+   * 
+   * 普通查询订单API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/e_transactions/chapter3_5.shtml
+   * 
+ * + * @param request 商户订单信息 + * @return 支付订单信息 + * @throws WxPayException the wx pay exception + */ + PartnerTransactionsResult queryPartnerTransactions(PartnerTransactionsQueryRequest request) throws WxPayException; + /** *
    * 服务商账户实时余额
@@ -201,6 +225,18 @@ public interface EcommerceService {
    */
   ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException;
 
+  /**
+   * 
+   * 查询分账结果API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_2.shtml
+   * 
+ * + * @param request 查询分账请求 + * @return 返回数据 profit sharing result + * @throws WxPayException the wx pay exception + */ + ProfitSharingResult queryProfitSharing(ProfitSharingQueryRequest request) throws WxPayException; + /** *
    * 请求分账回退API
@@ -213,4 +249,115 @@ public interface EcommerceService {
    */
   ReturnOrdersResult returnOrders(ReturnOrdersRequest request) throws WxPayException;
 
+  /**
+   * 
+   * 完结分账API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_5.shtml
+   * 
+ * + * @param request 完结分账请求 + * @return 返回数据 return orders result + * @throws WxPayException the wx pay exception + */ + ProfitSharingResult finishOrder(FinishOrderRequest request) throws WxPayException; + + /** + *
+   * 退款申请API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_1.shtml
+   * 
+ * + * @param request 退款请求 + * @return 返回数据 return refunds result + * @throws WxPayException the wx pay exception + */ + RefundsResult refunds(RefundsRequest request) throws WxPayException; + + /** + *
+   * 查询退款API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_2.shtml
+   * 
+ * + * @param subMchid 二级商户号 + * @param refundId 微信退款单号 + * @return 返回数据 return refunds result + * @throws WxPayException the wx pay exception + */ + RefundQueryResult queryRefundByRefundId(String subMchid, String refundId) throws WxPayException; + + /** + *
+   * 查询退款API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_2.shtml
+   * 
+ * + * @param subMchid 二级商户号 + * @param outRefundNo 商户退款单号 + * @return 返回数据 return refunds result + * @throws WxPayException the wx pay exception + */ + RefundQueryResult queryRefundByOutRefundNo(String subMchid, String outRefundNo) throws WxPayException; + + /** + *
+   * 退款通知回调数据处理
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_3.shtml
+   * 
+ * + * @param notifyData 通知数据 + * @param header 通知头部数据,不传则表示不校验头 + * @return 解密后通知数据 partner refund notify result + * @throws WxPayException the wx pay exception + */ + RefundNotifyResult parseRefundNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; + + /** + *
+   * 二级商户账户余额提现API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/fund/chapter3_2.shtml
+   * 
+ * + * @param request 提现请求 + * @return 返回数据 return withdraw result + * @throws WxPayException the wx pay exception + */ + SubWithdrawResult subWithdraw(SubWithdrawRequest request) throws WxPayException; + + /** + *
+   * 电商平台提现API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/fund/chapter3_5.shtml
+   * 
+ * + * @param request 提现请求 + * @return 返回数据 return withdraw result + * @throws WxPayException the wx pay exception + */ + SpWithdrawResult spWithdraw(SpWithdrawRequest request) throws WxPayException; + + /** + *
+   * 修改结算帐号API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter3_4.shtml
+   * 
+ * + * @param subMchid 二级商户号。 + * @param request 结算帐号 + * @throws WxPayException the wx pay exception + */ + void modifySettlement(String subMchid, SettlementRequest request) throws WxPayException; + + /** + *
+   * 查询结算账户API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter3_5.shtml
+   * 
+ * + * @param subMchid 二级商户号。 + * @return 返回数据 return settlement result + * @throws WxPayException the wx pay exception + */ + SettlementResult querySettlement(String subMchid) throws WxPayException; + } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java index b5012643ca..15ca423a29 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java @@ -23,6 +23,7 @@ import com.google.common.base.Joiner; import com.google.common.collect.Maps; import jodd.io.ZipUtil; +import me.chanjar.weixin.common.error.WxRuntimeException; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -409,7 +410,7 @@ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws W WxPayUnifiedOrderResult unifiedOrderResult = this.unifiedOrder(request); String prepayId = unifiedOrderResult.getPrepayId(); if (StringUtils.isBlank(prepayId)) { - throw new RuntimeException(String.format("无法获取prepay id,错误代码: '%s',信息:%s。", + throw new WxRuntimeException(String.format("无法获取prepay id,错误代码: '%s',信息:%s。", unifiedOrderResult.getErrCode(), unifiedOrderResult.getErrCodeDes())); } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java index b792771a1f..eefc7a2648 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java @@ -20,6 +20,7 @@ @RequiredArgsConstructor public class EcommerceServiceImpl implements EcommerceService { + private static final Gson GSON = new GsonBuilder().create(); private final WxPayService payService; @@ -73,14 +74,24 @@ public CombineTransactionsNotifyResult parseCombineNotifyResult(String notifyDat String apiV3Key = this.payService.getConfig().getApiV3Key(); try { String result = AesUtils.decryptToString(associatedData, nonce,cipherText, apiV3Key); - CombineTransactionsNotifyResult notifyResult = GSON.fromJson(result, CombineTransactionsNotifyResult.class); + CombineTransactionsResult transactionsResult = GSON.fromJson(result, CombineTransactionsResult.class); + + CombineTransactionsNotifyResult notifyResult = new CombineTransactionsNotifyResult(); notifyResult.setRawData(response); + notifyResult.setResult(transactionsResult); return notifyResult; } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } + @Override + public CombineTransactionsResult queryCombineTransactions(String outTradeNo) throws WxPayException { + String url = String.format("%s/v3/combine-transactions/out-trade-no/%s", this.payService.getPayBaseUrl(), outTradeNo); + String response = this.payService.getV3(URI.create(url)); + return GSON.fromJson(response, CombineTransactionsResult.class); + } + @Override public TransactionsResult partner(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException { String url = this.payService.getPayBaseUrl() + tradeType.getPartnerUrl(); @@ -108,14 +119,29 @@ public PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyDat String apiV3Key = this.payService.getConfig().getApiV3Key(); try { String result = AesUtils.decryptToString(associatedData, nonce,cipherText, apiV3Key); - PartnerTransactionsNotifyResult notifyResult = GSON.fromJson(result, PartnerTransactionsNotifyResult.class); + PartnerTransactionsResult transactionsResult = GSON.fromJson(result, PartnerTransactionsResult.class); + + PartnerTransactionsNotifyResult notifyResult = new PartnerTransactionsNotifyResult(); notifyResult.setRawData(response); + notifyResult.setResult(transactionsResult); return notifyResult; } catch (GeneralSecurityException | IOException e) { throw new WxPayException("解析报文异常!", e); } } + @Override + public PartnerTransactionsResult queryPartnerTransactions(PartnerTransactionsQueryRequest request) throws WxPayException { + String url = String.format("%s/v3/pay/partner/transactions/out-trade-no/%s", this.payService.getPayBaseUrl(), request.getOutTradeNo()); + if (Objects.isNull(request.getOutTradeNo())) { + url = String.format("%s/v3/pay/partner/transactions/id/%s", this.payService.getPayBaseUrl(), request.getTransactionId()); + } + String query = String.format("?sp_mchid=%s&sub_mchid=%s", request.getSpMchid(), request.getSubMchid()); + URI uri = URI.create(url + query); + String response = this.payService.getV3(uri); + return GSON.fromJson(response, PartnerTransactionsResult.class); + } + @Override public FundBalanceResult spNowBalance(SpAccountTypeEnum accountType) throws WxPayException { String url = String.format("%s/v3/merchant/fund/balance/%s", this.payService.getPayBaseUrl(), accountType); @@ -155,6 +181,14 @@ public ProfitSharingResult profitSharing(ProfitSharingRequest request) throws Wx return GSON.fromJson(response, ProfitSharingResult.class); } + @Override + public ProfitSharingResult queryProfitSharing(ProfitSharingQueryRequest request) throws WxPayException { + String url = String.format("%s/v3/ecommerce/profitsharing/orders?sub_mchid=%s&transaction_id=%s&out_order_no=%s", + this.payService.getPayBaseUrl(), request.getSubMchid(), request.getTransactionId(), request.getOutOrderNo()); + String response = this.payService.getV3(URI.create(url)); + return GSON.fromJson(response, ProfitSharingResult.class); + } + @Override public ReturnOrdersResult returnOrders(ReturnOrdersRequest request) throws WxPayException { String url = String.format("%s/v3/ecommerce/profitsharing/returnorders", this.payService.getPayBaseUrl()); @@ -162,6 +196,89 @@ public ReturnOrdersResult returnOrders(ReturnOrdersRequest request) throws WxPay return GSON.fromJson(response, ReturnOrdersResult.class); } + @Override + public ProfitSharingResult finishOrder(FinishOrderRequest request) throws WxPayException { + String url = String.format("%s/v3/ecommerce/profitsharing/finish-order", this.payService.getPayBaseUrl()); + String response = this.payService.postV3(url, GSON.toJson(request)); + return GSON.fromJson(response, ProfitSharingResult.class); + } + + @Override + public RefundsResult refunds(RefundsRequest request) throws WxPayException { + String url = String.format("%s/v3/ecommerce/refunds/apply", this.payService.getPayBaseUrl()); + String response = this.payService.postV3(url, GSON.toJson(request)); + return GSON.fromJson(response, RefundsResult.class); + } + + @Override + public RefundQueryResult queryRefundByRefundId(String subMchid, String refundId) throws WxPayException { + String url = String.format("%s/v3/ecommerce/refunds/id/%s?sub_mchid=%s", this.payService.getPayBaseUrl(), refundId, subMchid); + String response = this.payService.getV3(URI.create(url)); + return GSON.fromJson(response, RefundQueryResult.class); + } + + @Override + public RefundQueryResult queryRefundByOutRefundNo(String subMchid, String outRefundNo) throws WxPayException { + String url = String.format("%s/v3/ecommerce/applyments/out-request-no/%s?sub_mchid=%s", this.payService.getPayBaseUrl(), outRefundNo, subMchid); + String response = this.payService.getV3(URI.create(url)); + return GSON.fromJson(response, RefundQueryResult.class); + } + + @Override + public RefundNotifyResult parseRefundNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { + if(Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)){ + throw new WxPayException("非法请求,头部信息验证失败"); + } + NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class); + NotifyResponse.Resource resource = response.getResource(); + String cipherText = resource.getCiphertext(); + String associatedData = resource.getAssociatedData(); + String nonce = resource.getNonce(); + String apiV3Key = this.payService.getConfig().getApiV3Key(); + try { + String result = AesUtils.decryptToString(associatedData, nonce,cipherText, apiV3Key); + RefundNotifyResult notifyResult = GSON.fromJson(result, RefundNotifyResult.class); + notifyResult.setRawData(response); + return notifyResult; + } catch (GeneralSecurityException | IOException e) { + throw new WxPayException("解析报文异常!", e); + } + } + + @Override + public SubWithdrawResult subWithdraw(SubWithdrawRequest request) throws WxPayException { + String url = String.format("%s/v3/ecommerce/fund/withdraw", this.payService.getPayBaseUrl()); + String response = this.payService.postV3(url, GSON.toJson(request)); + return GSON.fromJson(response, SubWithdrawResult.class); + } + + @Override + public SpWithdrawResult spWithdraw(SpWithdrawRequest request) throws WxPayException { + String url = String.format("%s/v3/merchant/fund/withdraw", this.payService.getPayBaseUrl()); + String response = this.payService.postV3(url, GSON.toJson(request)); + return GSON.fromJson(response, SpWithdrawResult.class); + } + + @Override + public void modifySettlement(String subMchid, SettlementRequest request) throws WxPayException { + String url = String.format("%s/v3/apply4sub/sub_merchants/%s/modify-settlement", this.payService.getPayBaseUrl(), subMchid); + RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate()); + this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request)); + } + + @Override + public SettlementResult querySettlement(String subMchid) throws WxPayException { + String url = String.format("%s/v3/apply4sub/sub_merchants/%s/settlement", this.payService.getPayBaseUrl(), subMchid); + String response = this.payService.getV3(URI.create(url)); + return GSON.fromJson(response, SettlementResult.class); + } + + /** + * 校验通知签名 + * @param header 通知头信息 + * @param data 通知数据 + * @return true:校验通过 false:校验不通过 + */ private boolean verifyNotifySign(SignatureHeader header, String data) { String beforeSign = String.format("%s\n%s\n%s\n", header.getTimeStamp(), diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/AutoUpdateCertificatesVerifier.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/AutoUpdateCertificatesVerifier.java index a490108146..e93e3cd78b 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/AutoUpdateCertificatesVerifier.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/AutoUpdateCertificatesVerifier.java @@ -10,6 +10,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.error.WxRuntimeException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; @@ -94,7 +95,7 @@ public AutoUpdateCertificatesVerifier(Credentials credentials, byte[] apiV3Key, autoUpdateCert(); instant = Instant.now(); } catch (IOException | GeneralSecurityException e) { - throw new RuntimeException(e); + throw new WxRuntimeException(e); } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/CertificatesVerifier.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/CertificatesVerifier.java index 7239d9e64d..9ca8b5b836 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/CertificatesVerifier.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/CertificatesVerifier.java @@ -1,5 +1,7 @@ package com.github.binarywang.wxpay.v3.auth; +import me.chanjar.weixin.common.error.WxRuntimeException; + import java.math.BigInteger; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -30,11 +32,11 @@ private boolean verify(X509Certificate certificate, byte[] message, String signa sign.update(message); return sign.verify(Base64.getDecoder().decode(signature)); } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("当前Java环境不支持SHA256withRSA", e); + throw new WxRuntimeException("当前Java环境不支持SHA256withRSA", e); } catch (SignatureException e) { - throw new RuntimeException("签名验证过程发生了错误", e); + throw new WxRuntimeException("签名验证过程发生了错误", e); } catch (InvalidKeyException e) { - throw new RuntimeException("无效的证书", e); + throw new WxRuntimeException("无效的证书", e); } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/PrivateKeySigner.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/PrivateKeySigner.java index 37ec51cf58..183e46e260 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/PrivateKeySigner.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/PrivateKeySigner.java @@ -1,5 +1,7 @@ package com.github.binarywang.wxpay.v3.auth; +import me.chanjar.weixin.common.error.WxRuntimeException; + import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; @@ -27,11 +29,11 @@ public SignatureResult sign(byte[] message) { return new SignatureResult( Base64.getEncoder().encodeToString(sign.sign()), certificateSerialNumber); } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("当前Java环境不支持SHA256withRSA", e); + throw new WxRuntimeException("当前Java环境不支持SHA256withRSA", e); } catch (SignatureException e) { - throw new RuntimeException("签名计算失败", e); + throw new WxRuntimeException("签名计算失败", e); } catch (InvalidKeyException e) { - throw new RuntimeException("无效的私钥", e); + throw new WxRuntimeException("无效的私钥", e); } } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/PemUtils.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/PemUtils.java index bf4d2657b5..c039ccb636 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/PemUtils.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/PemUtils.java @@ -1,5 +1,7 @@ package com.github.binarywang.wxpay.v3.util; +import me.chanjar.weixin.common.error.WxRuntimeException; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -35,11 +37,11 @@ public static PrivateKey loadPrivateKey(InputStream inputStream) { return kf.generatePrivate( new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey))); } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("当前Java环境不支持RSA", e); + throw new WxRuntimeException("当前Java环境不支持RSA", e); } catch (InvalidKeySpecException e) { - throw new RuntimeException("无效的密钥格式"); + throw new WxRuntimeException("无效的密钥格式"); } catch (IOException e) { - throw new RuntimeException("无效的密钥"); + throw new WxRuntimeException("无效的密钥"); } } @@ -50,11 +52,11 @@ public static X509Certificate loadCertificate(InputStream inputStream) { cert.checkValidity(); return cert; } catch (CertificateExpiredException e) { - throw new RuntimeException("证书已过期", e); + throw new WxRuntimeException("证书已过期", e); } catch (CertificateNotYetValidException e) { - throw new RuntimeException("证书尚未生效", e); + throw new WxRuntimeException("证书尚未生效", e); } catch (CertificateException e) { - throw new RuntimeException("无效的证书", e); + throw new WxRuntimeException("无效的证书", e); } } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/RsaCryptoUtil.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/RsaCryptoUtil.java index d88c67e419..287ac11fcf 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/RsaCryptoUtil.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/RsaCryptoUtil.java @@ -2,6 +2,7 @@ import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.v3.SpecEncrypt; +import me.chanjar.weixin.common.error.WxRuntimeException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; @@ -70,7 +71,7 @@ public static String encryptOAEP(String message, X509Certificate certificate) byte[] ciphertext = cipher.doFinal(data); return Base64.getEncoder().encodeToString(ciphertext); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { - throw new RuntimeException("当前Java环境不支持RSA v1.5/OAEP", e); + throw new WxRuntimeException("当前Java环境不支持RSA v1.5/OAEP", e); } catch (InvalidKeyException e) { throw new IllegalArgumentException("无效的证书", e); } catch (IllegalBlockSizeException | BadPaddingException e) { @@ -87,7 +88,7 @@ public static String decryptOAEP(String ciphertext, PrivateKey privateKey) byte[] data = Base64.getDecoder().decode(ciphertext); return new String(cipher.doFinal(data), StandardCharsets.UTF_8); } catch (NoSuchPaddingException | NoSuchAlgorithmException e) { - throw new RuntimeException("当前Java环境不支持RSA v1.5/OAEP", e); + throw new WxRuntimeException("当前Java环境不支持RSA v1.5/OAEP", e); } catch (InvalidKeyException e) { throw new IllegalArgumentException("无效的私钥", e); } catch (BadPaddingException | IllegalBlockSizeException e) { diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/SignUtils.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/SignUtils.java index 275a8d51ba..fff68ce280 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/SignUtils.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/SignUtils.java @@ -1,12 +1,14 @@ package com.github.binarywang.wxpay.v3.util; +import me.chanjar.weixin.common.error.WxRuntimeException; + import java.security.*; import java.util.Base64; import java.util.Random; public class SignUtils { - public static String sign(String string, PrivateKey privateKey){ + public static String sign(String string, PrivateKey privateKey) { try { Signature sign = Signature.getInstance("SHA256withRSA"); sign.initSign(privateKey); @@ -14,23 +16,24 @@ public static String sign(String string, PrivateKey privateKey){ return Base64.getEncoder().encodeToString(sign.sign()); } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("当前Java环境不支持SHA256withRSA", e); + throw new WxRuntimeException("当前Java环境不支持SHA256withRSA", e); } catch (SignatureException e) { - throw new RuntimeException("签名计算失败", e); + throw new WxRuntimeException("签名计算失败", e); } catch (InvalidKeyException e) { - throw new RuntimeException("无效的私钥", e); + throw new WxRuntimeException("无效的私钥", e); } } /** * 随机生成32位字符串. */ - public static String genRandomStr(){ + public static String genRandomStr() { return genRandomStr(32); } /** * 生成随机字符串 + * * @param length 字符串长度 * @return */ diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java new file mode 100644 index 0000000000..b56084466b --- /dev/null +++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java @@ -0,0 +1,78 @@ +package com.github.binarywang.wxpay.service.impl; + +import com.github.binarywang.wxpay.bean.ecommerce.PartnerTransactionsQueryRequest; +import com.github.binarywang.wxpay.bean.ecommerce.PartnerTransactionsResult; +import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; +import com.github.binarywang.wxpay.exception.WxPayException; +import com.github.binarywang.wxpay.service.WxPayService; +import com.github.binarywang.wxpay.testbase.ApiTestModule; +import com.google.inject.Inject; +import lombok.extern.slf4j.Slf4j; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import java.nio.charset.StandardCharsets; + +@Slf4j +@Test +@Guice(modules = ApiTestModule.class) +public class EcommerceServiceImplTest { + + @Inject + private WxPayService wxPayService; + + @Test + public void testNotifySign(){ + //通知报文主体 + String notifyData = ""; + //请求头 Wechatpay-Timestamp + String timeStamp = ""; + //请求头 Wechatpay-Nonce + String nonce = ""; + //请求头 Wechatpay-Signature + String signed = ""; + //请求头 Wechatpay-Serial + String serialNo = ""; + + SignatureHeader header = new SignatureHeader(); + header.setNonce(nonce); + header.setSerialNo(serialNo); + header.setTimeStamp(timeStamp); + header.setSigned(signed); + + String beforeSign = String.format("%s\n%s\n%s\n", + header.getTimeStamp(), + header.getNonce(), + notifyData); + boolean signResult = wxPayService.getConfig().getVerifier().verify(header.getSerialNo(), + beforeSign.getBytes(StandardCharsets.UTF_8), header.getSigned()); + log.info("签名结果:{} \nheader:{} \ndata:{}", signResult, header, notifyData); + } + + @Test + public void testQueryPartnerTransactions() throws WxPayException { + PartnerTransactionsQueryRequest request = new PartnerTransactionsQueryRequest(); + //服务商商户号 + request.setSpMchid(""); + //二级商户号 + request.setSubMchid(""); + //商户订单号 + request.setOutTradeNo(""); + //微信订单号 + request.setTransactionId(""); + wxPayService.getEcommerceService().queryPartnerTransactions(request); + } + + @Test + public void testSubNowBalance() throws WxPayException { + String subMchid = ""; + wxPayService.getEcommerceService().subNowBalance(subMchid); + } + + @Test + public void testSubDayEndBalance() throws WxPayException { + String subMchid = ""; + String date = ""; + wxPayService.getEcommerceService().subDayEndBalance(subMchid,date); + } +} diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/testbase/ApiTestModule.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/testbase/ApiTestModule.java index b29b1af16c..7155b544b6 100644 --- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/testbase/ApiTestModule.java +++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/testbase/ApiTestModule.java @@ -6,6 +6,7 @@ import com.google.inject.Binder; import com.google.inject.Module; import com.thoughtworks.xstream.XStream; +import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,7 +25,7 @@ public class ApiTestModule implements Module { public void configure(Binder binder) { try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) { if (inputStream == null) { - throw new RuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成"); + throw new WxRuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成"); } XmlWxPayConfig config = this.fromXml(XmlWxPayConfig.class, inputStream);