【微信点餐】-- 发起支付

1.查询订单

2.发起支付

        @GetMapping("/create")
        public ModelAndView create(@RequestParam("orderId") String orderId,
                @RequestParam("returnUrl") String returnUrl,
                Map<String, Object> map) {
            //1.查询订单
            OrderDTO orderDTO = orderService.findOne(orderId);
            if (orderDTO == null) {
                throw new SellException(ResultEnum.ORDER_NOT_EXIST);
            }
            //2.发起支付
            PayResponse payResponse = payServices.create(orderDTO);
            map.put("payResponse", payResponse);
        map.put("returnUrl",returnUrl);
        //ModelAndView方法有很多,可以传不同参数,返回不同的结果类型
        return new ModelAndView("pay/create", map);
    }

将参数注入到模板中去

    1.在参数中添加Map<String,Object> map;

    2.使用freemarker实现参数注入的方式:

                测试: <h1>这里是模板的标题${orderId}</h1>  -- 普通参数 

注意:double与decimal类型的比较,不要用以下方式

!orderDTO.getOrderAmount().equals(payResponse.getOrderAmount())

double和double类型的比较也不要使用上述方式

可采用以下方式来进行比较

扫描二维码关注公众号,回复: 1757177 查看本文章

orderDTO.getOrderAmount().compareTo(new BigDecimal(payResponse.getOrderAmount())) != 0

通过上述方法比较金额,还是会出现问题:


为解决这个问题,可以考虑两个金额相减,减后结果<0.01,则视为相等,且不会存在精度不一致的问题。

!MathUtil.equals(payResponse.getOrderAmount(),orderDTO.getOrderAmount().doubleValue())


猜你喜欢

转载自blog.csdn.net/qqxyy99/article/details/79875624
今日推荐