diff --git a/pom.xml b/pom.xml index 35b0be51..b310bd9c 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 00000000..fe75ef4e --- /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 00000000..6ee73290 --- /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 00000000..109b398d --- /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 00000000..6477e61f --- /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 00000000..4bb1c3d6 --- /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 51a36364..a4d91fad 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: