package cc.mrbird.febs.pay.controller;
|
|
import cc.mrbird.febs.common.enumerates.OrderDeliveryStateEnum;
|
import cc.mrbird.febs.common.enumerates.OrderStatusEnum;
|
import cc.mrbird.febs.common.exception.FebsException;
|
import cc.mrbird.febs.common.utils.ValidateEntityUtils;
|
import cc.mrbird.febs.mall.entity.MallOrderInfo;
|
import cc.mrbird.febs.mall.mapper.MallOrderInfoMapper;
|
import cn.hutool.core.date.DateUtil;
|
import io.swagger.annotations.Api;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.codec.digest.DigestUtils;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import javax.annotation.Resource;
|
import java.util.Map;
|
|
@Slf4j
|
@Controller
|
@Api(value = "FIUUController", tags = "FIUU支付")
|
@RequestMapping(value = "/api/fuPayReturn")
|
public class FiuuReturnController {
|
|
|
@Resource
|
private MallOrderInfoMapper mallOrderInfoMapper;
|
|
// Java 通知接口 暂时停止使用
|
@PostMapping("/callback")
|
public String handlePaymentCallback(@RequestParam Map<String, String> params, Model model) {
|
String secretKey = "59c709fc18978a6a83b87f05d37cecbf";
|
String tranID = params.get("tranID");
|
String orderId = params.get("orderid");
|
String status = params.get("status");
|
String domain = params.get("domain");
|
String amount = params.get("amount");
|
String currency = params.get("currency");
|
String paydate = params.get("paydate");
|
String skey = params.get("skey");
|
|
// 计算 skey 验证
|
String preSkey = DigestUtils.md5Hex(tranID + orderId + status + domain + amount + currency);
|
String calculatedSkey = DigestUtils.md5Hex(paydate + domain + preSkey + secretKey);
|
MallOrderInfo mallOrderInfo = ValidateEntityUtils
|
.ensureColumnReturnEntity(orderId, MallOrderInfo::getId, mallOrderInfoMapper::selectOne, "订单不存在");
|
log.info("callback status: {}", status);
|
log.info("callback skey: {}", preSkey);
|
log.info("callback calculatedSkey: {}", calculatedSkey);
|
log.info("callback payResult: {}", mallOrderInfo.getPayResult());
|
if("1".equals(mallOrderInfo.getPayResult())){
|
return "success";
|
}
|
|
if (!calculatedSkey.equals(skey)) {
|
throw new FebsException("订单回调失败,---"+orderId);
|
}
|
if ("00".equals(status)) {
|
updateOrderStatus(orderId, status, amount, paydate, tranID);
|
return "success";
|
}else{
|
return "fail";
|
}
|
}
|
|
private void updateOrderStatus(String orderId, String status, String amount, String paydate, String tranID) {
|
// 实现订单状态更新逻辑(如更新数据库)
|
MallOrderInfo mallOrderInfo = ValidateEntityUtils.ensureColumnReturnEntity(orderId, MallOrderInfo::getId, mallOrderInfoMapper::selectOne, "订单不存在");
|
ValidateEntityUtils.ensureNotEqual(mallOrderInfo.getPayResult(), "1", "订单已支付");
|
ValidateEntityUtils.ensureEqual(mallOrderInfo.getAmount().toString(), amount, "订单金额异常");
|
// 更新订单状态
|
mallOrderInfo.setPayMethod("FIUU支付");
|
mallOrderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue());
|
mallOrderInfo.setPayResult("1");
|
mallOrderInfo.setPayTime(DateUtil.parseDateTime(paydate));
|
mallOrderInfo.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue());
|
mallOrderInfo.setPayOrderNo(tranID);
|
mallOrderInfoMapper.updateById(mallOrderInfo);
|
}
|
}
|