From 6852d7afeb78177b2e2bd8ee58dae3c75efe7dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com> Date: Wed, 9 Oct 2024 14:11:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E7=8E=B0=E5=92=8C=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=B8=A0=E9=81=93=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => pay/wx}/config/WxPayConfig.java | 21 +------ .../pay/wx/config/WxTransferConfig.java | 58 +++++++++++++++++++ .../common/pay/wx/service/WxPayService.java | 2 +- .../pay/wx/service/WxTransferService.java | 9 +-- .../src/main/resources/application-dev.yml | 17 +++++- .../src/main/resources/application-prod.yml | 16 ++++- 6 files changed, 94 insertions(+), 29 deletions(-) rename smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/{ => pay/wx}/config/WxPayConfig.java (84%) create mode 100644 smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/config/WxTransferConfig.java diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/config/WxPayConfig.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/config/WxPayConfig.java similarity index 84% rename from smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/config/WxPayConfig.java rename to smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/config/WxPayConfig.java index 73e3dcdf..67fb3cf4 100644 --- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/config/WxPayConfig.java +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/config/WxPayConfig.java @@ -1,4 +1,4 @@ -package com.ruoyi.common.config; +package com.ruoyi.common.pay.wx.config; import com.wechat.pay.java.core.Config; import com.wechat.pay.java.core.RSAAutoCertificateConfig; @@ -10,7 +10,6 @@ import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; import com.wechat.pay.java.service.refund.RefundService; import com.wechat.pay.java.service.transferbatch.TransferBatchService; import lombok.Getter; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -52,9 +51,6 @@ public class WxPayConfig { @Value("${wx.pay.merchantSerialNumber}") private String merchantSerialNumber; - @Value("${wx.pay.transferNotifyUrl}") - private String transferNotifyUrl; - @Bean public AppService appService () { // 初始化商户配置 @@ -130,19 +126,4 @@ public class WxPayConfig { return new NotificationParser(config); } - @Bean - public TransferBatchService transferBatchService() { - // 初始化商户配置 - Config config = new RSAAutoCertificateConfig.Builder() - .merchantId(merchantId) - // 使用 com.wechat.pay.java.core.util - // 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 - .privateKeyFromPath(privateKeyPath) - .merchantSerialNumber(merchantSerialNumber) - .apiV3Key(apiV3Key) - .build(); - - // 初始化服务 - return new TransferBatchService.Builder().config(config).build(); - } } diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/config/WxTransferConfig.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/config/WxTransferConfig.java new file mode 100644 index 00000000..35a91da1 --- /dev/null +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/config/WxTransferConfig.java @@ -0,0 +1,58 @@ +package com.ruoyi.common.pay.wx.config; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAAutoCertificateConfig; +import com.wechat.pay.java.service.transferbatch.TransferBatchService; +import lombok.Getter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author wjh + * 2024/10/9 + */ +@Configuration +@Getter +public class WxTransferConfig { + + // 小程序id + @Value("${wx.transfer.appId}") + private String appId; + + // 商户id + @Value("${wx.transfer.merchantId}") + private String merchantId; + + // apiV3私钥 + @Value("${wx.transfer.apiV3Key}") + private String apiV3Key; + + // 私钥证书路径 + @Value("${wx.transfer.privateKeyPath}") + private String privateKeyPath; + + // 证书序列号 + @Value("${wx.transfer.merchantSerialNumber}") + private String merchantSerialNumber; + + // 转账回调地址 + @Value("${wx.transfer.transferNotifyUrl}") + private String transferNotifyUrl; + + @Bean + public TransferBatchService transferBatchService() { + // 初始化商户配置 + Config config = new RSAAutoCertificateConfig.Builder() + .merchantId(merchantId) + // 使用 com.wechat.pay.java.core.util + // 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 + .privateKeyFromPath(privateKeyPath) + .merchantSerialNumber(merchantSerialNumber) + .apiV3Key(apiV3Key) + .build(); + + // 初始化服务 + return new TransferBatchService.Builder().config(config).build(); + } +} diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/service/WxPayService.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/service/WxPayService.java index 97379c76..95c3876c 100644 --- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/service/WxPayService.java +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/service/WxPayService.java @@ -1,7 +1,7 @@ package com.ruoyi.common.pay.wx.service; import com.alibaba.fastjson2.JSON; -import com.ruoyi.common.config.WxPayConfig; +import com.ruoyi.common.pay.wx.config.WxPayConfig; import com.ruoyi.common.pay.wx.domain.*; import com.wechat.pay.java.service.payments.jsapi.JsapiService; import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/service/WxTransferService.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/service/WxTransferService.java index be88d819..0838dbda 100644 --- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/service/WxTransferService.java +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/wx/service/WxTransferService.java @@ -1,7 +1,8 @@ package com.ruoyi.common.pay.wx.service; -import com.ruoyi.common.config.WxPayConfig; +import com.ruoyi.common.pay.wx.config.WxPayConfig; import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.pay.wx.config.WxTransferConfig; import com.ruoyi.common.pay.wx.domain.BatchTransferAble; import com.ruoyi.common.pay.wx.domain.request.MyInitiateBatchTransferRequest; import com.wechat.pay.java.service.transferbatch.TransferBatchService; @@ -17,7 +18,7 @@ import org.springframework.stereotype.Service; public class WxTransferService { @Autowired - private WxPayConfig wxPayConfig; + private WxTransferConfig config; @Autowired private TransferBatchService transferBatchService; @@ -27,14 +28,14 @@ public class WxTransferService { */ public InitiateBatchTransferResponse batchTransfer(BatchTransferAble batchTransferAble) { MyInitiateBatchTransferRequest request = new MyInitiateBatchTransferRequest(); - request.setAppid(wxPayConfig.getAppId()); + request.setAppid(config.getAppId()); request.setOutBatchNo(batchTransferAble.transferOutBatchNo()); request.setBatchName(batchTransferAble.transferBatchName()); request.setBatchRemark(batchTransferAble.transferBatchRemark()); request.setTotalAmount(batchTransferAble.transferTotalAmount()); request.setTotalNum(batchTransferAble.transferDetailList().size()); request.setTransferDetailList(batchTransferAble.transferDetailList()); - request.setNotifyUrl(wxPayConfig.getTransferNotifyUrl()); + request.setNotifyUrl(config.getTransferNotifyUrl()); try { return transferBatchService.initiateBatchTransfer(request); } catch (com.wechat.pay.java.core.exception.ServiceException e) { diff --git a/smart-switch-web/src/main/resources/application-dev.yml b/smart-switch-web/src/main/resources/application-dev.yml index afc3f0b4..dae83776 100644 --- a/smart-switch-web/src/main/resources/application-dev.yml +++ b/smart-switch-web/src/main/resources/application-dev.yml @@ -23,13 +23,26 @@ wx: notifyUrl: http://124.221.246.124:2290/app/pay/notify/wx # 退款通知回调地址 refundNotifyUrl: http://124.221.246.124:2290/app/pay/notify/wx/refund - # 转账回调地址 - transferNotifyUrl: https://kg-dev.chuangtewl.com/dev-api/app/pay/notify/wx/transfer # 密钥所在位置 # privateKeyPath: H:/project/创特/证书/wxpay-kg/apiclient_key.pem privateKeyPath: D:/project/证书/wxpay-kg-q6/apiclient_key.pem # 证书序列号 merchantSerialNumber: 5100BE228C3F865D2B916D052B8E80B212961955 + # 微信转账配置 + transfer: + # 微信小程序id + appId: ${wx.appid} + # 商户id + merchantId: 1676202154 + # apiV3密钥 + apiV3Key: 49819e0f0abdb2df3246f7b27f264d75 + # 密钥所在位置 + # privateKeyPath: H:/project/创特/证书/wxpay-kg/apiclient_key.pem + privateKeyPath: D:/project/证书/wxpay-kg/apiclient_key.pem + # 证书序列号 + merchantSerialNumber: 6AD69237C0F22A9AE51A64F1927E3A0962AC1FB0 + # 转账回调地址 + transferNotifyUrl: http://124.221.246.124:2290/app/pay/notify/wx/transfer # 设备配置 device: diff --git a/smart-switch-web/src/main/resources/application-prod.yml b/smart-switch-web/src/main/resources/application-prod.yml index d01a22d0..b69dc37e 100644 --- a/smart-switch-web/src/main/resources/application-prod.yml +++ b/smart-switch-web/src/main/resources/application-prod.yml @@ -23,12 +23,24 @@ wx: notifyUrl: https://kg.chuangtewl.com/prod-api/app/pay/notify/wx # 退款通知回调地址 refundNotifyUrl: https://kg.chuangtewl.com/prod-api/app/pay/notify/wx/refund - # 转账回调地址 - transferNotifyUrl: https://kg.chuangtewl.com/prod-api/app/pay/notify/wx/transfer # 密钥所在位置 privateKeyPath: /www/wwwroot/smart-switch/wxpay-kg-q6/apiclient_key.pem # 证书序列号 merchantSerialNumber: 5100BE228C3F865D2B916D052B8E80B212961955 + # 微信转账配置 + transfer: + # 微信小程序id + appId: ${wx.appid} + # 商户id + merchantId: 1676202154 + # apiV3密钥 + apiV3Key: 49819e0f0abdb2df3246f7b27f264d75 + # 密钥所在位置 + privateKeyPath: /www/wwwroot/smart-switch/wxpay/apiclient_key.pem + # 证书序列号 + merchantSerialNumber: 6AD69237C0F22A9AE51A64F1927E3A0962AC1FB0 + # 转账回调地址 + transferNotifyUrl: https://kg.chuangtewl.com/prod-api/app/pay/notify/wx/transfer # 设备配置 device: