支付接口远程调用

This commit is contained in:
2025-08-22 00:52:06 +08:00
parent b98fc2b902
commit b354b0b274
10 changed files with 410 additions and 1 deletions

View File

@ -14,4 +14,10 @@ public interface OrderDistribService {
* @return * @return
*/ */
IPage<OrderDistribDTO> pageQueryOrderDistrib(Integer pageNo, Integer pageSize, OrderDistribQueryReq orderDistribQueryReq); IPage<OrderDistribDTO> pageQueryOrderDistrib(Integer pageNo, Integer pageSize, OrderDistribQueryReq orderDistribQueryReq);
/**
* 保存订单分润记录
* @param orderNo
*/
void saveOrderDistrib(String orderNo);
} }

View File

@ -20,4 +20,9 @@ public class OrderDistribServiceImpl implements OrderDistribService {
public IPage<OrderDistribDTO> pageQueryOrderDistrib(Integer pageNo, Integer pageSize, OrderDistribQueryReq orderDistribQueryReq) { public IPage<OrderDistribDTO> pageQueryOrderDistrib(Integer pageNo, Integer pageSize, OrderDistribQueryReq orderDistribQueryReq) {
return orderDistribRepo.pageQueryOrderDistrib(pageNo, pageSize, orderDistribQueryReq); return orderDistribRepo.pageQueryOrderDistrib(pageNo, pageSize, orderDistribQueryReq);
} }
@Override
public void saveOrderDistrib(String orderNo) {
//TODO 获取订单分润信息
}
} }

View File

@ -21,6 +21,7 @@ import com.sczx.order.service.OrderService;
import com.sczx.order.thirdpart.dto.*; import com.sczx.order.thirdpart.dto.*;
import com.sczx.order.thirdpart.dto.req.CarQueryConditionReq; import com.sczx.order.thirdpart.dto.req.CarQueryConditionReq;
import com.sczx.order.thirdpart.integration.CarInteg; import com.sczx.order.thirdpart.integration.CarInteg;
import com.sczx.order.thirdpart.integration.PayInteg;
import com.sczx.order.thirdpart.integration.StoreInteg; import com.sczx.order.thirdpart.integration.StoreInteg;
import com.sczx.order.utils.JwtUtil; import com.sczx.order.utils.JwtUtil;
import com.sczx.order.utils.OrderUtil; import com.sczx.order.utils.OrderUtil;
@ -62,6 +63,9 @@ public class OrderServiceImpl implements OrderService {
@Autowired @Autowired
private OrderCarImgRepo orderCarImgRepo; private OrderCarImgRepo orderCarImgRepo;
@Autowired
private PayInteg payInteg;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public RentCarOrderResultDTO submitRentCarOrder(RentCarOrderReq rentCarOrderReq) { public RentCarOrderResultDTO submitRentCarOrder(RentCarOrderReq rentCarOrderReq) {

View File

@ -0,0 +1,38 @@
package com.sczx.order.thirdpart.dto;
import java.util.Map;
/**
* 支付响应数据传输对象
*/
public class PaymentResponse {
private String code;
private String message;
private Map<String, String> payData;
public PaymentResponse() {}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Map<String, String> getPayData() {
return payData;
}
public void setPayData(Map<String, String> payData) {
this.payData = payData;
}
}

View File

@ -0,0 +1,74 @@
package com.sczx.order.thirdpart.dto.req;
/**
* 支付请求数据传输对象
*/
public class PaymentRequest {
private Long companyId; // 公司ID
private String body; // 商品描述
private String outTradeNo; // 商户订单号
private Integer totalFee; // 总金额,单位为分
private String spbillCreateIp; // 终端IP
private String openId; // 用户标识
private String attach; // 附加数据
// 构造函数
public PaymentRequest() {}
// getter和setter方法
public Long getCompanyId() {
return companyId;
}
public void setCompanyId(Long companyId) {
this.companyId = companyId;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getOutTradeNo() {
return outTradeNo;
}
public void setOutTradeNo(String outTradeNo) {
this.outTradeNo = outTradeNo;
}
public Integer getTotalFee() {
return totalFee;
}
public void setTotalFee(Integer totalFee) {
this.totalFee = totalFee;
}
public String getSpbillCreateIp() {
return spbillCreateIp;
}
public void setSpbillCreateIp(String spbillCreateIp) {
this.spbillCreateIp = spbillCreateIp;
}
public String getOpenId() {
return openId;
}
public void setOpenId(String openId) {
this.openId = openId;
}
public String getAttach() {
return attach;
}
public void setAttach(String attach) {
this.attach = attach;
}
}

View File

@ -0,0 +1,65 @@
package com.sczx.order.thirdpart.dto.req;
/**
* 退款请求数据传输对象
*/
public class RefundRequest {
private Long companyId; // 公司ID
private String outTradeNo; // 商户订单号
private String outRefundNo; // 商户退款单号
private Integer totalFee; // 订单金额(分)
private Integer refundFee; // 退款金额(分)
private String refundDesc; // 退款原因
// 构造函数
public RefundRequest() {}
// getter和setter方法
public Long getCompanyId() {
return companyId;
}
public void setCompanyId(Long companyId) {
this.companyId = companyId;
}
public String getOutTradeNo() {
return outTradeNo;
}
public void setOutTradeNo(String outTradeNo) {
this.outTradeNo = outTradeNo;
}
public String getOutRefundNo() {
return outRefundNo;
}
public void setOutRefundNo(String outRefundNo) {
this.outRefundNo = outRefundNo;
}
public Integer getTotalFee() {
return totalFee;
}
public void setTotalFee(Integer totalFee) {
this.totalFee = totalFee;
}
public Integer getRefundFee() {
return refundFee;
}
public void setRefundFee(Integer refundFee) {
this.refundFee = refundFee;
}
public String getRefundDesc() {
return refundDesc;
}
public void setRefundDesc(String refundDesc) {
this.refundDesc = refundDesc;
}
}

View File

@ -0,0 +1,47 @@
package com.sczx.order.thirdpart.facade;
import com.sczx.order.thirdpart.dto.PaymentResponse;
import com.sczx.order.thirdpart.dto.req.PaymentRequest;
import com.sczx.order.thirdpart.dto.req.RefundRequest;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@FeignClient(name = "sczx-singlepay", url = "${sczx-singlepay.ribbon.listOfServers:}")
public interface PayFacade {
/**
* 统一下单
* @param request
* @return
*/
@PostMapping("/api/payment/unifiedOrder")
PaymentResponse unifiedOrder(@RequestBody PaymentRequest request);
/**
* 查询订单
* @param companyId
* @param outTradeNo
* @return
*/
@GetMapping("/api/payment/query/{companyId}/{outTradeNo}")
Map<String, String> orderQuery(@PathVariable Long companyId, @PathVariable String outTradeNo);
/**
* 退款
* @param request
* @return
*/
@PostMapping("/api/payment/refund")
Map<String, String> refund(@RequestBody RefundRequest request);
/**
* 退款查询
* @param companyId
* @param outTradeNo
* @return
*/
@GetMapping("/api/payment/refundQuery/{companyId}")
Map<String, String> refundQuery(@PathVariable Long companyId, @RequestParam String outTradeNo);
}

View File

@ -0,0 +1,109 @@
package com.sczx.order.thirdpart.integration;
import com.sczx.order.common.enums.PaymentTypeEnum;
import com.sczx.order.exception.InnerException;
import com.sczx.order.thirdpart.dto.PaymentResponse;
import com.sczx.order.thirdpart.dto.UnifiedPaymentInfoDTO;
import com.sczx.order.thirdpart.dto.req.PaymentRequest;
import com.sczx.order.thirdpart.dto.req.RefundRequest;
import com.sczx.order.thirdpart.facade.PayFacade;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
@Slf4j
@Component
public class PayInteg {
@Autowired
private PayFacade payFacade;
public UnifiedPaymentInfoDTO unifiedOrder(PaymentRequest request){
try{
PaymentResponse result = payFacade.unifiedOrder(request);
if(StringUtils.isNotBlank(result.getCode()) && "SUCCESS".equals(result.getCode())){
UnifiedPaymentInfoDTO unifiedPaymentInfo = new UnifiedPaymentInfoDTO();
unifiedPaymentInfo.setAppId(result.getPayData().get("appid"));
unifiedPaymentInfo.setTimeStamp(result.getPayData().get("timeStamp"));
unifiedPaymentInfo.setNonceStr(result.getPayData().get("nonceStr"));
unifiedPaymentInfo.setPackageValue(result.getPayData().get("package"));
unifiedPaymentInfo.setSignType(result.getPayData().get("signType"));
unifiedPaymentInfo.setPaySign(result.getPayData().get("paySign"));
unifiedPaymentInfo.setOutTradeNo(result.getPayData().get("out_trade_no"));
unifiedPaymentInfo.setPaymentType(PaymentTypeEnum.WX_PAY.getCode());
return unifiedPaymentInfo;
}else {
throw new InnerException(result.getMessage());
}
} catch (Exception e){
log.error("支付下单失败",e);
throw new InnerException("支付下单失败");
}
}
/**
* 查询订单
* @param companyId
* @param outTradeNo
* @return
*/
public Map<String, String> orderQuery(Long companyId, String outTradeNo){
try {
Map<String, String> result = payFacade.orderQuery(companyId, outTradeNo);
String returnCode = result.get("return_code");
if(StringUtils.equalsIgnoreCase(returnCode, "FAIL")){
throw new InnerException("查询订单失败");
}else {
return result;
}
} catch (Exception e){
log.error("查询订单失败",e);
throw new InnerException("查询订单失败");
}
}
/**
* 退款
* @param request
* @return
*/
public Map<String, String> refund(RefundRequest request){
try {
Map<String, String> result = payFacade.refund(request);
String returnCode = result.get("return_code");
if(StringUtils.equalsIgnoreCase(returnCode, "FAIL")){
throw new InnerException("退款失败");
}else {
return result;
}
} catch (Exception e){
log.error("退款失败",e);
throw new InnerException("退款失败");
}
}
/**
* 退款查询
* @param companyId
* @param outTradeNo
* @return
*/
public Map<String, String> refundQuery(Long companyId, String outTradeNo){
try {
Map<String, String> result = payFacade.refundQuery(companyId, outTradeNo);
String returnCode = result.get("return_code");
if(StringUtils.equalsIgnoreCase(returnCode, "FAIL")){
throw new InnerException("查询退款失败");
}else {
return result;
}
} catch (Exception e){
log.error("查询退款失败",e);
throw new InnerException("查询退款失败");
}
}
}

View File

@ -0,0 +1,57 @@
package com.sczx.order.utils;
import org.springframework.stereotype.Service;
import java.util.concurrent.*;
/**
* 线程池工具类,用于执行异步任务
* Created by zengji on 2019/5/13.
*
*/
@Service
public class ThreadPoolUtils {
public static ThreadPoolExecutor threadPool;
//核心线程大小
private static int corePoolSize=120;
//最大线程个数
private static int maximumPoolSize=180;
//空闲线程存活时间
private static long keepAliveTime=300;
//队列容量
private static int capacity=200;
/**
* 无返回值
*/
public static void execute(Runnable runnable){
getThreadPool().execute(runnable);
}
/**
* 有返回值
*/
public static <T> Future<T> submit(Callable<T> callable){
return getThreadPool().submit(callable);
}
/**
* dcs获取线程池
* @return 线程池对象
*/
public static ThreadPoolExecutor getThreadPool() {
if (threadPool != null) {
return threadPool;
} else {
synchronized (ThreadPoolUtils.class) {
if (threadPool == null) {
threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(capacity), new ThreadPoolExecutor.CallerRunsPolicy());
}
return threadPool;
}
}
}
}

View File

@ -4,4 +4,8 @@ sczx-store:
sczx-car: sczx-car:
ribbon: ribbon:
listOfServers: http://115.190.8.52:8083 listOfServers: http://115.190.8.52:8083
sczx-singlepay:
ribbon:
listOfServers: http://115.190.8.52:8019