| | |
| | | import io.swagger.annotations.Api; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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 javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | |
| | | @Slf4j |
| | | @Controller |
| | | @Api(value = "FIUUController", tags = "FIUU支付") |
| | | //@RestController |
| | | @Api(value = "FiuuReturnController", tags = "FIUU支付-ReturnURL") |
| | | @RequestMapping(value = "/api/fuPayReturn") |
| | | public class FiuuReturnController { |
| | | |
| | |
| | | @Resource |
| | | private MallOrderInfoMapper mallOrderInfoMapper; |
| | | |
| | | // Java 通知接口 暂时停止使用 |
| | | @PostMapping("/callback") |
| | | public void handlePaymentCallback( |
| | | @PostMapping("/payment/callback") |
| | | public String handlePaymentCallback( |
| | | @RequestParam("amount") String amount, |
| | | @RequestParam("orderid") String orderId, |
| | | @RequestParam("tranID") String tranId, |
| | |
| | | @RequestParam("domain") String domain, |
| | | @RequestParam("currency") String currency, |
| | | @RequestParam("paydate") String payDate, |
| | | @RequestParam("approcode") String appCode, |
| | | @RequestParam("appcode") String appCode, |
| | | @RequestParam("skey") String receivedSkey, |
| | | HttpServletResponse response) throws IOException{ |
| | | Model model) { |
| | | |
| | | // 计算 skey 验证 |
| | | // 验证skey以确保数据完整性 |
| | | String calculatedSkey = calculateSkey(tranId, orderId, status, domain, amount, currency, payDate, appCode); |
| | | MallOrderInfo mallOrderInfo = ValidateEntityUtils |
| | | .ensureColumnReturnEntity(orderId, MallOrderInfo::getId, mallOrderInfoMapper::selectOne, "订单不存在"); |
| | | log.info("callback status: {}", status); |
| | | log.info("callback skey: {}", receivedSkey); |
| | | log.info("callback calculatedSkey: {}", calculatedSkey); |
| | | log.info("callback payResult: {}", mallOrderInfo.getPayResult()); |
| | | if("1".equals(mallOrderInfo.getPayResult())){ |
| | | response.sendRedirect("/pages/order/pay/paySuccess?amount="+amount+"&type=3"); |
| | | return; |
| | | } |
| | | |
| | | // 将支付结果信息传递给支付成功页面 |
| | | model.addAttribute("amount", amount); |
| | | model.addAttribute("orderId", orderId); |
| | | model.addAttribute("tranId", tranId); |
| | | model.addAttribute("status", status); |
| | | model.addAttribute("currency", currency); |
| | | model.addAttribute("payDate", payDate); |
| | | |
| | | if (!calculatedSkey.equalsIgnoreCase(receivedSkey)) { |
| | | // 记录安全警告日志 |
| | | throw new FebsException("订单回调失败,---"+orderId); |
| | | } |
| | | if ("00".equals(status)) { |
| | | updateOrderStatus(orderId, status, amount, payDate, tranId); |
| | | response.sendRedirect("/pages/order/pay/paySuccess?amount="+amount+"&type=3"); |
| | | return; |
| | | } |
| | | updateOrderStatus(orderId, status, amount, payDate, tranId); |
| | | |
| | | // 跳转到支付成功页面 |
| | | return "payment-success"; |
| | | } |
| | | |
| | | private String calculateSkey(String tranId, String orderId, String status, |