-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
194 changed files
with
6,430 additions
and
1,124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ Icon | |
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.vscode | ||
.VolumeIcon.icns | ||
.AppleDB | ||
.AppleDesktop | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"java.configuration.updateBuildConfiguration": "interactive" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# wx-java-mp-starter | ||
## 快速开始 | ||
1. 引入依赖 | ||
```xml | ||
<dependency> | ||
<groupId>com.github.binarywang</groupId> | ||
<artifactId>wx-java-mp-starter</artifactId> | ||
<version>${version}</version> | ||
</dependency> | ||
``` | ||
2. 添加配置(application.properties) | ||
```properties | ||
# 公众号配置(必填) | ||
wx.mp.appId = @appId | ||
wx.mp.secret = @secret | ||
wx.mp.token = @token | ||
wx.mp.aesKey = @aesKey | ||
# 存储配置redis(可选) | ||
wx.mp.config-storage.type = redis | ||
wx.mp.config-storage.redis.host = 127.0.0.1 | ||
wx.mp.config-storage.redis.port = 6379 | ||
``` | ||
3. 支持自动注入的类型 | ||
|
||
`WxMpService`以及相关的服务类, 比如: `wxMpService.getXxxService`。 | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.github.binarywang</groupId> | ||
<artifactId>wx-java</artifactId> | ||
<version>3.4.0</version> | ||
<relativePath>../../</relativePath> | ||
</parent> | ||
|
||
<artifactId>wx-java-mp-starter</artifactId> | ||
<name>WxJava - Spring Boot Starter for MP</name> | ||
<description>微信公众号开发的Spring Boot Starter</description> | ||
|
||
<properties> | ||
<spring.boot.version>2.1.4.RELEASE</spring.boot.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.binarywang</groupId> | ||
<artifactId>weixin-java-mp</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>redis.clients</groupId> | ||
<artifactId>jedis</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>2.2.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar-no-fork</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
42 changes: 42 additions & 0 deletions
42
...ava-mp-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/RedisProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.binarywang.spring.starter.wxjava.mp; | ||
|
||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Redis配置 | ||
*/ | ||
@Data | ||
public class RedisProperties implements Serializable { | ||
|
||
/** | ||
* 主机地址 | ||
*/ | ||
private String host = "127.0.0.1"; | ||
|
||
/** | ||
* 端口号 | ||
*/ | ||
private int port = 6379; | ||
|
||
/** | ||
* 密码 | ||
*/ | ||
private String password; | ||
|
||
/** | ||
* 超时 | ||
*/ | ||
private int timeout = 2000; | ||
|
||
/** | ||
* 数据库 | ||
*/ | ||
private int database = 0; | ||
|
||
private Integer maxActive; | ||
private Integer maxIdle; | ||
private Integer maxWaitMillis; | ||
private Integer minIdle; | ||
} |
11 changes: 11 additions & 0 deletions
11
...-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/WxMpAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.binarywang.spring.starter.wxjava.mp; | ||
|
||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(WxMpProperties.class) | ||
@Import({WxMpStorageAutoConfiguration.class, WxMpServiceAutoConfiguration.class}) | ||
public class WxMpAutoConfiguration { | ||
} |
58 changes: 58 additions & 0 deletions
58
...java-mp-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/WxMpProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.binarywang.spring.starter.wxjava.mp; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
import java.io.Serializable; | ||
|
||
import static com.binarywang.spring.starter.wxjava.mp.WxMpProperties.PREFIX; | ||
import static com.binarywang.spring.starter.wxjava.mp.WxMpProperties.StorageType.memory; | ||
|
||
|
||
/** | ||
* 微信接入相关配置属性 | ||
*/ | ||
@Data | ||
@ConfigurationProperties(PREFIX) | ||
public class WxMpProperties { | ||
public static final String PREFIX = "wx.mp"; | ||
|
||
/** | ||
* 设置微信公众号的appid | ||
*/ | ||
private String appId; | ||
|
||
/** | ||
* 设置微信公众号的app secret | ||
*/ | ||
private String secret; | ||
|
||
/** | ||
* 设置微信公众号的token | ||
*/ | ||
private String token; | ||
|
||
/** | ||
* 设置微信公众号的EncodingAESKey | ||
*/ | ||
private String aesKey; | ||
|
||
/** | ||
* 存储策略, memory, redis | ||
*/ | ||
private ConfigStorage configStorage = new ConfigStorage(); | ||
|
||
|
||
@Data | ||
public static class ConfigStorage implements Serializable { | ||
|
||
private StorageType type = memory; | ||
|
||
private RedisProperties redis = new RedisProperties(); | ||
|
||
} | ||
|
||
public enum StorageType { | ||
memory, redis | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...r/src/main/java/com/binarywang/spring/starter/wxjava/mp/WxMpServiceAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.binarywang.spring.starter.wxjava.mp; | ||
|
||
import me.chanjar.weixin.mp.api.WxMpConfigStorage; | ||
import me.chanjar.weixin.mp.api.WxMpService; | ||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* 微信公众号相关服务自动注册 | ||
*/ | ||
@Configuration | ||
public class WxMpServiceAutoConfiguration { | ||
@Autowired | ||
private ApplicationContext ctx; | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public WxMpService wxMpService(WxMpConfigStorage configStorage) { | ||
WxMpService wxMpService = new WxMpServiceImpl(); | ||
wxMpService.setWxMpConfigStorage(configStorage); | ||
registerWxMpSubService(wxMpService); | ||
return wxMpService; | ||
} | ||
|
||
@ConditionalOnBean(WxMpService.class) | ||
public Object registerWxMpSubService(WxMpService wxMpService) { | ||
ConfigurableListableBeanFactory factory = (ConfigurableListableBeanFactory) ctx.getAutowireCapableBeanFactory(); | ||
factory.registerSingleton("wxMpKefuService", wxMpService.getKefuService()); | ||
factory.registerSingleton("wxMpMaterialService", wxMpService.getMaterialService()); | ||
factory.registerSingleton("wxMpMenuService", wxMpService.getMenuService()); | ||
factory.registerSingleton("wxMpUserService", wxMpService.getUserService()); | ||
factory.registerSingleton("wxMpUserTagService", wxMpService.getUserTagService()); | ||
factory.registerSingleton("wxMpQrcodeService", wxMpService.getQrcodeService()); | ||
factory.registerSingleton("wxMpCardService", wxMpService.getCardService()); | ||
factory.registerSingleton("wxMpDataCubeService", wxMpService.getDataCubeService()); | ||
factory.registerSingleton("wxMpUserBlacklistService", wxMpService.getBlackListService()); | ||
factory.registerSingleton("wxMpStoreService", wxMpService.getStoreService()); | ||
factory.registerSingleton("wxMpTemplateMsgService", wxMpService.getTemplateMsgService()); | ||
factory.registerSingleton("wxMpSubscribeMsgService", wxMpService.getSubscribeMsgService()); | ||
factory.registerSingleton("wxMpDeviceService", wxMpService.getDeviceService()); | ||
factory.registerSingleton("wxMpShakeService", wxMpService.getShakeService()); | ||
factory.registerSingleton("wxMpMemberCardService", wxMpService.getMemberCardService()); | ||
factory.registerSingleton("wxMpMassMessageService", wxMpService.getMassMessageService()); | ||
return Boolean.TRUE; | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
...r/src/main/java/com/binarywang/spring/starter/wxjava/mp/WxMpStorageAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.binarywang.spring.starter.wxjava.mp; | ||
|
||
import me.chanjar.weixin.mp.api.WxMpConfigStorage; | ||
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; | ||
import me.chanjar.weixin.mp.api.WxMpInRedisConfigStorage; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import redis.clients.jedis.JedisPool; | ||
import redis.clients.jedis.JedisPoolConfig; | ||
|
||
/** | ||
* 微信公众号存储策略自动配置 | ||
*/ | ||
@Configuration | ||
public class WxMpStorageAutoConfiguration { | ||
|
||
@Autowired | ||
private WxMpProperties properties; | ||
|
||
@Autowired(required = false) | ||
private JedisPool jedisPool; | ||
|
||
@Bean | ||
@ConditionalOnMissingBean(WxMpConfigStorage.class) | ||
public WxMpConfigStorage wxMpInMemoryConfigStorage() { | ||
WxMpProperties.ConfigStorage storage = properties.getConfigStorage(); | ||
WxMpProperties.StorageType type = storage.getType(); | ||
|
||
if (type == WxMpProperties.StorageType.redis) { | ||
return getWxMpInRedisConfigStorage(); | ||
} | ||
return getWxMpInMemoryConfigStorage(); | ||
} | ||
|
||
private WxMpInMemoryConfigStorage getWxMpInMemoryConfigStorage() { | ||
WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage(); | ||
setWxMpInfo(config); | ||
return config; | ||
} | ||
|
||
private WxMpInRedisConfigStorage getWxMpInRedisConfigStorage() { | ||
JedisPool poolToUse = jedisPool; | ||
if (poolToUse == null) { | ||
poolToUse = getJedisPool(); | ||
} | ||
WxMpInRedisConfigStorage config = new WxMpInRedisConfigStorage(poolToUse); | ||
setWxMpInfo(config); | ||
return config; | ||
} | ||
|
||
private void setWxMpInfo(WxMpInMemoryConfigStorage config) { | ||
config.setAppId(properties.getAppId()); | ||
config.setSecret(properties.getSecret()); | ||
config.setToken(properties.getToken()); | ||
config.setAesKey(properties.getAesKey()); | ||
} | ||
|
||
private JedisPool getJedisPool() { | ||
WxMpProperties.ConfigStorage storage = properties.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); | ||
|
||
JedisPool pool = new JedisPool(config, redis.getHost(), redis.getPort(), | ||
redis.getTimeout(), redis.getPassword(), redis.getDatabase()); | ||
return pool; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
starters/wx-java-mp-starter/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.binarywang.spring.starter.wxjava.mp.WxMpAutoConfiguration |
Oops, something went wrong.