Merge branch 'test' into dev
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.sqx.modules.pay.controller.app;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -183,50 +184,69 @@ public class WuyouController {
|
||||
|
||||
@PostMapping("/notify")
|
||||
public String notify(HttpServletRequest request, NotifyDto notifyDto) {
|
||||
log.info("无忧支付回调, {}", notifyDto);
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("callbacks", notifyDto.getCallbacks());
|
||||
params.put("total", notifyDto.getTotal());
|
||||
params.put("out_trade_no", notifyDto.getOut_trade_no());
|
||||
params.put("pay_time", notifyDto.getPay_time());
|
||||
try {
|
||||
log.info("无忧支付回调, {}", notifyDto);
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("callbacks", notifyDto.getCallbacks());
|
||||
params.put("total", notifyDto.getTotal());
|
||||
params.put("out_trade_no", notifyDto.getOut_trade_no());
|
||||
params.put("pay_time", notifyDto.getPay_time());
|
||||
|
||||
String sign = Encrypt.getParamsSign(params);
|
||||
if (!sign.equals(notifyDto.getSign())) {
|
||||
log.error("无忧支付回调签名错误, 参数: {},签名结果:{}", JSONObject.toJSONString(notifyDto), sign);
|
||||
String sign = Encrypt.getParamsSign(params);
|
||||
if (!sign.equals(notifyDto.getSign())) {
|
||||
log.error("无忧支付回调签名错误, 参数: {},签名结果:{}", JSONObject.toJSONString(notifyDto), sign);
|
||||
// return "签名错误";
|
||||
}
|
||||
|
||||
if (!"CODE_SUCCESS".equals(notifyDto.getCallbacks())) {
|
||||
log.error("无忧支付回调 未支付成功, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "success";
|
||||
}
|
||||
|
||||
log.info("无忧支付回调成功, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
|
||||
DateTime offsetMinute = DateUtil.offsetMinute(new Date(), -30);
|
||||
String format = DateUtil.format(offsetMinute, "yyyy-MM-dd HH:mm:ss");
|
||||
List<PayDetails> details = payDetailsDao.selectList(new LambdaQueryWrapper<PayDetails>()
|
||||
.eq(PayDetails::getTradeNo, notifyDto.getOut_trade_no()).ge(PayDetails::getCreateTime, format));
|
||||
if (details.isEmpty()) {
|
||||
log.error("无忧支付回调订单不存在, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "success";
|
||||
}
|
||||
if (details.size() > 1) {
|
||||
log.error("无忧支付回调订单重复, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "success";
|
||||
}
|
||||
PayDetails payDetails = details.get(0);
|
||||
if (payDetails == null) {
|
||||
log.error("无忧支付回调订单不存在, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "success";
|
||||
}
|
||||
|
||||
if (payDetails.getState() == 1) {
|
||||
log.info("重复回调!参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "success";
|
||||
}
|
||||
|
||||
QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("orders_no", payDetails.getOrderId()).eq("user_id", payDetails.getUserId());
|
||||
queryWrapper.last("limit 1");
|
||||
Orders order = ordersService.getOne(queryWrapper);
|
||||
if (order == null) {
|
||||
log.error("无忧支付回调订单不存在, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "订单不存在";
|
||||
}
|
||||
|
||||
if (order.getStatus() != 0) {
|
||||
log.error("无忧支付回调订单已支付, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "订单已支付";
|
||||
}
|
||||
|
||||
payDetails.setThirdOrderNo(notifyDto.getOrder_sn());
|
||||
ordersTask.updateOrderStatus(payDetails, order);
|
||||
} catch (Exception e) {
|
||||
log.error("无忧支付回调异常, 参数: {}", JSONObject.toJSONString(notifyDto), e);
|
||||
}
|
||||
|
||||
if (!"CODE_SUCCESS".equals(notifyDto.getCallbacks())) {
|
||||
log.error("无忧支付回调 未支付成功, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "success";
|
||||
}
|
||||
|
||||
log.info("无忧支付回调成功, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
|
||||
PayDetails payDetails = payDetailsDao.selectByTradeNo(notifyDto.getOut_trade_no());
|
||||
if (payDetails == null) {
|
||||
log.error("无忧支付回调订单不存在, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "success";
|
||||
}
|
||||
|
||||
if (payDetails.getState() == 1) {
|
||||
log.info("重复回调!参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "success";
|
||||
}
|
||||
|
||||
Orders order = ordersService.selectOrderByOrdersNo(payDetails.getOrderId());
|
||||
if (order == null) {
|
||||
log.error("无忧支付回调订单不存在, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "订单不存在";
|
||||
}
|
||||
|
||||
if (order.getStatus() != 0) {
|
||||
log.error("无忧支付回调订单已支付, 参数: {}", JSONObject.toJSONString(notifyDto));
|
||||
return "订单已支付";
|
||||
}
|
||||
|
||||
payDetails.setThirdOrderNo(notifyDto.getOrder_sn());
|
||||
ordersTask.updateOrderStatus(payDetails, order);
|
||||
return "success";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user