diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml
index c7b0e9dc7..15bf2a83a 100644
--- a/yudao-dependencies/pom.xml
+++ b/yudao-dependencies/pom.xml
@@ -70,7 +70,7 @@
+ * 微信支付自动配置 + * Created by BinaryWang on 2019/4/17. + *+ * + * @author Binary Wang + */ +@Configuration +@EnableConfigurationProperties(WxPayProperties.class) +@ConditionalOnClass(WxPayService.class) +@ConditionalOnProperty(prefix = "wx.pay.one", value = "enabled", matchIfMissing = true) +public class WxPayOneAutoConfiguration { + private WxPayProperties properties; + + @Autowired + public WxPayOneAutoConfiguration(WxPayProperties properties) { + this.properties = properties; + } + + /** + * 构造微信支付服务对象. + * + * @return 微信支付service + */ + @Bean + @ConditionalOnMissingBean(WxPayService.class) + public WxPayService wxPayOneService() { + 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())); + payConfig.setNotifyUrl(StringUtils.trimToNull(this.properties.getNotifyUrl())); + //以下是apiv3以及支付分相关 + payConfig.setServiceId(StringUtils.trimToNull(this.properties.getServiceId())); + payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.properties.getPayScoreNotifyUrl())); + payConfig.setPrivateKeyPath(StringUtils.trimToNull(this.properties.getPrivateKeyPath())); + payConfig.setPrivateCertPath(StringUtils.trimToNull(this.properties.getPrivateCertPath())); + payConfig.setCertSerialNo(StringUtils.trimToNull(this.properties.getCertSerialNo())); + payConfig.setApiV3Key(StringUtils.trimToNull(this.properties.getApiv3Key())); + wxPayService.setConfig(payConfig); + return wxPayService; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/config/WxPayTwoAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/config/WxPayTwoAutoConfiguration.java new file mode 100644 index 000000000..b1437bec8 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/config/WxPayTwoAutoConfiguration.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.framework.pay.config; + +import cn.iocoder.yudao.framework.pay.properties.WxPayTwoProperties; +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; + +/** + *
+ * 微信支付自动配置 + * Created by BinaryWang on 2019/4/17. + *+ * + * @author Binary Wang + */ +@Configuration +@EnableConfigurationProperties(WxPayTwoProperties.class) +@ConditionalOnClass(WxPayService.class) +@ConditionalOnProperty(prefix = "wx.pay.two", value = "enabled", matchIfMissing = true) +public class WxPayTwoAutoConfiguration { + + private WxPayTwoProperties wxPayTwoProperties; + + @Autowired + public WxPayTwoAutoConfiguration(WxPayTwoProperties wxPayTwoProperties) { + this.wxPayTwoProperties = wxPayTwoProperties; + } + + /** + * 构造微信支付服务对象. + * + * @return 微信支付service + */ + @Bean + @ConditionalOnMissingBean(WxPayService.class) + public WxPayService wxPayTwoService() { + final WxPayServiceImpl wxPayService = new WxPayServiceImpl(); + WxPayConfig payConfig = new WxPayConfig(); + payConfig.setAppId(StringUtils.trimToNull(this.wxPayTwoProperties.getAppId())); + payConfig.setMchId(StringUtils.trimToNull(this.wxPayTwoProperties.getMchId())); + payConfig.setMchKey(StringUtils.trimToNull(this.wxPayTwoProperties.getMchKey())); + payConfig.setSubAppId(StringUtils.trimToNull(this.wxPayTwoProperties.getSubAppId())); + payConfig.setSubMchId(StringUtils.trimToNull(this.wxPayTwoProperties.getSubMchId())); + payConfig.setKeyPath(StringUtils.trimToNull(this.wxPayTwoProperties.getKeyPath())); + payConfig.setNotifyUrl(StringUtils.trimToNull(this.wxPayTwoProperties.getNotifyUrl())); + //以下是apiv3以及支付分相关 + payConfig.setServiceId(StringUtils.trimToNull(this.wxPayTwoProperties.getServiceId())); + payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.wxPayTwoProperties.getPayScoreNotifyUrl())); + payConfig.setPrivateKeyPath(StringUtils.trimToNull(this.wxPayTwoProperties.getPrivateKeyPath())); + payConfig.setPrivateCertPath(StringUtils.trimToNull(this.wxPayTwoProperties.getPrivateCertPath())); + payConfig.setCertSerialNo(StringUtils.trimToNull(this.wxPayTwoProperties.getCertSerialNo())); + payConfig.setApiV3Key(StringUtils.trimToNull(this.wxPayTwoProperties.getApiv3Key())); + wxPayService.setConfig(payConfig); + return wxPayService; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/properties/WxPayProperties.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/properties/WxPayProperties.java new file mode 100644 index 000000000..6559665fe --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/properties/WxPayProperties.java @@ -0,0 +1,86 @@ +package cn.iocoder.yudao.framework.pay.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + *
+ * 微信支付属性配置类 + * Created by Binary Wang on 2019/4/17. + *+ * + * @author Binary Wang + */ +@Data +@ConfigurationProperties(prefix = "wx.pay.one") +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; + + /** + * 微信支付分serviceId + */ + private String serviceId; + /** + * 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数. + */ + private String notifyUrl; + + /** + * 微信退款异步回掉地址,通知url必须为直接可访问的url,不能携带参数. + */ + private String refundNotifyUrl; + + /** + * 证书序列号 + */ + private String certSerialNo; + + /** + * apiV3秘钥 + */ + private String apiv3Key; + + /** + * 微信支付分回调地址 + */ + private String payScoreNotifyUrl; + + /** + * apiv3 商户apiclient_key.pem + */ + private String privateKeyPath; + + /** + * apiv3 商户apiclient_cert.pem + */ + private String privateCertPath; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/properties/WxPayTwoProperties.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/properties/WxPayTwoProperties.java new file mode 100644 index 000000000..f8c198c7c --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/properties/WxPayTwoProperties.java @@ -0,0 +1,86 @@ +package cn.iocoder.yudao.framework.pay.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + *
+ * 微信支付属性配置类 + * Created by Binary Wang on 2019/4/17. + *+ * + * @author Binary Wang + */ +@Data +@ConfigurationProperties(prefix = "wx.pay.two") +public class WxPayTwoProperties { + /** + * 设置微信公众号或者小程序等的appid. + */ + private String appId; + + /** + * 微信支付商户号. + */ + private String mchId; + + /** + * 微信支付商户密钥. + */ + private String mchKey; + + /** + * 服务商模式下的子商户公众账号ID,普通模式请不要配置,请在配置文件中将对应项删除. + */ + private String subAppId; + + /** + * 服务商模式下的子商户号,普通模式请不要配置,最好是请在配置文件中将对应项删除. + */ + private String subMchId; + + /** + * apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定. + */ + private String keyPath; + + /** + * 微信支付分serviceId + */ + private String serviceId; + /** + * 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数. + */ + private String notifyUrl; + + /** + * 微信退款异步回掉地址,通知url必须为直接可访问的url,不能携带参数. + */ + private String refundNotifyUrl; + + /** + * 证书序列号 + */ + private String certSerialNo; + + /** + * apiV3秘钥 + */ + private String apiv3Key; + + /** + * 微信支付分回调地址 + */ + private String payScoreNotifyUrl; + + /** + * apiv3 商户apiclient_key.pem + */ + private String privateKeyPath; + + /** + * apiv3 商户apiclient_cert.pem + */ + private String privateCertPath; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index f2a8bf146..3a42b1c47 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1,3 @@ -cn.iocoder.yudao.framework.pay.config.YudaoPayAutoConfiguration \ No newline at end of file +cn.iocoder.yudao.framework.pay.config.YudaoPayAutoConfiguration +cn.iocoder.yudao.framework.pay.config.WxPayOneAutoConfiguration +cn.iocoder.yudao.framework.pay.config.WxPayTwoAutoConfiguration \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-shop-biz/pom.xml b/yudao-module-mall/yudao-module-shop-biz/pom.xml index 932b69f99..f96408a10 100644 --- a/yudao-module-mall/yudao-module-shop-biz/pom.xml +++ b/yudao-module-mall/yudao-module-shop-biz/pom.xml @@ -79,5 +79,13 @@