xiongzhu vor 3 Jahren
Ursprung
Commit
30d491570e

+ 112 - 15
src/main/java/com/izouma/nineth/service/OrderPayService.java

@@ -78,25 +78,27 @@ public class OrderPayService {
         if (order.getStatus() != OrderStatus.NOT_PAID) {
             throw new BusinessException("订单状态错误");
         }
-//        switch (PAY_CHANNEL) {
-//            case Constants.PayChannel.SAND:
-//                return sandPayService.pay(orderId + "", order.getName(), order.getTotalPrice(),
-//                        order.getCreatedAt().plusMinutes(3), "order");
-//            case Constants.PayChannel.HM:
-//                return hmPayService.requestAlipay(orderId + "", order.getTotalPrice(), order.getName(),
-//                        HMPayService.getTimeout(order.getCreatedAt(), 180), Constants.OrderNotifyType.ORDER,
-//                        generalProperties.getHost() + "/9th/orderDetail?id=" + orderId);
-//        }
-//        throw new BusinessException(Constants.PAY_ERR_MSG);
+        switch (PAY_CHANNEL) {
+            case Constants.PayChannel.SAND:
+                return sandPayService.pay(orderId + "", order.getName(), order.getTotalPrice(),
+                        order.getCreatedAt().plusMinutes(3), "order");
+            case Constants.PayChannel.HM:
+                return hmPayService.requestAlipay(orderId + "", order.getTotalPrice(), order.getName(),
+                        HMPayService.getTimeout(order.getCreatedAt(), 180), Constants.OrderNotifyType.ORDER,
+                        generalProperties.getHost() + "/9th/orderDetail?id=" + orderId);
+        }
+        throw new BusinessException(Constants.PAY_ERR_MSG);
+    }
 
+    private String aliRequest(Long orderId, BigDecimal amount, String subject, String type) {
         AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
         request.setNotifyUrl(alipayProperties.getNotifyUrl());
         JSONObject bizContent = new JSONObject();
         bizContent.put("out_trade_no", orderId + "");
-        bizContent.put("total_amount", order.getTotalPrice());
-        bizContent.put("subject", order.getName());
+        bizContent.put("total_amount", amount);
+        bizContent.put("subject", subject);
         JSONObject body = new JSONObject();
-        body.put("type", Constants.OrderNotifyType.ORDER);
+        body.put("type", type);
         body.put("orderId", orderId);
         bizContent.put("body", body.toString());
 
@@ -108,12 +110,22 @@ public class OrderPayService {
             e.printStackTrace();
             throw new BusinessException(Constants.PAY_ERR_MSG, e.getErrMsg());
         }
-        String qrCode;
         if (response.isSuccess()) {
-            qrCode = response.getQrCode();
+            return response.getQrCode();
         } else {
             throw new BusinessException(response.getSubMsg());
         }
+    }
+
+    @Cacheable(value = "payOrder", key = "'order#'+#orderId")
+    public String payOrderAli(Long orderId) {
+        Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
+        if (order.getStatus() != OrderStatus.NOT_PAID) {
+            throw new BusinessException("订单状态错误");
+        }
+
+        String qrCode = aliRequest(orderId, order.getTotalPrice(), order.getName(), Constants.OrderNotifyType.ORDER);
+
         String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("User-Agent");
         if (ua.toLowerCase().contains("micromessenger")) {
             return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder.encode(qrCode, StandardCharsets.UTF_8)
@@ -211,6 +223,25 @@ public class OrderPayService {
         throw new BusinessException(Constants.PAY_ERR_MSG);
     }
 
+    @Cacheable(value = "payOrder", key = "'gift#'+#orderId")
+    public String payGiftAli(Long orderId) {
+        GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
+        if (order.getStatus() != OrderStatus.NOT_PAID) {
+            throw new BusinessException("订单状态错误");
+        }
+
+        String qrCode = aliRequest(orderId, order.getGasPrice(), "转赠", Constants.OrderNotifyType.GIFT);
+
+        String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("User-Agent");
+        if (ua.toLowerCase().contains("micromessenger")) {
+            return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder.encode(qrCode, StandardCharsets.UTF_8)
+                    + "&orderId=" + orderId + "&type=gift&returnUrl="
+                    + URLEncoder.encode(generalProperties.getHost() + "/9th/store", StandardCharsets.UTF_8);
+        } else {
+            return "alipays://platformapi/startapp?saId=10000007&qrcode=" + qrCode;
+        }
+    }
+
     @Cacheable(value = "payOrder", key = "'gift#'+#orderId")
     public String payGiftQuick(Long orderId) {
         GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
@@ -282,6 +313,25 @@ public class OrderPayService {
         throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
     }
 
+    @Cacheable(value = "payOrder", key = "'mintOrder#'+#orderId")
+    public String payMintAli(Long orderId) {
+        MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
+        if (order.getStatus() != MintOrderStatus.NOT_PAID) {
+            throw new BusinessException("订单状态错误");
+        }
+
+        String qrCode = aliRequest(orderId, order.getGasPrice(), "铸造活动:" + order.getMintActivityId(), Constants.OrderNotifyType.MINT);
+
+        String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("User-Agent");
+        if (ua.toLowerCase().contains("micromessenger")) {
+            return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder.encode(qrCode, StandardCharsets.UTF_8)
+                    + "&orderId=" + orderId + "&type=mintOrder&returnUrl="
+                    + URLEncoder.encode(generalProperties.getHost() + "/9th/store", StandardCharsets.UTF_8);
+        } else {
+            return "alipays://platformapi/startapp?saId=10000007&qrcode=" + qrCode;
+        }
+    }
+
     @Cacheable(value = "payOrder", key = "'mintOrder#'+#orderId")
     public String payMintQuick(Long orderId) {
         MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
@@ -375,6 +425,34 @@ public class OrderPayService {
         throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
     }
 
+    public String payRechargeAli(Long userId, BigDecimal amount) {
+        BigDecimal minAmount = sysConfigService.getBigDecimal("min_recharge_amount");
+        if (amount.compareTo(minAmount) < 0) {
+            throw new BusinessException("充值金额不能小于" + minAmount);
+        }
+        if (amount.compareTo(new BigDecimal("50000")) > 0) {
+            throw new BusinessException("充值金额不能大于50000");
+        }
+        RechargeOrder order = RechargeOrder.builder()
+                .id(snowflakeIdWorker.nextId())
+                .userId(userId)
+                .amount(amount)
+                .status(OrderStatus.NOT_PAID)
+                .build();
+        rechargeOrderRepo.save(order);
+
+        String qrCode = aliRequest(order.getId(), order.getAmount(), "余额充值", Constants.OrderNotifyType.RECHARGE);
+
+        String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("User-Agent");
+        if (ua.toLowerCase().contains("micromessenger")) {
+            return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder.encode(qrCode, StandardCharsets.UTF_8)
+                    + "&orderId=" + order.getId() + "&type=recharge&returnUrl="
+                    + URLEncoder.encode(generalProperties.getHost() + "/9th/store", StandardCharsets.UTF_8);
+        } else {
+            return "alipays://platformapi/startapp?saId=10000007&qrcode=" + qrCode;
+        }
+    }
+
     public Map<String, Object> rechargeAgreement(Long userId, BigDecimal amount, String bindCardId) {
         BigDecimal minAmount = sysConfigService.getBigDecimal("min_recharge_amount");
         if (amount.compareTo(minAmount) < 0) {
@@ -519,6 +597,25 @@ public class OrderPayService {
         throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
     }
 
+    @Cacheable(value = "payOrder", key = "'auctionOrder#'+#orderId")
+    public String payAuctionAli(Long orderId) {
+        AuctionOrder order = auctionOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
+        if (order.getStatus() != AuctionOrderStatus.NOT_PAID) {
+            throw new BusinessException("订单状态错误");
+        }
+
+        String qrCode = aliRequest(orderId, order.getTotalPrice(), "拍卖:" + order.getName(), Constants.OrderNotifyType.AUCTION);
+
+        String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("User-Agent");
+        if (ua.toLowerCase().contains("micromessenger")) {
+            return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder.encode(qrCode, StandardCharsets.UTF_8)
+                    + "&orderId=" + orderId + "&type=auctionOrder&returnUrl="
+                    + URLEncoder.encode(generalProperties.getHost() + "/9th/store", StandardCharsets.UTF_8);
+        } else {
+            return "alipays://platformapi/startapp?saId=10000007&qrcode=" + qrCode;
+        }
+    }
+
     @Cacheable(value = "payOrder", key = "'auctionOrder#'+#orderId")
     public String payAuctionQuick(Long orderId) {
         AuctionOrder order = auctionOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));

+ 30 - 0
src/main/java/com/izouma/nineth/web/OrderPayControllerV2.java

@@ -35,6 +35,12 @@ public class OrderPayControllerV2 {
         return orderPayService.payOrder(id);
     }
 
+    @RequestMapping(value = "/ali")
+    @ResponseBody
+    public String payOrderAli(Long id) {
+        return orderPayService.payOrderAli(id);
+    }
+
     @RequestMapping(value = "/alipay_wx")
     public String payOrderAlipayWx(Long id, Model model) {
         Order order = orderRepo.findById(id).orElseThrow(new BusinessException("订单不存在"));
@@ -88,6 +94,12 @@ public class OrderPayControllerV2 {
         return orderPayService.payGiftOrder(id);
     }
 
+    @RequestMapping(value = "/gift/ali")
+    @ResponseBody
+    public String payGiftOrderAli(Long id) {
+        return orderPayService.payGiftAli(id);
+    }
+
     @RequestMapping(value = "/gift/alipay_wx")
     public String payGiftOrderAlipayWx(Long id, Model model) {
         String payUrl = orderPayService.payGiftOrder(id);
@@ -126,6 +138,12 @@ public class OrderPayControllerV2 {
         return orderPayService.payMintOrder(id);
     }
 
+    @RequestMapping(value = "/mint/ali")
+    @ResponseBody
+    public String payMintAli(Long id) {
+        return orderPayService.payMintAli(id);
+    }
+
     @RequestMapping(value = "/mint/alipay_wx")
     public String payMintOrderAlipayWx(Long id, Model model) {
         String payUrl = orderPayService.payMintOrder(id);
@@ -164,6 +182,12 @@ public class OrderPayControllerV2 {
         return orderPayService.recharge(SecurityUtils.getAuthenticatedUser().getId(), amount);
     }
 
+    @RequestMapping(value = "/recharge/ali")
+    @ResponseBody
+    public String rechargeAli(@RequestParam BigDecimal amount) {
+        return orderPayService.payRechargeAli(SecurityUtils.getAuthenticatedUser().getId(), amount);
+    }
+
     @RequestMapping(value = "/recharge/agreement")
     @ResponseBody
     public Map<String, Object> payRechargeAgreement(@RequestParam Long userId, @RequestParam BigDecimal amount,
@@ -189,6 +213,12 @@ public class OrderPayControllerV2 {
         return orderPayService.payAuctionOrder(id);
     }
 
+    @RequestMapping(value = "/auction/ali")
+    @ResponseBody
+    public String payAuctionOrderAli(Long id) {
+        return orderPayService.payAuctionAli(id);
+    }
+
     @RequestMapping(value = "/auction/alipay_wx", method = RequestMethod.GET)
     public String payAuctionOrderAlipayWx(Long id, Model model) {
         String payUrl = orderPayService.payAuctionOrder(id);