From 3c099f8d8dcda159346e926ee7d32a4e946b0d05 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sat, 10 Aug 2019 18:43:05 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20#1082=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84spring-boot-starter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 +- .../README.md | 26 +++++++ .../pom.xml | 68 +++++++++++++++++++ .../miniapp/config/WxMaAutoConfiguration.java | 50 ++++++++++++++ .../miniapp/properties/WxMaProperties.java | 39 +++++++++++ .../main/resources/META-INF/spring.factories | 1 + .../wx-java-pay-spring-boot-starter/README.md | 6 +- 7 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md create mode 100644 spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml create mode 100644 spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java create mode 100644 spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java create mode 100644 spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/resources/META-INF/spring.factories diff --git a/pom.xml b/pom.xml index 35b0be5125..b310bd9c91 100644 --- a/pom.xml +++ b/pom.xml @@ -105,8 +105,9 @@ weixin-java-pay weixin-java-miniapp weixin-java-open - starters/wx-java-pay-starter - starters/wx-java-mp-starter + spring-boot-starters/wx-java-pay-spring-boot-starter + spring-boot-starters/wx-java-mp-spring-boot-starter + spring-boot-starters/wx-java-miniapp-spring-boot-starter diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md new file mode 100644 index 0000000000..fe75ef4e3e --- /dev/null +++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md @@ -0,0 +1,26 @@ +# 使用说明 +1. 在自己的Spring Boot项目里,引入maven依赖 +```xml + + com.github.binarywang + wx-java-miniapp-spring-boot-starter + ${version} + + ``` +2. 添加配置(application.yml) +```yml +wx: + miniapp: + appid: 111 + secret: 111 + token: 111 + aesKey: 111 + msgDataFormat: JSON +``` + + + + + + + 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 new file mode 100644 index 0000000000..6ee7329082 --- /dev/null +++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml @@ -0,0 +1,68 @@ + + + + wx-java + com.github.binarywang + 3.4.9.B + ../../ + + 4.0.0 + + wx-java-miniapp-spring-boot-starter + WxJava - Spring Boot Starter for MiniApp + 微信小程序开发的 Spring Boot Starter + + + 2.1.4.RELEASE + + + + + org.springframework.boot + spring-boot-autoconfigure + ${spring.boot.version} + + + org.springframework.boot + spring-boot-configuration-processor + ${spring.boot.version} + true + + + org.projectlombok + lombok + provided + + + com.github.binarywang + weixin-java-miniapp + ${project.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + + diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java new file mode 100644 index 0000000000..109b398d13 --- /dev/null +++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java @@ -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 Binary Wang + * @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; + } +} diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java new file mode 100644 index 0000000000..6477e61fa2 --- /dev/null +++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java @@ -0,0 +1,39 @@ +package com.binarywang.spring.starter.wxjava.miniapp.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * 属性配置类. + * + * @author Binary Wang + * @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; +} diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/resources/META-INF/spring.factories b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..4bb1c3d604 --- /dev/null +++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.binarywang.spring.starter.wxjava.miniapp.config.WxMaAutoConfiguration diff --git a/spring-boot-starters/wx-java-pay-spring-boot-starter/README.md b/spring-boot-starters/wx-java-pay-spring-boot-starter/README.md index 51a363644e..a4d91fade0 100644 --- a/spring-boot-starters/wx-java-pay-spring-boot-starter/README.md +++ b/spring-boot-starters/wx-java-pay-spring-boot-starter/README.md @@ -11,9 +11,9 @@ ```yml wx: pay: - appId: wx5b69c56ac01ed858 - mchId: 1462547202 - mchKey: OGL9fvig9y2HrXrQ86tM4jTwyv4ja6G5 + appId: + mchId: + mchKey: subAppId: subMchId: keyPath: