From aba1e755f98bc6c89caabe590850161b903db420 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Fri, 12 May 2023 11:34:26 +0800
Subject: [PATCH] 支付设置

---
 src/main/java/cc/mrbird/febs/pay/service/impl/WxPayServiceImpl.java    |    4 +++-
 src/main/java/cc/mrbird/febs/pay/configure/WxPayConfiguration.java     |   42 ++++++++++++++++++++++++++++++++++++++++++
 src/main/resources/application-dev.yml                                 |    8 ++++++++
 src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java |    4 +++-
 4 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/pay/configure/WxPayConfiguration.java b/src/main/java/cc/mrbird/febs/pay/configure/WxPayConfiguration.java
new file mode 100644
index 0000000..30cd9ce
--- /dev/null
+++ b/src/main/java/cc/mrbird/febs/pay/configure/WxPayConfiguration.java
@@ -0,0 +1,42 @@
+package cc.mrbird.febs.pay.configure;
+
+import cc.mrbird.febs.pay.properties.WxPayProperties;
+import cn.hutool.core.util.StrUtil;
+import com.github.binarywang.wxpay.config.WxPayConfig;
+import com.github.binarywang.wxpay.service.WxPayService;
+import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
+import lombok.AllArgsConstructor;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author wzy
+ * @date 2023-04-07
+ **/
+@Configuration
+@ConditionalOnClass(WxPayService.class)
+@EnableConfigurationProperties(WxPayProperties.class)
+@AllArgsConstructor
+public class WxPayConfiguration {
+    private WxPayProperties properties;
+
+    @Bean
+    @ConditionalOnMissingBean
+    public WxPayService wxService() {
+        WxPayConfig payConfig = new WxPayConfig();
+        payConfig.setAppId(StrUtil.trim(this.properties.getAppId()));
+        payConfig.setMchId(StrUtil.trim(this.properties.getMchId()));
+        payConfig.setMchKey(StrUtil.trim(this.properties.getMchKey()));
+        payConfig.setKeyPath(StrUtil.trim(this.properties.getKeyPath()));
+
+        // 可以指定是否使用沙箱环境
+        payConfig.setUseSandboxEnv(false);
+
+        WxPayService wxPayService = new WxPayServiceImpl();
+        wxPayService.setConfig(payConfig);
+        return wxPayService;
+    }
+}
diff --git a/src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java b/src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java
index b490620..a3e1bc2 100644
--- a/src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java
+++ b/src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java
@@ -36,7 +36,9 @@
     @Resource
     private AliPayProperties aliPayProperties;
 
-    private WxPayService wxPayService = new com.github.binarywang.wxpay.service.impl.WxPayServiceImpl();
+    @Autowired
+    private WxPayService wxPayService;
+//    private WxPayService wxPayService = new com.github.binarywang.wxpay.service.impl.WxPayServiceImpl();
 
     @Autowired
     private IPayService wechatPayService;
diff --git a/src/main/java/cc/mrbird/febs/pay/service/impl/WxPayServiceImpl.java b/src/main/java/cc/mrbird/febs/pay/service/impl/WxPayServiceImpl.java
index 9e4e884..a86f486 100644
--- a/src/main/java/cc/mrbird/febs/pay/service/impl/WxPayServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/pay/service/impl/WxPayServiceImpl.java
@@ -53,7 +53,9 @@
     @Autowired
     private MallOrderInfoMapper orderInfoMapper;
 
-    private WxPayService wxPayService = new com.github.binarywang.wxpay.service.impl.WxPayServiceImpl();
+    @Autowired
+    private WxPayService wxPayService;
+//    private WxPayService wxPayService = new com.github.binarywang.wxpay.service.impl.WxPayServiceImpl();
 
     @Autowired
     private WxPayProperties wxPayProperties;
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
index dcb37b7..954e7e8 100644
--- a/src/main/resources/application-dev.yml
+++ b/src/main/resources/application-dev.yml
@@ -62,3 +62,11 @@
     # 回调地址
     noticeUrl: http://120.27.238.55:8801/api/pay/aliCallBack
     domain: https://openapi.alipaydev.com/gateway.do
+
+
+  wx:
+    appId: wxdf3340fe7591375d
+    mchId: 1644265360
+    mchKey: wqri51aCfiG31o4IcdX3dW12qnX3u4hp
+    keyPath: classpath:cert/apiclient_cert.p12
+    noticeUrl: https://gzypapi.meiao.biz/api/pay/wxPayCallBack

--
Gitblit v1.9.1