fix:支付通用模块功能逻辑完善,订单模块动态引入逻辑调整
This commit is contained in:
+2
-4
@@ -4,20 +4,18 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
|
|||||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
@Configuration
|
//@Configuration
|
||||||
@RequiredArgsConstructor
|
//@RequiredArgsConstructor
|
||||||
public class WxMpConfiguration {
|
public class WxMpConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
+12
-10
@@ -9,7 +9,6 @@ import com.central.common.model.PageResult;
|
|||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import com.central.common.model.SysUser;
|
import com.central.common.model.SysUser;
|
||||||
import com.central.log.annotation.AuditLog;
|
import com.central.log.annotation.AuditLog;
|
||||||
import com.central.order.config.TencentPayProperties;
|
|
||||||
import com.central.order.enums.CommonStatus;
|
import com.central.order.enums.CommonStatus;
|
||||||
import com.central.order.enums.OrderStatus;
|
import com.central.order.enums.OrderStatus;
|
||||||
import com.central.order.feign.DeviceCenterService;
|
import com.central.order.feign.DeviceCenterService;
|
||||||
@@ -17,7 +16,9 @@ import com.central.order.feign.FileCenterService;
|
|||||||
import com.central.order.feign.UserCenterService;
|
import com.central.order.feign.UserCenterService;
|
||||||
import com.central.order.model.*;
|
import com.central.order.model.*;
|
||||||
import com.central.order.service.*;
|
import com.central.order.service.*;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
import com.central.wechat.config.WxPayConfigFactory;
|
||||||
|
import com.central.wechat.entity.WechatConfig;
|
||||||
|
import com.central.wechat.feign.WechatConfigService;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.*;
|
import com.wechat.pay.java.service.payments.jsapi.model.*;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@@ -71,14 +72,11 @@ public class OrderController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private FileCenterService fileCenterService;
|
private FileCenterService fileCenterService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JsapiServiceExtension service;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IQrCodeService qrCodeService;
|
private IQrCodeService qrCodeService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TencentPayProperties tencentPayProperties;
|
private WechatConfigService wechatConfigService;
|
||||||
|
|
||||||
@Value("${file.oss-url}")
|
@Value("${file.oss-url}")
|
||||||
private String cdnOssUrl;
|
private String cdnOssUrl;
|
||||||
@@ -97,6 +95,9 @@ public class OrderController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IProfitSharingService profitSharingService;
|
private IProfitSharingService profitSharingService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WxPayConfigFactory wxPayConfigFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表
|
* 列表
|
||||||
*/
|
*/
|
||||||
@@ -247,15 +248,16 @@ public class OrderController {
|
|||||||
|
|
||||||
// 3. 创建支付请求
|
// 3. 创建支付请求
|
||||||
PrepayRequest request = new PrepayRequest();
|
PrepayRequest request = new PrepayRequest();
|
||||||
|
WechatConfig wechatConfig = wechatConfigService.getConfig("PAY",qrCode.getTenantId());
|
||||||
|
|
||||||
// 设置基本支付信息
|
// 设置基本支付信息
|
||||||
Amount amount = new Amount();
|
Amount amount = new Amount();
|
||||||
amount.setTotal(Integer.parseInt(order.getOrderAmount()));
|
amount.setTotal(Integer.parseInt(order.getOrderAmount()));
|
||||||
request.setAmount(amount);
|
request.setAmount(amount);
|
||||||
request.setAppid(tencentPayProperties.getAppId());
|
request.setAppid(wechatConfig.getAppId());
|
||||||
request.setMchid(tencentPayProperties.getMerchantId());
|
request.setMchid(wechatConfig.getMerchantId());
|
||||||
request.setDescription(order.getOrderNo());
|
request.setDescription(order.getOrderNo());
|
||||||
request.setNotifyUrl(tencentPayProperties.getNotifyUrl());
|
request.setNotifyUrl(wechatConfig.getNotifyUrl());
|
||||||
request.setOutTradeNo(order.getOrderNo());
|
request.setOutTradeNo(order.getOrderNo());
|
||||||
|
|
||||||
// 设置支付者信息
|
// 设置支付者信息
|
||||||
@@ -277,7 +279,7 @@ public class OrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 5. 调用支付接口
|
// 5. 调用支付接口
|
||||||
PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);
|
PrepayWithRequestPaymentResponse response = wxPayConfigFactory.createJsapiService(qrCode.getTenantId()).prepayWithRequestPayment(request);
|
||||||
|
|
||||||
// 6. 返回结果
|
// 6. 返回结果
|
||||||
return Result.succeed(response, order.getOrderNo());
|
return Result.succeed(response, order.getOrderNo());
|
||||||
|
|||||||
+3
-3
@@ -7,7 +7,7 @@ import com.central.order.enums.RefundState;
|
|||||||
import com.central.order.model.Order;
|
import com.central.order.model.Order;
|
||||||
import com.central.order.service.IOrderService;
|
import com.central.order.service.IOrderService;
|
||||||
import com.central.order.service.IRefundService;
|
import com.central.order.service.IRefundService;
|
||||||
import com.wechat.pay.java.service.refund.RefundService;
|
import com.central.wechat.config.WxPayConfigFactory;
|
||||||
import com.wechat.pay.java.service.refund.model.AmountReq;
|
import com.wechat.pay.java.service.refund.model.AmountReq;
|
||||||
import com.wechat.pay.java.service.refund.model.CreateRequest;
|
import com.wechat.pay.java.service.refund.model.CreateRequest;
|
||||||
import com.wechat.pay.java.service.refund.model.Refund;
|
import com.wechat.pay.java.service.refund.model.Refund;
|
||||||
@@ -28,7 +28,7 @@ import java.util.Map;
|
|||||||
public class RefundController {
|
public class RefundController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RefundService service;
|
private WxPayConfigFactory wxPayConfigFactory;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IOrderService orderService;
|
private IOrderService orderService;
|
||||||
@@ -135,7 +135,7 @@ public class RefundController {
|
|||||||
request.setAmount(amount);
|
request.setAmount(amount);
|
||||||
|
|
||||||
// 发起退款请求
|
// 发起退款请求
|
||||||
Refund response = service.create(request);
|
Refund response = wxPayConfigFactory.createRefundService(order.getTenantId()).create(request);
|
||||||
Assert.notNull(response, "退款失败");
|
Assert.notNull(response, "退款失败");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 记录异常信息
|
// 记录异常信息
|
||||||
|
|||||||
+5
-5
@@ -10,7 +10,7 @@ import com.central.order.service.IOrderService;
|
|||||||
import com.central.order.service.IProfitSharingService;
|
import com.central.order.service.IProfitSharingService;
|
||||||
import com.central.order.service.IQrCodeService;
|
import com.central.order.service.IQrCodeService;
|
||||||
import com.central.order.service.IRefundService;
|
import com.central.order.service.IRefundService;
|
||||||
import com.wechat.pay.java.core.notification.NotificationConfig;
|
import com.central.wechat.config.WxPayConfigFactory;
|
||||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||||
import com.wechat.pay.java.core.notification.RequestParam;
|
import com.wechat.pay.java.core.notification.RequestParam;
|
||||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
import com.wechat.pay.java.service.payments.model.Transaction;
|
||||||
@@ -45,7 +45,7 @@ public class WxPayController {
|
|||||||
private IProfitSharingService profitSharingService;
|
private IProfitSharingService profitSharingService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private NotificationConfig config;
|
private WxPayConfigFactory wxPayConfigFactory;
|
||||||
|
|
||||||
@PostMapping("/pay/notify")
|
@PostMapping("/pay/notify")
|
||||||
public String handleCallback(@RequestHeader("Wechatpay-Signature") String signature,
|
public String handleCallback(@RequestHeader("Wechatpay-Signature") String signature,
|
||||||
@@ -65,7 +65,7 @@ public class WxPayController {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
NotificationParser notificationParser = new NotificationParser(config);
|
NotificationParser notificationParser = wxPayConfigFactory.createNotificationParser("");
|
||||||
// 解析通知
|
// 解析通知
|
||||||
Transaction transaction = notificationParser.parse(requestParam,Transaction.class);
|
Transaction transaction = notificationParser.parse(requestParam,Transaction.class);
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ public class WxPayController {
|
|||||||
.timestamp(timestamp)
|
.timestamp(timestamp)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
NotificationParser notificationParser = new NotificationParser(config);
|
NotificationParser notificationParser = wxPayConfigFactory.createNotificationParser("");
|
||||||
// 解析通知
|
// 解析通知
|
||||||
RefundNotification notification = notificationParser.parse(requestParam, RefundNotification.class);
|
RefundNotification notification = notificationParser.parse(requestParam, RefundNotification.class);
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ public class WxPayController {
|
|||||||
*/
|
*/
|
||||||
private ProfitSharingNotification parseNotification(RequestParam requestParam) {
|
private ProfitSharingNotification parseNotification(RequestParam requestParam) {
|
||||||
try {
|
try {
|
||||||
NotificationParser parser = new NotificationParser(config);
|
NotificationParser parser = wxPayConfigFactory.createNotificationParser("");
|
||||||
// 解析为Map后转换为ProfitSharingNotification对象
|
// 解析为Map后转换为ProfitSharingNotification对象
|
||||||
Map<String, Object> result = parser.parse(requestParam, Map.class);
|
Map<String, Object> result = parser.parse(requestParam, Map.class);
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package com.central.order.model;
|
package com.central.order.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.central.order.enums.PayeeTypeEnum;
|
import com.central.order.enums.PayeeTypeEnum;
|
||||||
import com.central.order.enums.ProfitSharingStatusEnum;
|
import com.central.order.enums.ProfitSharingStatusEnum;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.hibernate.validator.constraints.Length;
|
import org.hibernate.validator.constraints.Length;
|
||||||
|
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
@@ -116,6 +116,8 @@ public class ProfitSharing {
|
|||||||
@Schema(description = "更新时间")
|
@Schema(description = "更新时间")
|
||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
|
|
||||||
|
private String tenantId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取状态描述
|
* 获取状态描述
|
||||||
*/
|
*/
|
||||||
|
|||||||
+12
-18
@@ -6,7 +6,6 @@ import com.central.common.exception.BusinessException;
|
|||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.common.service.impl.SuperServiceImpl;
|
import com.central.common.service.impl.SuperServiceImpl;
|
||||||
import com.central.order.config.ProfitSharingProperties;
|
import com.central.order.config.ProfitSharingProperties;
|
||||||
import com.central.order.config.TencentPayProperties;
|
|
||||||
import com.central.order.constants.ProfitSharingConstants;
|
import com.central.order.constants.ProfitSharingConstants;
|
||||||
import com.central.order.enums.ProfitSharingStatusEnum;
|
import com.central.order.enums.ProfitSharingStatusEnum;
|
||||||
import com.central.order.mapper.ProfitSharingMapper;
|
import com.central.order.mapper.ProfitSharingMapper;
|
||||||
@@ -17,14 +16,14 @@ import com.central.order.model.QrCode;
|
|||||||
import com.central.order.model.vo.ProfitSharingStatisticsVO;
|
import com.central.order.model.vo.ProfitSharingStatisticsVO;
|
||||||
import com.central.order.service.IProfitSharingService;
|
import com.central.order.service.IProfitSharingService;
|
||||||
import com.central.order.service.IQrCodeService;
|
import com.central.order.service.IQrCodeService;
|
||||||
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
import com.central.wechat.config.WxPayConfigFactory;
|
||||||
|
import com.central.wechat.feign.WechatConfigService;
|
||||||
import com.wechat.pay.java.service.profitsharing.model.*;
|
import com.wechat.pay.java.service.profitsharing.model.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -36,7 +35,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -44,10 +42,10 @@ import java.util.stream.Collectors;
|
|||||||
public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapper, ProfitSharing> implements IProfitSharingService {
|
public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapper, ProfitSharing> implements IProfitSharingService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TencentPayProperties tencentPayProperties;
|
private WechatConfigService wechatConfigService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProfitsharingService profitsharingService;
|
private WxPayConfigFactory wxPayConfigFactory;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IQrCodeService qrCodeService;
|
private IQrCodeService qrCodeService;
|
||||||
@@ -55,12 +53,6 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ProfitSharingProperties profitSharingProperties;
|
private ProfitSharingProperties profitSharingProperties;
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private Executor profitSharingExecutor;
|
|
||||||
|
|
||||||
@Value("${wechat.pay.platform-rate:0.30}")
|
|
||||||
private String platformRate;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProfitSharingMapper profitSharingMapper;
|
private ProfitSharingMapper profitSharingMapper;
|
||||||
|
|
||||||
@@ -97,6 +89,7 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
|||||||
.payeeType(qrCode.getPayeeType())
|
.payeeType(qrCode.getPayeeType())
|
||||||
.codeId(qrCode.getCodeId())
|
.codeId(qrCode.getCodeId())
|
||||||
.status(0)
|
.status(0)
|
||||||
|
.tenantId(qrCode.getTenantId())
|
||||||
.createTime(new Date())
|
.createTime(new Date())
|
||||||
.updateTime(new Date())
|
.updateTime(new Date())
|
||||||
.build();
|
.build();
|
||||||
@@ -177,7 +170,7 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
|||||||
private OrdersEntity executeProfitSharingRequest(ProfitSharing profitSharing) {
|
private OrdersEntity executeProfitSharingRequest(ProfitSharing profitSharing) {
|
||||||
CreateOrderRequest request = buildProfitSharingRequest(profitSharing);
|
CreateOrderRequest request = buildProfitSharingRequest(profitSharing);
|
||||||
try {
|
try {
|
||||||
return profitsharingService.createOrder(request);
|
return wxPayConfigFactory.createProfitsharingService(profitSharing.getTenantId()).createOrder(request);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("调用微信分账接口失败", e);
|
log.error("调用微信分账接口失败", e);
|
||||||
throw new BusinessException("分账请求失败");
|
throw new BusinessException("分账请求失败");
|
||||||
@@ -225,7 +218,7 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
|||||||
|
|
||||||
// 2. 构建添加接收方请求
|
// 2. 构建添加接收方请求
|
||||||
AddReceiverRequest request = new AddReceiverRequest();
|
AddReceiverRequest request = new AddReceiverRequest();
|
||||||
request.setAppid(tencentPayProperties.getAppId());
|
request.setAppid(wechatConfigService.getConfig("PAY",qrCode.getTenantId()).getAppId());
|
||||||
|
|
||||||
// 设置接收方类型
|
// 设置接收方类型
|
||||||
try {
|
try {
|
||||||
@@ -243,7 +236,7 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
|||||||
|
|
||||||
// 3. 调用微信接口添加接收方
|
// 3. 调用微信接口添加接收方
|
||||||
try {
|
try {
|
||||||
AddReceiverResponse response = profitsharingService.addReceiver(request);
|
AddReceiverResponse response = wxPayConfigFactory.createProfitsharingService(qrCode.getTenantId()).addReceiver(request);
|
||||||
|
|
||||||
// 4. 处理响应结果
|
// 4. 处理响应结果
|
||||||
if (response != null && response.getAccount() != null) {
|
if (response != null && response.getAccount() != null) {
|
||||||
@@ -469,7 +462,8 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
|||||||
QueryOrderRequest request = new QueryOrderRequest();
|
QueryOrderRequest request = new QueryOrderRequest();
|
||||||
request.setOutOrderNo(outOrderNo);
|
request.setOutOrderNo(outOrderNo);
|
||||||
request.setTransactionId(transactionId);
|
request.setTransactionId(transactionId);
|
||||||
return profitsharingService.queryOrder(request);
|
ProfitSharing profitSharing = getByOrderNo(outOrderNo);
|
||||||
|
return wxPayConfigFactory.createProfitsharingService(profitSharing.getTenantId()).queryOrder(request);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("查询分账结果失败: outOrderNo={}, transactionId={}", outOrderNo, transactionId, e);
|
log.error("查询分账结果失败: outOrderNo={}, transactionId={}", outOrderNo, transactionId, e);
|
||||||
throw new RuntimeException("查询分账结果失败", e);
|
throw new RuntimeException("查询分账结果失败", e);
|
||||||
@@ -496,7 +490,7 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
|||||||
QueryOrderRequest request = new QueryOrderRequest();
|
QueryOrderRequest request = new QueryOrderRequest();
|
||||||
request.setOutOrderNo(profitSharing.getOutOrderNo());
|
request.setOutOrderNo(profitSharing.getOutOrderNo());
|
||||||
request.setTransactionId(profitSharing.getTransactionId());
|
request.setTransactionId(profitSharing.getTransactionId());
|
||||||
response = profitsharingService.queryOrder(request);
|
response = wxPayConfigFactory.createProfitsharingService(profitSharing.getTenantId()).queryOrder(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 构建返回结果
|
// 4. 构建返回结果
|
||||||
@@ -636,7 +630,7 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
|||||||
CreateOrderRequest request = new CreateOrderRequest();
|
CreateOrderRequest request = new CreateOrderRequest();
|
||||||
|
|
||||||
// 2. 设置基本信息
|
// 2. 设置基本信息
|
||||||
request.setAppid(tencentPayProperties.getAppId());
|
request.setAppid(wechatConfigService.getConfig("PAY",profitSharing.getTenantId()).getAppId());
|
||||||
request.setTransactionId(profitSharing.getTransactionId());
|
request.setTransactionId(profitSharing.getTransactionId());
|
||||||
request.setOutOrderNo(generateProfitSharingNo());
|
request.setOutOrderNo(generateProfitSharingNo());
|
||||||
|
|
||||||
|
|||||||
+11
-7
@@ -1,13 +1,13 @@
|
|||||||
package com.central.order.service.impl;
|
package com.central.order.service.impl;
|
||||||
|
|
||||||
import com.central.common.exception.BusinessException;
|
import com.central.common.exception.BusinessException;
|
||||||
import com.central.order.config.TencentPayProperties;
|
|
||||||
import com.central.order.config.WxMpProperties;
|
|
||||||
import com.central.order.enums.CommonStatus;
|
import com.central.order.enums.CommonStatus;
|
||||||
import com.central.order.model.WxMessageRecord;
|
import com.central.order.model.WxMessageRecord;
|
||||||
import com.central.order.service.IWxMessageRecordService;
|
import com.central.order.service.IWxMessageRecordService;
|
||||||
import com.central.order.service.IWxTemplateMessageService;
|
import com.central.order.service.IWxTemplateMessageService;
|
||||||
import com.central.order.service.IWxUserService;
|
import com.central.order.service.IWxUserService;
|
||||||
|
import com.central.wechat.entity.WechatConfig;
|
||||||
|
import com.central.wechat.feign.WechatConfigService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
@@ -16,6 +16,7 @@ import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|||||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.retry.annotation.Backoff;
|
import org.springframework.retry.annotation.Backoff;
|
||||||
import org.springframework.retry.annotation.Recover;
|
import org.springframework.retry.annotation.Recover;
|
||||||
import org.springframework.retry.annotation.Retryable;
|
import org.springframework.retry.annotation.Retryable;
|
||||||
@@ -34,17 +35,19 @@ public class WxTemplateMessageServiceImpl implements IWxTemplateMessageService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private WxMpService wxMpService;
|
private WxMpService wxMpService;
|
||||||
@Autowired
|
|
||||||
private WxMpProperties wxMpProperties;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IWxUserService wxUserService;
|
private IWxUserService wxUserService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TencentPayProperties tencentPayProperties;
|
private WechatConfigService wechatConfigService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IWxMessageRecordService wxMessageRecordService;
|
private IWxMessageRecordService wxMessageRecordService;
|
||||||
|
|
||||||
|
@Value("${zlt.tenant.id}")
|
||||||
|
private String defaultTenantId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Retryable(value = WxErrorException.class, maxAttempts = 3, backoff = @Backoff(delay = 1000, multiplier = 2))
|
@Retryable(value = WxErrorException.class, maxAttempts = 3, backoff = @Backoff(delay = 1000, multiplier = 2))
|
||||||
public void sendPaymentSuccessNotice(String unionId, String orderNo, String tourismName,
|
public void sendPaymentSuccessNotice(String unionId, String orderNo, String tourismName,
|
||||||
@@ -60,10 +63,11 @@ public class WxTemplateMessageServiceImpl implements IWxTemplateMessageService {
|
|||||||
try {
|
try {
|
||||||
String openId = wxUserService.getMpOpenIdByUnionId(unionId);
|
String openId = wxUserService.getMpOpenIdByUnionId(unionId);
|
||||||
log.info("获取到服务号openId={}", openId);
|
log.info("获取到服务号openId={}", openId);
|
||||||
|
WechatConfig config = wechatConfigService.getConfig("PAY",defaultTenantId);
|
||||||
// 构建模板消息
|
// 构建模板消息
|
||||||
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
||||||
.toUser(openId)
|
.toUser(openId)
|
||||||
.templateId(wxMpProperties.getTemplateId().getPaymentSuccess())
|
.templateId(config.getPaymentSuccessTemplateId())
|
||||||
.data(Arrays.asList(
|
.data(Arrays.asList(
|
||||||
new WxMpTemplateData("thing2", tourismName+"提示: 您当前排在第"+rank+"位!"),
|
new WxMpTemplateData("thing2", tourismName+"提示: 您当前排在第"+rank+"位!"),
|
||||||
new WxMpTemplateData("time3", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))),
|
new WxMpTemplateData("time3", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))),
|
||||||
@@ -71,7 +75,7 @@ public class WxTemplateMessageServiceImpl implements IWxTemplateMessageService {
|
|||||||
// new WxMpTemplateData("amount4", "19.90")
|
// new WxMpTemplateData("amount4", "19.90")
|
||||||
))
|
))
|
||||||
.miniProgram(new WxMpTemplateMessage.MiniProgram(
|
.miniProgram(new WxMpTemplateMessage.MiniProgram(
|
||||||
tencentPayProperties.getAppId(),
|
config.getAppId(),
|
||||||
"pages/index/index",
|
"pages/index/index",
|
||||||
true))
|
true))
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ knife4j:
|
|||||||
zlt:
|
zlt:
|
||||||
#多租户配置
|
#多租户配置
|
||||||
tenant:
|
tenant:
|
||||||
|
id: webApp
|
||||||
enable: false
|
enable: false
|
||||||
ignoreTables:
|
ignoreTables:
|
||||||
- edit_task
|
- edit_task
|
||||||
|
|||||||
-58
@@ -5,12 +5,7 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
|||||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||||
import com.central.wechat.entity.WechatConfig;
|
import com.central.wechat.entity.WechatConfig;
|
||||||
import com.central.wechat.feign.WechatConfigService;
|
import com.central.wechat.feign.WechatConfigService;
|
||||||
import com.wechat.pay.java.core.Config;
|
|
||||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
|
||||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.SettleInfo;
|
import com.wechat.pay.java.service.payments.jsapi.model.SettleInfo;
|
||||||
import com.wechat.pay.java.service.refund.RefundService;
|
|
||||||
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||||
@@ -22,10 +17,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|||||||
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
|
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
@@ -74,36 +65,6 @@ public class WechatAutoConfiguration {
|
|||||||
return new WxPayConfigFactory(configService);
|
return new WxPayConfigFactory(configService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnBean(WxPayConfigFactory.class)
|
|
||||||
public Config wxPayConfig(WxPayConfigFactory factory) {
|
|
||||||
return factory.createConfig(getCurrentTenantId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnBean(WxPayConfigFactory.class)
|
|
||||||
public JsapiServiceExtension jsapiService(WxPayConfigFactory factory) {
|
|
||||||
return factory.createJsapiService(getCurrentTenantId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnBean(WxPayConfigFactory.class)
|
|
||||||
public NotificationParser notificationParser(WxPayConfigFactory factory) {
|
|
||||||
return factory.createNotificationParser(getCurrentTenantId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnBean(WxPayConfigFactory.class)
|
|
||||||
public RefundService refundService(WxPayConfigFactory factory) {
|
|
||||||
return factory.createRefundService(getCurrentTenantId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnBean(Config.class)
|
|
||||||
public ProfitsharingService profitsharingService(Config config) {
|
|
||||||
return new ProfitsharingService.Builder().config(config).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnBean(WechatConfigService.class)
|
@ConditionalOnBean(WechatConfigService.class)
|
||||||
public SettleInfo settleInfo(WechatConfigService configService) {
|
public SettleInfo settleInfo(WechatConfigService configService) {
|
||||||
@@ -113,25 +74,6 @@ public class WechatAutoConfiguration {
|
|||||||
return settleInfo;
|
return settleInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnBean(WechatConfigService.class)
|
|
||||||
public Executor profitSharingExecutor(WechatConfigService configService) {
|
|
||||||
log.info("profitSharingExecutor被加载,tenantId:{}", getCurrentTenantId());
|
|
||||||
WechatConfig config = configService.getConfig("PAY", getCurrentTenantId());
|
|
||||||
if (!config.getAsyncEnabled()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
|
||||||
executor.setCorePoolSize(config.getAsyncPoolSize());
|
|
||||||
executor.setMaxPoolSize(config.getAsyncPoolSize());
|
|
||||||
executor.setQueueCapacity(100);
|
|
||||||
executor.setThreadNamePrefix("profit-sharing-");
|
|
||||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
|
||||||
executor.initialize();
|
|
||||||
return executor;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getCurrentTenantId() {
|
private String getCurrentTenantId() {
|
||||||
return "webApp";
|
return "webApp";
|
||||||
}
|
}
|
||||||
|
|||||||
+41
@@ -8,12 +8,16 @@ import com.wechat.pay.java.core.notification.NotificationConfig;
|
|||||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||||
import com.wechat.pay.java.service.refund.RefundService;
|
import com.wechat.pay.java.service.refund.RefundService;
|
||||||
|
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@@ -25,6 +29,8 @@ public class WxPayConfigFactory {
|
|||||||
private final Map<String, JsapiServiceExtension> jsapiServiceCache = new ConcurrentHashMap<>();
|
private final Map<String, JsapiServiceExtension> jsapiServiceCache = new ConcurrentHashMap<>();
|
||||||
private final Map<String, NotificationParser> notificationParserCache = new ConcurrentHashMap<>();
|
private final Map<String, NotificationParser> notificationParserCache = new ConcurrentHashMap<>();
|
||||||
private final Map<String, RefundService> refundServiceCache = new ConcurrentHashMap<>();
|
private final Map<String, RefundService> refundServiceCache = new ConcurrentHashMap<>();
|
||||||
|
private final Map<String, ProfitsharingService> profitsharingServiceCache = new ConcurrentHashMap<>();
|
||||||
|
private final Map<String, Executor> executorCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public WxPayConfigFactory(WechatConfigService configService) {
|
public WxPayConfigFactory(WechatConfigService configService) {
|
||||||
this.configService = configService;
|
this.configService = configService;
|
||||||
@@ -85,6 +91,37 @@ public class WxPayConfigFactory {
|
|||||||
return new RefundService.Builder().config(config).build();
|
return new RefundService.Builder().config(config).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProfitsharingService createProfitsharingService(String tenantId) {
|
||||||
|
return profitsharingServiceCache.computeIfAbsent(tenantId, this::buildProfitsharingService);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ProfitsharingService buildProfitsharingService(String tenantId) {
|
||||||
|
log.info("创建微信分账服务,tenantId:{}", tenantId);
|
||||||
|
Config config = createConfig(tenantId);
|
||||||
|
return new ProfitsharingService.Builder().config(config).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Executor createExecutor(String tenantId) {
|
||||||
|
return executorCache.computeIfAbsent(tenantId, this::buildExecutor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Executor buildExecutor(String tenantId) {
|
||||||
|
log.info("创建分账异步执行器,tenantId:{}", tenantId);
|
||||||
|
WechatConfig config = configService.getConfig("PAY", tenantId);
|
||||||
|
if (!config.getAsyncEnabled()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
|
executor.setCorePoolSize(config.getAsyncPoolSize());
|
||||||
|
executor.setMaxPoolSize(config.getAsyncPoolSize());
|
||||||
|
executor.setQueueCapacity(100);
|
||||||
|
executor.setThreadNamePrefix("profit-sharing-" + tenantId + "-");
|
||||||
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
executor.initialize();
|
||||||
|
return executor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除指定租户的缓存
|
* 清除指定租户的缓存
|
||||||
*/
|
*/
|
||||||
@@ -93,6 +130,8 @@ public class WxPayConfigFactory {
|
|||||||
jsapiServiceCache.remove(tenantId);
|
jsapiServiceCache.remove(tenantId);
|
||||||
notificationParserCache.remove(tenantId);
|
notificationParserCache.remove(tenantId);
|
||||||
refundServiceCache.remove(tenantId);
|
refundServiceCache.remove(tenantId);
|
||||||
|
profitsharingServiceCache.remove(tenantId);
|
||||||
|
executorCache.remove(tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,5 +142,7 @@ public class WxPayConfigFactory {
|
|||||||
jsapiServiceCache.clear();
|
jsapiServiceCache.clear();
|
||||||
notificationParserCache.clear();
|
notificationParserCache.clear();
|
||||||
refundServiceCache.clear();
|
refundServiceCache.clear();
|
||||||
|
profitsharingServiceCache.clear();
|
||||||
|
executorCache.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user