我正在尝试通过UPI超链接付款,例如

upi://pay?pa=abc@upi&pn=payeeName&tr=1234&tn=Pay%20to%20payeeName&am=1&mam=1&cu=INR&url=https://test.com/payment/orderId=123456
  • 我通过短信
  • 发送以上链接
  • 当我单击链接时,它将UPI应用程序列表显示为
  • 选项
  • 我选择了BHIM应用程序(也尝试过其他应用程序)
  • 然后完成付款,直到现在一切正常。

  • 在完成UPI付款之后,处理对https://test.com/payment/orderId=12345的“回调”请求的Spring Controller 不会被调用。

    那么如何在Java中正确获得UPI超链接付款的响应呢?

    编辑:

    这是 Controller 方法。我也尝试过@GetMapping而不是@PostMapping
    @PostMapping("/payment")
    public ModelAndView credPayment(HttpServletRequest request) {
    
        String key = request.getParameter("orderId");
        String txnId = request.getParameter("txnId");
        String responseCode = request.getParameter("responseCode");
        String approvalRefNo = request.getParameter("ApprovalRefNo");
        String status = request.getParameter("Status");
        String txnRef = request.getParameter("txnRef");
        System.out.println("Parameter Names");
        while (request.getParameterNames().hasMoreElements()) {
            System.out.println(request.getParameterNames().nextElement());
        }
    
        System.out.println("Header Names");
        while (request.getHeaderNames().hasMoreElements()) {
            System.out.println(request.getHeaderNames().nextElement());
        }
    
        System.out.println("txnId : "+txnId);
        System.out.println("responseCode : "+responseCode);
        System.out.println("ApprovalRefNo : "+approvalRefNo);
        System.out.println("Status : "+status);
        System.out.println("txnRef : "+txnRef);
    
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("redirect:/");
        return modelAndView;
    }
    

    最佳答案

    如果我正确理解,则您的重定向网址为

    https://test.com/payment/orderId=123456
    

    调用此方法时,您需要在 Controller 中获取订单ID值。

    然后尝试将您的方法更改为如下所示:
    @GetMapping(value = "/payment/{order}")
    public ModelAndView credPayment(@PathVariable("order") String order, HttpServletRequest request) {
        System.out.println(order); // prints orderId=123456
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("redirect:/");
        return modelAndView;
    }
    

    问题:

    您已将URL映射仅配置为/payment,因此此后的所有内容都将从该映射中排除,例如:/payment/sdfdsfs

    08-27 05:49