| @@ -105,6 +105,7 @@ | |||
| <module>weixin-java-pay</module> | |||
| <module>weixin-java-miniapp</module> | |||
| <module>weixin-java-open</module> | |||
| <module>starters/wx-java-pay-starter</module> | |||
| <!--module>weixin-java-osgi</module--> | |||
| </modules> | |||
| @@ -0,0 +1,65 @@ | |||
| <?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.3.8.B</version> | |||
| </parent> | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <artifactId>wx-java-pay-starter</artifactId> | |||
| <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-pay</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> | |||
| @@ -0,0 +1,57 @@ | |||
| package com.binarywang.spring.starter.wxjava.pay.config; | |||
| import com.binarywang.spring.starter.wxjava.pay.properties.WxPayProperties; | |||
| import com.github.binarywang.wxpay.config.WxPayConfig; | |||
| import com.github.binarywang.wxpay.service.WxPayService; | |||
| import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| 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; | |||
| /** | |||
| * <pre> | |||
| * 微信支付自动配置 | |||
| * Created by BinaryWang on 2019/4/17. | |||
| * </pre> | |||
| * | |||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
| */ | |||
| @Configuration | |||
| @EnableConfigurationProperties(WxPayProperties.class) | |||
| @ConditionalOnClass(WxPayService.class) | |||
| @ConditionalOnProperty(prefix = "wx.pay", value = "enabled", matchIfMissing = true) | |||
| public class WxPayAutoConfiguration { | |||
| private WxPayProperties properties; | |||
| @Autowired | |||
| public WxPayAutoConfiguration(WxPayProperties properties) { | |||
| this.properties = properties; | |||
| } | |||
| /** | |||
| * 构造微信支付服务对象. | |||
| * | |||
| * @return 微信支付service | |||
| */ | |||
| @Bean | |||
| @ConditionalOnMissingBean(WxPayService.class) | |||
| public WxPayService wxPayService() { | |||
| final WxPayServiceImpl wxPayService = new WxPayServiceImpl(); | |||
| WxPayConfig payConfig = new WxPayConfig(); | |||
| payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId())); | |||
| payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId())); | |||
| payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey())); | |||
| payConfig.setSubAppId(StringUtils.trimToNull(this.properties.getSubAppId())); | |||
| payConfig.setSubMchId(StringUtils.trimToNull(this.properties.getSubMchId())); | |||
| payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath())); | |||
| wxPayService.setConfig(payConfig); | |||
| return wxPayService; | |||
| } | |||
| } | |||
| @@ -0,0 +1,46 @@ | |||
| package com.binarywang.spring.starter.wxjava.pay.properties; | |||
| import lombok.Data; | |||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||
| /** | |||
| * <pre> | |||
| * 微信支付属性配置类 | |||
| * Created by Binary Wang on 2019/4/17. | |||
| * </pre> | |||
| * | |||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
| */ | |||
| @Data | |||
| @ConfigurationProperties(prefix = "wx.pay") | |||
| public class WxPayProperties { | |||
| /** | |||
| * 设置微信公众号或者小程序等的appid. | |||
| */ | |||
| private String appId; | |||
| /** | |||
| * 微信支付商户号. | |||
| */ | |||
| private String mchId; | |||
| /** | |||
| * 微信支付商户密钥. | |||
| */ | |||
| private String mchKey; | |||
| /** | |||
| * 服务商模式下的子商户公众账号ID,普通模式请不要配置,请在配置文件中将对应项删除. | |||
| */ | |||
| private String subAppId; | |||
| /** | |||
| * 服务商模式下的子商户号,普通模式请不要配置,最好是请在配置文件中将对应项删除. | |||
| */ | |||
| private String subMchId; | |||
| /** | |||
| * apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定. | |||
| */ | |||
| private String keyPath; | |||
| } | |||
| @@ -0,0 +1 @@ | |||
| org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.binarywang.spring.starter.wxjava.pay.config.WxPayAutoConfiguration | |||