下单逻辑和消费消息查询订单状态完善
This commit is contained in:
parent
130af70d45
commit
7c348ac613
@ -0,0 +1,10 @@
|
||||
package net.jieyuu.constant;
|
||||
|
||||
public class TimeConstant {
|
||||
|
||||
/**
|
||||
* 支付订单有效时长,超过未支付则关闭订单
|
||||
* 订单超时 毫秒 默认30分钟
|
||||
*/
|
||||
public static final long ORDER_PAY_TIMEOUT_MILLS = 1000 * 60 * 30;
|
||||
}
|
@ -43,13 +43,15 @@ public class CallbackController {
|
||||
*/
|
||||
@PostMapping("alipay")
|
||||
public String alipayCallback(HttpServletRequest request, HttpServletResponse response) {
|
||||
// return productOrderService.alipayCallback();
|
||||
|
||||
// 新思路 todo
|
||||
// 将支付宝消息投入MQ
|
||||
// MQ发送消息,调用再更新订单数据消费
|
||||
|
||||
// 将异步通知中收到的所有参数转化为map
|
||||
Map<String, String> paramsMap = convertRequestParamsToMap(request);
|
||||
|
||||
log.info("支付宝回调通知请求:{}", paramsMap);
|
||||
|
||||
|
||||
try {
|
||||
boolean signVerified = AlipaySignature.rsaCheckV1(paramsMap, AlipayConfig.ALIPAY_PUB_KEY, AlipayConfig.CHARSET, AlipayConfig.SIGN_TYPE);
|
||||
if (signVerified) {
|
||||
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.jieyuu.component.PayFactory;
|
||||
import net.jieyuu.config.RabbitMQConfig;
|
||||
import net.jieyuu.constant.TimeConstant;
|
||||
import net.jieyuu.enums.*;
|
||||
import net.jieyuu.exception.BizException;
|
||||
import net.jieyuu.feign.CouponFeignService;
|
||||
@ -25,6 +26,7 @@ import net.jieyuu.utils.CommonUtil;
|
||||
import net.jieyuu.utils.JsonData;
|
||||
import net.jieyuu.vo.CouponRecordVO;
|
||||
import net.jieyuu.vo.OrderItemVO;
|
||||
import net.jieyuu.vo.PayInfoVO;
|
||||
import net.jieyuu.vo.ProductOrderAddressVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
@ -71,6 +73,9 @@ public class ProductOrderServiceImpl extends ServiceImpl<ProductOrderMapper, Pro
|
||||
@Autowired
|
||||
private RabbitMQConfig rabbitMQConfig;
|
||||
|
||||
@Autowired
|
||||
private PayFactory payFactory;
|
||||
|
||||
/**
|
||||
* * 防重提交
|
||||
* * 用户微服务-确认收货地址
|
||||
@ -127,11 +132,23 @@ public class ProductOrderServiceImpl extends ServiceImpl<ProductOrderMapper, Pro
|
||||
orderMessage.setMessageId(productOrderDO.getId());
|
||||
rabbitTemplate.convertAndSend(rabbitMQConfig.getEventExchange(), rabbitMQConfig.getOrderCloseDelayRoutingKey(), orderMessage);
|
||||
|
||||
//创建支付 todo
|
||||
// PayFactory payFactory = new PayFactory();
|
||||
//创建支付
|
||||
PayInfoVO payInfoVO = new PayInfoVO(orderOutTradeNo,
|
||||
productOrderDO.getPayAmount(),
|
||||
orderRequest.getPayType(),
|
||||
orderRequest.getClientType(),
|
||||
orderItemList.get(0).getProductTitle(),
|
||||
"",
|
||||
TimeConstant.ORDER_PAY_TIMEOUT_MILLS);
|
||||
String payResult = payFactory.pay(payInfoVO);
|
||||
|
||||
|
||||
return null;
|
||||
if (StringUtils.isNotBlank(payResult)) {
|
||||
log.error("创建支付订单成功:payInfo={},payResult={}", payInfoVO, payResult);
|
||||
return JsonData.buildSuccess(payResult);
|
||||
} else {
|
||||
log.error("创建支付订单失败:payInfo={},payResult={}", payInfoVO, payResult);
|
||||
return JsonData.buildResult(BizCodeEnum.PAY_ORDER_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -390,18 +407,20 @@ public class ProductOrderServiceImpl extends ServiceImpl<ProductOrderMapper, Pro
|
||||
log.info("直接确认消息,订单支付成功:{}", orderMessage);
|
||||
return true;
|
||||
}
|
||||
// 向第三方支付查询支付情况 todo
|
||||
// 向第三方支付查询支付情况
|
||||
PayInfoVO payInfoVO = new PayInfoVO();
|
||||
payInfoVO.setPayType(productOrderDO.getPayType());
|
||||
payInfoVO.setOutTradeNo(orderMessage.getOutTradeNo());
|
||||
String payResult = payFactory.querySuccess(payInfoVO);
|
||||
|
||||
|
||||
String payResult = "";
|
||||
// 订单结果为空,支付不成功,取消订单
|
||||
if (StringUtils.isBlank(payResult)) {
|
||||
productOrderMapper.updateOrderPayState(orderMessage.getOutTradeNo(), ProductOrderStateEnum.CANCEL.name(), ProductOrderStateEnum.NEW.name());
|
||||
log.info("结果为空,则未支付成功,本地取消订单:{}", orderMessage);
|
||||
log.info("结果为空,则未支付成功,本地取消订单:{}", orderMessage);
|
||||
return true;
|
||||
} else {
|
||||
// 将订单状态改为已经支付
|
||||
log.warn("支付成功,主动修改订单状态为已支付,造成该元婴的情况可能是支付通道回调有问题:{}", orderMessage);
|
||||
log.warn("支付成功,主动修改订单状态为已支付,造成该元婴的情况可能是支付通道回调有问题:{}", orderMessage);
|
||||
productOrderMapper.updateOrderPayState(orderMessage.getOutTradeNo(), ProductOrderStateEnum.PAY.name(), ProductOrderStateEnum.NEW.name());
|
||||
return true;
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ -16,7 +18,7 @@ public class PayInfoVO {
|
||||
/**
|
||||
* 订单总金额
|
||||
*/
|
||||
private String payFee;
|
||||
private BigDecimal payFee;
|
||||
|
||||
/**
|
||||
* 支付类型 支付宝-微信-银行-其他
|
||||
|
Loading…
Reference in New Issue
Block a user