提现和支付渠道分离

This commit is contained in:
墨大叔 2024-10-09 14:11:01 +08:00
parent 3bb4f33182
commit 6852d7afeb
6 changed files with 94 additions and 29 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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) {

View File

@ -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:

View File

@ -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: