Skip to content

Commit f46187a

Browse files
committed
#1007 增加微信支付的 spring boot starter
1 parent 0133cd0 commit f46187a

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<module>weixin-java-pay</module>
106106
<module>weixin-java-miniapp</module>
107107
<module>weixin-java-open</module>
108+
<module>starters/wx-java-pay-starter</module>
108109
<!--module>weixin-java-osgi</module-->
109110
</modules>
110111

starters/wx-java-pay-starter/pom.xml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>wx-java</artifactId>
7+
<groupId>com.github.binarywang</groupId>
8+
<version>3.3.8.B</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>wx-java-pay-starter</artifactId>
13+
14+
<properties>
15+
<spring.boot.version>2.1.4.RELEASE</spring.boot.version>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-autoconfigure</artifactId>
22+
<version>${spring.boot.version}</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-configuration-processor</artifactId>
27+
<version>${spring.boot.version}</version>
28+
<optional>true</optional>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.projectlombok</groupId>
32+
<artifactId>lombok</artifactId>
33+
<scope>provided</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.github.binarywang</groupId>
37+
<artifactId>weixin-java-pay</artifactId>
38+
<version>${project.version}</version>
39+
</dependency>
40+
</dependencies>
41+
42+
<build>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-maven-plugin</artifactId>
47+
<version>${spring.boot.version}</version>
48+
</plugin>
49+
<plugin>
50+
<groupId>org.apache.maven.plugins</groupId>
51+
<artifactId>maven-source-plugin</artifactId>
52+
<version>2.2.1</version>
53+
<executions>
54+
<execution>
55+
<id>attach-sources</id>
56+
<goals>
57+
<goal>jar-no-fork</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
65+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.binarywang.spring.starter.wxjava.pay.config;
2+
3+
import com.binarywang.spring.starter.wxjava.pay.properties.WxPayProperties;
4+
import com.github.binarywang.wxpay.config.WxPayConfig;
5+
import com.github.binarywang.wxpay.service.WxPayService;
6+
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
7+
import org.apache.commons.lang3.StringUtils;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
10+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
11+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
12+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
13+
import org.springframework.context.annotation.Bean;
14+
import org.springframework.context.annotation.Configuration;
15+
16+
/**
17+
* <pre>
18+
* 微信支付自动配置
19+
* Created by BinaryWang on 2019/4/17.
20+
* </pre>
21+
*
22+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
23+
*/
24+
@Configuration
25+
@EnableConfigurationProperties(WxPayProperties.class)
26+
@ConditionalOnClass(WxPayService.class)
27+
@ConditionalOnProperty(prefix = "wx.pay", value = "enabled", matchIfMissing = true)
28+
public class WxPayAutoConfiguration {
29+
private WxPayProperties properties;
30+
31+
@Autowired
32+
public WxPayAutoConfiguration(WxPayProperties properties) {
33+
this.properties = properties;
34+
}
35+
36+
/**
37+
* 构造微信支付服务对象.
38+
*
39+
* @return 微信支付service
40+
*/
41+
@Bean
42+
@ConditionalOnMissingBean(WxPayService.class)
43+
public WxPayService wxPayService() {
44+
final WxPayServiceImpl wxPayService = new WxPayServiceImpl();
45+
WxPayConfig payConfig = new WxPayConfig();
46+
payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId()));
47+
payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId()));
48+
payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey()));
49+
payConfig.setSubAppId(StringUtils.trimToNull(this.properties.getSubAppId()));
50+
payConfig.setSubMchId(StringUtils.trimToNull(this.properties.getSubMchId()));
51+
payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
52+
53+
wxPayService.setConfig(payConfig);
54+
return wxPayService;
55+
}
56+
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.binarywang.spring.starter.wxjava.pay.properties;
2+
3+
import lombok.Data;
4+
import org.springframework.boot.context.properties.ConfigurationProperties;
5+
6+
/**
7+
* <pre>
8+
* 微信支付属性配置类
9+
* Created by Binary Wang on 2019/4/17.
10+
* </pre>
11+
*
12+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
13+
*/
14+
@Data
15+
@ConfigurationProperties(prefix = "wx.pay")
16+
public class WxPayProperties {
17+
/**
18+
* 设置微信公众号或者小程序等的appid.
19+
*/
20+
private String appId;
21+
22+
/**
23+
* 微信支付商户号.
24+
*/
25+
private String mchId;
26+
27+
/**
28+
* 微信支付商户密钥.
29+
*/
30+
private String mchKey;
31+
32+
/**
33+
* 服务商模式下的子商户公众账号ID,普通模式请不要配置,请在配置文件中将对应项删除.
34+
*/
35+
private String subAppId;
36+
37+
/**
38+
* 服务商模式下的子商户号,普通模式请不要配置,最好是请在配置文件中将对应项删除.
39+
*/
40+
private String subMchId;
41+
42+
/**
43+
* apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定.
44+
*/
45+
private String keyPath;
46+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.binarywang.spring.starter.wxjava.pay.config.WxPayAutoConfiguration

0 commit comments

Comments
 (0)