Skip to content

Commit 3c099f8

Browse files
committed
#1082 增加微信小程序模块的spring-boot-starter
1 parent 23ab472 commit 3c099f8

File tree

7 files changed

+190
-5
lines changed

7 files changed

+190
-5
lines changed

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@
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>
108+
<module>spring-boot-starters/wx-java-pay-spring-boot-starter</module>
109+
<module>spring-boot-starters/wx-java-mp-spring-boot-starter</module>
110+
<module>spring-boot-starters/wx-java-miniapp-spring-boot-starter</module>
110111
<!--module>weixin-java-osgi</module-->
111112
</modules>
112113

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 使用说明
2+
1. 在自己的Spring Boot项目里,引入maven依赖
3+
```xml
4+
<dependency>
5+
<groupId>com.github.binarywang</groupId>
6+
<artifactId>wx-java-miniapp-spring-boot-starter</artifactId>
7+
<version>${version}</version>
8+
</dependency>
9+
```
10+
2. 添加配置(application.yml)
11+
```yml
12+
wx:
13+
miniapp:
14+
appid: 111
15+
secret: 111
16+
token: 111
17+
aesKey: 111
18+
msgDataFormat: JSON
19+
```
20+
21+
22+
23+
24+
25+
26+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
<parent>
6+
<artifactId>wx-java</artifactId>
7+
<groupId>com.github.binarywang</groupId>
8+
<version>3.4.9.B</version>
9+
<relativePath>../../</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>wx-java-miniapp-spring-boot-starter</artifactId>
14+
<name>WxJava - Spring Boot Starter for MiniApp</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>org.projectlombok</groupId>
35+
<artifactId>lombok</artifactId>
36+
<scope>provided</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.github.binarywang</groupId>
40+
<artifactId>weixin-java-miniapp</artifactId>
41+
<version>${project.version}</version>
42+
</dependency>
43+
</dependencies>
44+
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-maven-plugin</artifactId>
50+
<version>${spring.boot.version}</version>
51+
</plugin>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-source-plugin</artifactId>
55+
<version>2.2.1</version>
56+
<executions>
57+
<execution>
58+
<id>attach-sources</id>
59+
<goals>
60+
<goal>jar-no-fork</goal>
61+
</goals>
62+
</execution>
63+
</executions>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
68+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.binarywang.spring.starter.wxjava.miniapp.config;
2+
3+
import cn.binarywang.wx.miniapp.api.WxMaService;
4+
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
5+
import cn.binarywang.wx.miniapp.config.WxMaConfig;
6+
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
7+
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
8+
import lombok.AllArgsConstructor;
9+
import org.apache.commons.lang3.StringUtils;
10+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
11+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
12+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
13+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
14+
import org.springframework.context.annotation.Bean;
15+
import org.springframework.context.annotation.Configuration;
16+
17+
/**
18+
* 自动配置.
19+
*
20+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
21+
* @date 2019-08-10
22+
*/
23+
@AllArgsConstructor
24+
@Configuration
25+
@ConditionalOnClass(WxMaService.class)
26+
@EnableConfigurationProperties(WxMaProperties.class)
27+
@ConditionalOnProperty(prefix = "wx.miniapp", value = "enabled", matchIfMissing = true)
28+
public class WxMaAutoConfiguration {
29+
private WxMaProperties properties;
30+
31+
/**
32+
* 小程序service.
33+
*
34+
* @return 小程序service
35+
*/
36+
@Bean
37+
@ConditionalOnMissingBean(WxMaService.class)
38+
public WxMaService service() {
39+
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
40+
config.setAppid(StringUtils.trimToNull(this.properties.getAppid()));
41+
config.setSecret(StringUtils.trimToNull(this.properties.getSecret()));
42+
config.setToken(StringUtils.trimToNull(this.properties.getToken()));
43+
config.setAesKey(StringUtils.trimToNull(this.properties.getAesKey()));
44+
config.setMsgDataFormat(StringUtils.trimToNull(this.properties.getMsgDataFormat()));
45+
46+
final WxMaServiceImpl service = new WxMaServiceImpl();
47+
service.setWxMaConfig(config);
48+
return service;
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.binarywang.spring.starter.wxjava.miniapp.properties;
2+
3+
import lombok.Data;
4+
import org.springframework.boot.context.properties.ConfigurationProperties;
5+
6+
/**
7+
* 属性配置类.
8+
*
9+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
10+
* @date 2019-08-10
11+
*/
12+
@Data
13+
@ConfigurationProperties(prefix = "wx.miniapp")
14+
public class WxMaProperties {
15+
/**
16+
* 设置微信小程序的appid.
17+
*/
18+
private String appid;
19+
20+
/**
21+
* 设置微信小程序的Secret.
22+
*/
23+
private String secret;
24+
25+
/**
26+
* 设置微信小程序消息服务器配置的token.
27+
*/
28+
private String token;
29+
30+
/**
31+
* 设置微信小程序消息服务器配置的EncodingAESKey.
32+
*/
33+
private String aesKey;
34+
35+
/**
36+
* 消息格式,XML或者JSON.
37+
*/
38+
private String msgDataFormat;
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.binarywang.spring.starter.wxjava.miniapp.config.WxMaAutoConfiguration

spring-boot-starters/wx-java-pay-spring-boot-starter/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
```yml
1212
wx:
1313
pay:
14-
appId: wx5b69c56ac01ed858
15-
mchId: 1462547202
16-
mchKey: OGL9fvig9y2HrXrQ86tM4jTwyv4ja6G5
14+
appId:
15+
mchId:
16+
mchKey:
1717
subAppId:
1818
subMchId:
1919
keyPath:

0 commit comments

Comments
 (0)