Skip to content

Commit

Permalink
Merge pull request Wechat-Group#1151 from Wechat-Group/develop
Browse files Browse the repository at this point in the history
合并 Develop 分支
  • Loading branch information
binarywang committed Aug 10, 2019
2 parents 5570cba + 3bf1bb9 commit 476b067
Show file tree
Hide file tree
Showing 237 changed files with 6,661 additions and 2,043 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ language: java
# secure: "834110c7191f97ecb226970c46dcaff8e681da5a"

jdk:
- oraclejdk8
- openjdk8
script: "mvn clean package -DskipTests=true -Dcheckstyle.skip=true"

#script:
Expand Down
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

10 changes: 6 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.binarywang</groupId>
<artifactId>wx-java</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>
<packaging>pom</packaging>
<name>WxJava - Weixin/Wechat Java SDK</name>
<description>微信开发Java SDK</description>
Expand Down 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 Expand Up @@ -246,7 +247,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -370,6 +371,7 @@
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<skip>true</skip>
<configLocation>quality-checks/google_checks.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<consoleOutput>true</consoleOutput>
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.5.0</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 @@ -4,7 +4,7 @@
```xml
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>wx-java-mp-starter</artifactId>
<artifactId>wx-java-mp-spring-boot-starter</artifactId>
<version>${version}</version>
</dependency>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<parent>
<groupId>com.github.binarywang</groupId>
<artifactId>wx-java</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>
<relativePath>../../</relativePath>
</parent>

<artifactId>wx-java-mp-starter</artifactId>
<artifactId>wx-java-mp-spring-boot-starter</artifactId>
<name>WxJava - Spring Boot Starter for MP</name>
<description>微信公众号开发的Spring Boot Starter</description>
<description>微信公众号开发的 Spring Boot Starter</description>

<properties>
<spring.boot.version>2.1.4.RELEASE</spring.boot.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.binarywang.spring.starter.wxjava.mp;
package com.binarywang.spring.starter.wxjava.mp.config;

import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
* .
*
* @author someone
*/
@Configuration
@EnableConfigurationProperties(WxMpProperties.class)
@Import({WxMpStorageAutoConfiguration.class, WxMpServiceAutoConfiguration.class})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.binarywang.spring.starter.wxjava.mp.config;

import me.chanjar.weixin.mp.config.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;

/**
* 微信公众号相关服务自动注册.
*
* @author someone
*/
@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;
}

}
Loading

0 comments on commit 476b067

Please sign in to comment.