优化支付模块的代码,增加微信扫码支付的功能
This commit is contained in:
parent
cac17af0fe
commit
98217a5cfe
@ -0,0 +1,32 @@
|
|||||||
|
package com.seer.teach.common.utils;
|
||||||
|
|
||||||
|
import cn.hutool.extra.servlet.JakartaServletUtil;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.web.context.request.RequestAttributes;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
public class IpUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前请求
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static HttpServletRequest getRequest() {
|
||||||
|
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||||
|
if (!(requestAttributes instanceof ServletRequestAttributes)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ((ServletRequestAttributes) requestAttributes).getRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前请求的IP
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getIp() {
|
||||||
|
return JakartaServletUtil.getClientIP(getRequest());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -49,4 +49,9 @@ public class PayRefundReqDTO {
|
|||||||
* 渠道编码
|
* 渠道编码
|
||||||
*/
|
*/
|
||||||
private String channelCode;
|
private String channelCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回调地址
|
||||||
|
*/
|
||||||
|
private String notifyUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -150,7 +150,7 @@ public abstract class AbstractWxPayClient extends AbstractPayClient {
|
|||||||
.setAmount(new WxPayRefundV3Request.Amount().setRefund(reqDTO.getRefundPrice())
|
.setAmount(new WxPayRefundV3Request.Amount().setRefund(reqDTO.getRefundPrice())
|
||||||
.setTotal(reqDTO.getPayPrice()).setCurrency("CNY"))
|
.setTotal(reqDTO.getPayPrice()).setCurrency("CNY"))
|
||||||
.setReason(reqDTO.getReason())
|
.setReason(reqDTO.getReason())
|
||||||
.setNotifyUrl(this.refundNotifyUrl);
|
.setNotifyUrl(reqDTO.getNotifyUrl());
|
||||||
try {
|
try {
|
||||||
WxPayRefundV3Result response = client.refundV3(request);
|
WxPayRefundV3Result response = client.refundV3(request);
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.seer.teach.pay.app.pay.service.impl;
|
package com.seer.teach.pay.app.pay.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
import com.alibaba.nacos.shaded.com.google.common.collect.Maps;
|
import com.alibaba.nacos.shaded.com.google.common.collect.Maps;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.seer.teach.common.constants.CommonConstant;
|
import com.seer.teach.common.constants.CommonConstant;
|
||||||
@ -8,6 +9,7 @@ import com.seer.teach.common.enums.pay.PayChannelEnum;
|
|||||||
import com.seer.teach.common.enums.pay.PayOrderSourceEnum;
|
import com.seer.teach.common.enums.pay.PayOrderSourceEnum;
|
||||||
import com.seer.teach.common.enums.pay.PayStatusEnum;
|
import com.seer.teach.common.enums.pay.PayStatusEnum;
|
||||||
import com.seer.teach.common.utils.AssertUtils;
|
import com.seer.teach.common.utils.AssertUtils;
|
||||||
|
import com.seer.teach.common.utils.IpUtils;
|
||||||
import com.seer.teach.pay.app.client.PayClient;
|
import com.seer.teach.pay.app.client.PayClient;
|
||||||
import com.seer.teach.pay.app.client.PayClientFactory;
|
import com.seer.teach.pay.app.client.PayClientFactory;
|
||||||
import com.seer.teach.pay.app.client.convert.PayClientConvert;
|
import com.seer.teach.pay.app.client.convert.PayClientConvert;
|
||||||
@ -83,6 +85,7 @@ public class AppPayOrderServiceImpl implements IAppPayOrderService {
|
|||||||
}
|
}
|
||||||
payOrderReqDTO.setNotifyUrl(getNotifyUrl(payChannel));
|
payOrderReqDTO.setNotifyUrl(getNotifyUrl(payChannel));
|
||||||
payOrderReqDTO.setReturnUrl(orderPayReq.getReturnUrl());
|
payOrderReqDTO.setReturnUrl(orderPayReq.getReturnUrl());
|
||||||
|
payOrderReqDTO.setUserIp(IpUtils.getIp());
|
||||||
// 6,执行支付
|
// 6,执行支付
|
||||||
PayOrderRespDTO response = payClient.payOrder(payOrderReqDTO);
|
PayOrderRespDTO response = payClient.payOrder(payOrderReqDTO);
|
||||||
response.setChannelId(payChannel.getId());
|
response.setChannelId(payChannel.getId());
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import com.seer.teach.pay.service.IPayOrderService;
|
|||||||
import com.seer.teach.pay.service.IRefundOrderService;
|
import com.seer.teach.pay.service.IRefundOrderService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -50,6 +51,10 @@ public class AppRefundOrderServiceImpl implements IAppRefundOrderService {
|
|||||||
|
|
||||||
private final OrderProcessStrategyFactory orderProcessStrategyFactory;
|
private final OrderProcessStrategyFactory orderProcessStrategyFactory;
|
||||||
|
|
||||||
|
|
||||||
|
@Value("${server.servlet.context-path:}")
|
||||||
|
private String contextPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行退款订单
|
* 执行退款订单
|
||||||
*
|
*
|
||||||
@ -112,6 +117,8 @@ public class AppRefundOrderServiceImpl implements IAppRefundOrderService {
|
|||||||
.payPrice(refundRequest.getTotalAmount().intValue())
|
.payPrice(refundRequest.getTotalAmount().intValue())
|
||||||
.refundPrice(refundRequest.getRefundAmount().intValue())
|
.refundPrice(refundRequest.getRefundAmount().intValue())
|
||||||
.userId(refundRequest.getUserId())
|
.userId(refundRequest.getUserId())
|
||||||
|
.channelCode(channelCode)
|
||||||
|
.notifyUrl(getRefundNotifyUrl(payChannel))
|
||||||
.build();
|
.build();
|
||||||
log.info("构建退款请求参数完成,请求参数:{}", payRefundReqDTO);
|
log.info("构建退款请求参数完成,请求参数:{}", payRefundReqDTO);
|
||||||
|
|
||||||
@ -135,6 +142,10 @@ public class AppRefundOrderServiceImpl implements IAppRefundOrderService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getRefundNotifyUrl(PayChannelEntity payChannel) {
|
||||||
|
return payChannel.getNotifyDomain() + contextPath + "/app/callback/refund/" + payChannel.getChannelCode();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询退款状态
|
* 查询退款状态
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user