Skip to content

Commit 32f88b7

Browse files
authored
合并开发分支,发布正式版
2 parents 78a930a + a503171 commit 32f88b7

File tree

194 files changed

+6430
-1124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+6430
-1124
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Icon
4242
.Spotlight-V100
4343
.TemporaryItems
4444
.Trashes
45+
.vscode
4546
.VolumeIcon.icns
4647
.AppleDB
4748
.AppleDesktop

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "interactive"
3+
}

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.github.binarywang</groupId>
88
<artifactId>wx-java</artifactId>
9-
<version>3.3.0</version>
9+
<version>3.4.0</version>
1010
<packaging>pom</packaging>
1111
<name>WxJava - Weixin/Wechat Java SDK</name>
1212
<description>微信开发Java SDK</description>
@@ -105,6 +105,8 @@
105105
<module>weixin-java-pay</module>
106106
<module>weixin-java-miniapp</module>
107107
<module>weixin-java-open</module>
108+
<module>starters/wx-java-pay-starter</module>
109+
<module>starters/wx-java-mp-starter</module>
108110
<!--module>weixin-java-osgi</module-->
109111
</modules>
110112

starters/wx-java-mp-starter/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# wx-java-mp-starter
2+
## 快速开始
3+
1. 引入依赖
4+
```xml
5+
<dependency>
6+
<groupId>com.github.binarywang</groupId>
7+
<artifactId>wx-java-mp-starter</artifactId>
8+
<version>${version}</version>
9+
</dependency>
10+
```
11+
2. 添加配置(application.properties)
12+
```properties
13+
# 公众号配置(必填)
14+
wx.mp.appId = @appId
15+
wx.mp.secret = @secret
16+
wx.mp.token = @token
17+
wx.mp.aesKey = @aesKey
18+
# 存储配置redis(可选)
19+
wx.mp.config-storage.type = redis
20+
wx.mp.config-storage.redis.host = 127.0.0.1
21+
wx.mp.config-storage.redis.port = 6379
22+
```
23+
3. 支持自动注入的类型
24+
25+
`WxMpService`以及相关的服务类, 比如: `wxMpService.getXxxService`。
26+
27+
28+
29+
30+
31+
32+

starters/wx-java-mp-starter/pom.xml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.github.binarywang</groupId>
8+
<artifactId>wx-java</artifactId>
9+
<version>3.4.0</version>
10+
<relativePath>../../</relativePath>
11+
</parent>
12+
13+
<artifactId>wx-java-mp-starter</artifactId>
14+
<name>WxJava - Spring Boot Starter for MP</name>
15+
<description>微信公众号开发的Spring Boot Starter</description>
16+
17+
<properties>
18+
<spring.boot.version>2.1.4.RELEASE</spring.boot.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-autoconfigure</artifactId>
25+
<version>${spring.boot.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-configuration-processor</artifactId>
30+
<version>${spring.boot.version}</version>
31+
<optional>true</optional>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.github.binarywang</groupId>
35+
<artifactId>weixin-java-mp</artifactId>
36+
<version>${project.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>redis.clients</groupId>
40+
<artifactId>jedis</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.projectlombok</groupId>
44+
<artifactId>lombok</artifactId>
45+
<scope>provided</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-maven-plugin</artifactId>
54+
<version>${spring.boot.version}</version>
55+
</plugin>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-source-plugin</artifactId>
59+
<version>2.2.1</version>
60+
<executions>
61+
<execution>
62+
<id>attach-sources</id>
63+
<goals>
64+
<goal>jar-no-fork</goal>
65+
</goals>
66+
</execution>
67+
</executions>
68+
</plugin>
69+
</plugins>
70+
</build>
71+
72+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.binarywang.spring.starter.wxjava.mp;
2+
3+
import lombok.Data;
4+
5+
import java.io.Serializable;
6+
7+
/**
8+
* Redis配置
9+
*/
10+
@Data
11+
public class RedisProperties implements Serializable {
12+
13+
/**
14+
* 主机地址
15+
*/
16+
private String host = "127.0.0.1";
17+
18+
/**
19+
* 端口号
20+
*/
21+
private int port = 6379;
22+
23+
/**
24+
* 密码
25+
*/
26+
private String password;
27+
28+
/**
29+
* 超时
30+
*/
31+
private int timeout = 2000;
32+
33+
/**
34+
* 数据库
35+
*/
36+
private int database = 0;
37+
38+
private Integer maxActive;
39+
private Integer maxIdle;
40+
private Integer maxWaitMillis;
41+
private Integer minIdle;
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.binarywang.spring.starter.wxjava.mp;
2+
3+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.context.annotation.Import;
6+
7+
@Configuration
8+
@EnableConfigurationProperties(WxMpProperties.class)
9+
@Import({WxMpStorageAutoConfiguration.class, WxMpServiceAutoConfiguration.class})
10+
public class WxMpAutoConfiguration {
11+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.binarywang.spring.starter.wxjava.mp;
2+
3+
import lombok.Data;
4+
import org.springframework.boot.context.properties.ConfigurationProperties;
5+
6+
import java.io.Serializable;
7+
8+
import static com.binarywang.spring.starter.wxjava.mp.WxMpProperties.PREFIX;
9+
import static com.binarywang.spring.starter.wxjava.mp.WxMpProperties.StorageType.memory;
10+
11+
12+
/**
13+
* 微信接入相关配置属性
14+
*/
15+
@Data
16+
@ConfigurationProperties(PREFIX)
17+
public class WxMpProperties {
18+
public static final String PREFIX = "wx.mp";
19+
20+
/**
21+
* 设置微信公众号的appid
22+
*/
23+
private String appId;
24+
25+
/**
26+
* 设置微信公众号的app secret
27+
*/
28+
private String secret;
29+
30+
/**
31+
* 设置微信公众号的token
32+
*/
33+
private String token;
34+
35+
/**
36+
* 设置微信公众号的EncodingAESKey
37+
*/
38+
private String aesKey;
39+
40+
/**
41+
* 存储策略, memory, redis
42+
*/
43+
private ConfigStorage configStorage = new ConfigStorage();
44+
45+
46+
@Data
47+
public static class ConfigStorage implements Serializable {
48+
49+
private StorageType type = memory;
50+
51+
private RedisProperties redis = new RedisProperties();
52+
53+
}
54+
55+
public enum StorageType {
56+
memory, redis
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.binarywang.spring.starter.wxjava.mp;
2+
3+
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
4+
import me.chanjar.weixin.mp.api.WxMpService;
5+
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
8+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
9+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
10+
import org.springframework.context.ApplicationContext;
11+
import org.springframework.context.annotation.Bean;
12+
import org.springframework.context.annotation.Configuration;
13+
14+
/**
15+
* 微信公众号相关服务自动注册
16+
*/
17+
@Configuration
18+
public class WxMpServiceAutoConfiguration {
19+
@Autowired
20+
private ApplicationContext ctx;
21+
22+
@Bean
23+
@ConditionalOnMissingBean
24+
public WxMpService wxMpService(WxMpConfigStorage configStorage) {
25+
WxMpService wxMpService = new WxMpServiceImpl();
26+
wxMpService.setWxMpConfigStorage(configStorage);
27+
registerWxMpSubService(wxMpService);
28+
return wxMpService;
29+
}
30+
31+
@ConditionalOnBean(WxMpService.class)
32+
public Object registerWxMpSubService(WxMpService wxMpService) {
33+
ConfigurableListableBeanFactory factory = (ConfigurableListableBeanFactory) ctx.getAutowireCapableBeanFactory();
34+
factory.registerSingleton("wxMpKefuService", wxMpService.getKefuService());
35+
factory.registerSingleton("wxMpMaterialService", wxMpService.getMaterialService());
36+
factory.registerSingleton("wxMpMenuService", wxMpService.getMenuService());
37+
factory.registerSingleton("wxMpUserService", wxMpService.getUserService());
38+
factory.registerSingleton("wxMpUserTagService", wxMpService.getUserTagService());
39+
factory.registerSingleton("wxMpQrcodeService", wxMpService.getQrcodeService());
40+
factory.registerSingleton("wxMpCardService", wxMpService.getCardService());
41+
factory.registerSingleton("wxMpDataCubeService", wxMpService.getDataCubeService());
42+
factory.registerSingleton("wxMpUserBlacklistService", wxMpService.getBlackListService());
43+
factory.registerSingleton("wxMpStoreService", wxMpService.getStoreService());
44+
factory.registerSingleton("wxMpTemplateMsgService", wxMpService.getTemplateMsgService());
45+
factory.registerSingleton("wxMpSubscribeMsgService", wxMpService.getSubscribeMsgService());
46+
factory.registerSingleton("wxMpDeviceService", wxMpService.getDeviceService());
47+
factory.registerSingleton("wxMpShakeService", wxMpService.getShakeService());
48+
factory.registerSingleton("wxMpMemberCardService", wxMpService.getMemberCardService());
49+
factory.registerSingleton("wxMpMassMessageService", wxMpService.getMassMessageService());
50+
return Boolean.TRUE;
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.binarywang.spring.starter.wxjava.mp;
2+
3+
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
4+
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
5+
import me.chanjar.weixin.mp.api.WxMpInRedisConfigStorage;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
import redis.clients.jedis.JedisPool;
11+
import redis.clients.jedis.JedisPoolConfig;
12+
13+
/**
14+
* 微信公众号存储策略自动配置
15+
*/
16+
@Configuration
17+
public class WxMpStorageAutoConfiguration {
18+
19+
@Autowired
20+
private WxMpProperties properties;
21+
22+
@Autowired(required = false)
23+
private JedisPool jedisPool;
24+
25+
@Bean
26+
@ConditionalOnMissingBean(WxMpConfigStorage.class)
27+
public WxMpConfigStorage wxMpInMemoryConfigStorage() {
28+
WxMpProperties.ConfigStorage storage = properties.getConfigStorage();
29+
WxMpProperties.StorageType type = storage.getType();
30+
31+
if (type == WxMpProperties.StorageType.redis) {
32+
return getWxMpInRedisConfigStorage();
33+
}
34+
return getWxMpInMemoryConfigStorage();
35+
}
36+
37+
private WxMpInMemoryConfigStorage getWxMpInMemoryConfigStorage() {
38+
WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage();
39+
setWxMpInfo(config);
40+
return config;
41+
}
42+
43+
private WxMpInRedisConfigStorage getWxMpInRedisConfigStorage() {
44+
JedisPool poolToUse = jedisPool;
45+
if (poolToUse == null) {
46+
poolToUse = getJedisPool();
47+
}
48+
WxMpInRedisConfigStorage config = new WxMpInRedisConfigStorage(poolToUse);
49+
setWxMpInfo(config);
50+
return config;
51+
}
52+
53+
private void setWxMpInfo(WxMpInMemoryConfigStorage config) {
54+
config.setAppId(properties.getAppId());
55+
config.setSecret(properties.getSecret());
56+
config.setToken(properties.getToken());
57+
config.setAesKey(properties.getAesKey());
58+
}
59+
60+
private JedisPool getJedisPool() {
61+
WxMpProperties.ConfigStorage storage = properties.getConfigStorage();
62+
RedisProperties redis = storage.getRedis();
63+
64+
JedisPoolConfig config = new JedisPoolConfig();
65+
if (redis.getMaxActive() != null) {
66+
config.setMaxTotal(redis.getMaxActive());
67+
}
68+
if (redis.getMaxIdle() != null) {
69+
config.setMaxIdle(redis.getMaxIdle());
70+
}
71+
if (redis.getMaxWaitMillis() != null) {
72+
config.setMaxWaitMillis(redis.getMaxWaitMillis());
73+
}
74+
if (redis.getMinIdle() != null) {
75+
config.setMinIdle(redis.getMinIdle());
76+
}
77+
config.setTestOnBorrow(true);
78+
config.setTestWhileIdle(true);
79+
80+
JedisPool pool = new JedisPool(config, redis.getHost(), redis.getPort(),
81+
redis.getTimeout(), redis.getPassword(), redis.getDatabase());
82+
return pool;
83+
}
84+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.binarywang.spring.starter.wxjava.mp.WxMpAutoConfiguration

0 commit comments

Comments
 (0)