Skip to content

Commit

Permalink
#1082 增加微信小程序模块的spring-boot-starter
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Aug 10, 2019
1 parent 23ab472 commit 3c099f8
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@
<module>weixin-java-pay</module>
<module>weixin-java-miniapp</module>
<module>weixin-java-open</module>
<module>starters/wx-java-pay-starter</module>
<module>starters/wx-java-mp-starter</module>
<module>spring-boot-starters/wx-java-pay-spring-boot-starter</module>
<module>spring-boot-starters/wx-java-mp-spring-boot-starter</module>
<module>spring-boot-starters/wx-java-miniapp-spring-boot-starter</module>
<!--module>weixin-java-osgi</module-->
</modules>

Expand Down
26 changes: 26 additions & 0 deletions spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 使用说明
1. 在自己的Spring Boot项目里,引入maven依赖
```xml
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>wx-java-miniapp-spring-boot-starter</artifactId>
<version>${version}</version>
</dependency>
```
2. 添加配置(application.yml)
```yml
wx:
miniapp:
appid: 111
secret: 111
token: 111
aesKey: 111
msgDataFormat: JSON
```
68 changes: 68 additions & 0 deletions spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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">
<parent>
<artifactId>wx-java</artifactId>
<groupId>com.github.binarywang</groupId>
<version>3.4.9.B</version>
<relativePath>../../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>wx-java-miniapp-spring-boot-starter</artifactId>
<name>WxJava - Spring Boot Starter for MiniApp</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>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<version>${project.version}</version>
</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.binarywang.spring.starter.wxjava.miniapp.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* 自动配置.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2019-08-10
*/
@AllArgsConstructor
@Configuration
@ConditionalOnClass(WxMaService.class)
@EnableConfigurationProperties(WxMaProperties.class)
@ConditionalOnProperty(prefix = "wx.miniapp", value = "enabled", matchIfMissing = true)
public class WxMaAutoConfiguration {
private WxMaProperties properties;

/**
* 小程序service.
*
* @return 小程序service
*/
@Bean
@ConditionalOnMissingBean(WxMaService.class)
public WxMaService service() {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(StringUtils.trimToNull(this.properties.getAppid()));
config.setSecret(StringUtils.trimToNull(this.properties.getSecret()));
config.setToken(StringUtils.trimToNull(this.properties.getToken()));
config.setAesKey(StringUtils.trimToNull(this.properties.getAesKey()));
config.setMsgDataFormat(StringUtils.trimToNull(this.properties.getMsgDataFormat()));

final WxMaServiceImpl service = new WxMaServiceImpl();
service.setWxMaConfig(config);
return service;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.binarywang.spring.starter.wxjava.miniapp.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* 属性配置类.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2019-08-10
*/
@Data
@ConfigurationProperties(prefix = "wx.miniapp")
public class WxMaProperties {
/**
* 设置微信小程序的appid.
*/
private String appid;

/**
* 设置微信小程序的Secret.
*/
private String secret;

/**
* 设置微信小程序消息服务器配置的token.
*/
private String token;

/**
* 设置微信小程序消息服务器配置的EncodingAESKey.
*/
private String aesKey;

/**
* 消息格式,XML或者JSON.
*/
private String msgDataFormat;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.binarywang.spring.starter.wxjava.miniapp.config.WxMaAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
```yml
wx:
pay:
appId: wx5b69c56ac01ed858
mchId: 1462547202
mchKey: OGL9fvig9y2HrXrQ86tM4jTwyv4ja6G5
appId:
mchId:
mchKey:
subAppId:
subMchId:
keyPath:
Expand Down

0 comments on commit 3c099f8

Please sign in to comment.