支付功能工厂模式引入
This commit is contained in:
parent
975620ce34
commit
8195512ba8
@ -0,0 +1,31 @@
|
|||||||
|
package net.jieyuu.component;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.jieyuu.config.PayUrlConfig;
|
||||||
|
import net.jieyuu.vo.PayInfoVO;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class AlipayStrategy implements PayStrategy {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PayUrlConfig payUrlConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String unifiedorder(PayInfoVO payInfoVO) {
|
||||||
|
return PayStrategy.super.unifiedorder(payInfoVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String refund(PayInfoVO payInfoVO) {
|
||||||
|
return PayStrategy.super.refund(payInfoVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String queryPaySuccess(PayInfoVO payInfoVO) {
|
||||||
|
return PayStrategy.super.queryPaySuccess(payInfoVO);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package net.jieyuu.component;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.jieyuu.enums.ProductOrderPayTypeEnum;
|
||||||
|
import net.jieyuu.vo.PayInfoVO;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class PayFactory {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AlipayStrategy alipayStrategy;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WechatPayStrategy wechatPayStrategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建支付,简单工厂模式
|
||||||
|
*
|
||||||
|
* @param payInfoVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String pay(PayInfoVO payInfoVO) {
|
||||||
|
|
||||||
|
String payType = payInfoVO.getPayType();
|
||||||
|
if (ProductOrderPayTypeEnum.ALIPAY.name().equalsIgnoreCase(payType)) {// 支付宝
|
||||||
|
PayStrategyContext payStrategyContext = new PayStrategyContext(alipayStrategy);
|
||||||
|
return payStrategyContext.executeUnifiedorder(payInfoVO);
|
||||||
|
|
||||||
|
} else if (ProductOrderPayTypeEnum.WECHAT.name().equalsIgnoreCase(payType)) {// 微信支付
|
||||||
|
PayStrategyContext payStrategyContext = new PayStrategyContext(wechatPayStrategy);
|
||||||
|
return payStrategyContext.executeUnifiedorder(payInfoVO);
|
||||||
|
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询订单支付状态
|
||||||
|
*
|
||||||
|
* @param payInfoVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String querySuccess(PayInfoVO payInfoVO) {
|
||||||
|
|
||||||
|
String payType = payInfoVO.getPayType();
|
||||||
|
if (ProductOrderPayTypeEnum.ALIPAY.name().equalsIgnoreCase(payType)) {// 支付宝
|
||||||
|
PayStrategyContext payStrategyContext = new PayStrategyContext(alipayStrategy);
|
||||||
|
return payStrategyContext.executeQueryPaySuccess(payInfoVO);
|
||||||
|
|
||||||
|
} else if (ProductOrderPayTypeEnum.WECHAT.name().equalsIgnoreCase(payType)) {// 微信支付
|
||||||
|
PayStrategyContext payStrategyContext = new PayStrategyContext(wechatPayStrategy);
|
||||||
|
return payStrategyContext.executeQueryPaySuccess(payInfoVO);
|
||||||
|
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package net.jieyuu.component;
|
||||||
|
|
||||||
|
import net.jieyuu.vo.PayInfoVO;
|
||||||
|
|
||||||
|
public interface PayStrategy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下单
|
||||||
|
*
|
||||||
|
* @param payInfoVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
default String unifiedorder(PayInfoVO payInfoVO) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退款
|
||||||
|
*
|
||||||
|
* @param payInfoVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
default String refund(PayInfoVO payInfoVO) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询订单是否成功
|
||||||
|
*
|
||||||
|
* @param payInfoVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
default String queryPaySuccess(PayInfoVO payInfoVO) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package net.jieyuu.component;
|
||||||
|
|
||||||
|
import net.jieyuu.vo.PayInfoVO;
|
||||||
|
|
||||||
|
public class PayStrategyContext {
|
||||||
|
|
||||||
|
private PayStrategy payStrategy;
|
||||||
|
|
||||||
|
public PayStrategyContext(PayStrategy payStrategy) {
|
||||||
|
this.payStrategy = payStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据支付策略,调用不同支付
|
||||||
|
*
|
||||||
|
* @param payInfoVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String executeUnifiedorder(PayInfoVO payInfoVO) {
|
||||||
|
return this.payStrategy.unifiedorder(payInfoVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据支付策略,调用不同查询订单支持状态
|
||||||
|
*
|
||||||
|
* @param payInfoVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String executeQueryPaySuccess(PayInfoVO payInfoVO) {
|
||||||
|
return this.payStrategy.queryPaySuccess(payInfoVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
|||||||
|
package net.jieyuu.component;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.jieyuu.config.PayUrlConfig;
|
||||||
|
import net.jieyuu.vo.PayInfoVO;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class WechatPayStrategy implements PayStrategy {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PayUrlConfig payUrlConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String unifiedorder(PayInfoVO payInfoVO) {
|
||||||
|
return PayStrategy.super.unifiedorder(payInfoVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String refund(PayInfoVO payInfoVO) {
|
||||||
|
return PayStrategy.super.refund(payInfoVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String queryPaySuccess(PayInfoVO payInfoVO) {
|
||||||
|
return PayStrategy.super.queryPaySuccess(payInfoVO);
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.alibaba.fastjson.TypeReference;
|
import com.alibaba.fastjson.TypeReference;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.jieyuu.component.PayFactory;
|
||||||
import net.jieyuu.config.RabbitMQConfig;
|
import net.jieyuu.config.RabbitMQConfig;
|
||||||
import net.jieyuu.enums.*;
|
import net.jieyuu.enums.*;
|
||||||
import net.jieyuu.exception.BizException;
|
import net.jieyuu.exception.BizException;
|
||||||
@ -23,6 +24,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import net.jieyuu.utils.CommonUtil;
|
import net.jieyuu.utils.CommonUtil;
|
||||||
import net.jieyuu.utils.JsonData;
|
import net.jieyuu.utils.JsonData;
|
||||||
import net.jieyuu.vo.CouponRecordVO;
|
import net.jieyuu.vo.CouponRecordVO;
|
||||||
|
import net.jieyuu.vo.OrderItemVO;
|
||||||
import net.jieyuu.vo.ProductOrderAddressVO;
|
import net.jieyuu.vo.ProductOrderAddressVO;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
@ -125,6 +127,7 @@ public class ProductOrderServiceImpl extends ServiceImpl<ProductOrderMapper, Pro
|
|||||||
rabbitTemplate.convertAndSend(rabbitMQConfig.getEventExchange(), rabbitMQConfig.getOrderCloseDelayRoutingKey(), orderMessage);
|
rabbitTemplate.convertAndSend(rabbitMQConfig.getEventExchange(), rabbitMQConfig.getOrderCloseDelayRoutingKey(), orderMessage);
|
||||||
|
|
||||||
//创建支付 todo
|
//创建支付 todo
|
||||||
|
// PayFactory payFactory = new PayFactory();
|
||||||
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -389,7 +392,6 @@ public class ProductOrderServiceImpl extends ServiceImpl<ProductOrderMapper, Pro
|
|||||||
// 向第三方支付查询支付情况 todo
|
// 向第三方支付查询支付情况 todo
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String payResult = "";
|
String payResult = "";
|
||||||
// 订单结果为空,支付不成功,取消订单
|
// 订单结果为空,支付不成功,取消订单
|
||||||
if (StringUtils.isBlank(payResult)) {
|
if (StringUtils.isBlank(payResult)) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package net.jieyuu.model;
|
package net.jieyuu.vo;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
@ -0,0 +1,45 @@
|
|||||||
|
package net.jieyuu.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class PayInfoVO {
|
||||||
|
/**
|
||||||
|
* 订单号
|
||||||
|
*/
|
||||||
|
private String outTradeNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单总金额
|
||||||
|
*/
|
||||||
|
private String payFee;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付类型 支付宝-微信-银行-其他
|
||||||
|
*/
|
||||||
|
private String payType;
|
||||||
|
/**
|
||||||
|
* 客户端类型 h5/app/pc
|
||||||
|
*/
|
||||||
|
private String clientType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单支付超时时间 毫秒
|
||||||
|
*/
|
||||||
|
private long orderPayTimeoutMills;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user