xiongzhu пре 4 година
родитељ
комит
9c7d2ea513

+ 29 - 4
src/main/java/com/izouma/nineth/service/SandPayService.java

@@ -18,7 +18,6 @@ import com.izouma.nineth.utils.SnowflakeIdWorker;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.lang.StringUtils;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
@@ -28,9 +27,7 @@ import java.net.URLDecoder;
 import java.nio.charset.StandardCharsets;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
-import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -154,7 +151,7 @@ public class SandPayService {
         return requestServer(header, body, "https://cashier.sandpay.com.cn/qr/api/order/create");
     }
 
-    public JSONObject requestUnion(String orderId, BigDecimal amount, String subject, String desc,
+    public JSONObject requestQuick(String orderId, BigDecimal amount, String subject, String desc,
                                    int timeout, String extend, String frontUrl) {
         if (orderId.length() < 12) {
             for (int i = orderId.length(); i < 12; i++) {
@@ -261,6 +258,34 @@ public class SandPayService {
         return res.getJSONObject("body").getString("qrCode");
     }
 
+    @Cacheable(value = "sandPayQuick", key = "#orderId")
+    public String payOrderQuick(Long orderId) {
+        Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
+        if (order.getStatus() != OrderStatus.NOT_PAID) {
+            throw new BusinessException("订单状态错误");
+        }
+        JSONObject extend = new JSONObject();
+        extend.put("type", "order");
+        extend.put("id", orderId);
+
+        JSONObject res = requestQuick(orderId.toString(), order.getTotalPrice(), order.getName(), order.getName(),
+                180, extend.toJSONString(), generalProperties.getHost() + "/orderDetail?id=" + orderId);
+        if (res == null)
+            throw new BusinessException("下单失败,请稍后再试");
+
+        if (!"000000".equals(res.getJSONObject("head").getString("respCode"))) {
+            String msg = res.getJSONObject("head").getString("respMsg");
+            if (msg.contains("超限")) {
+                throw new BusinessException("超过商户单日额度");
+            }
+            if (msg.contains("商户状态")) {
+                throw new BusinessException("超过商户单日额度");
+            }
+            throw new BusinessException(msg);
+        }
+        return res.getJSONObject("body").getString("credential");
+    }
+
     @Cacheable(value = "sandPay", key = "#orderId")
     public String payGiftOrder(Long orderId) {
         GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));

+ 8 - 0
src/main/java/com/izouma/nineth/service/SysConfigService.java

@@ -90,6 +90,14 @@ public class SysConfigService {
                     .value("FULL")
                     .build());
         }
+        if (sysConfigRepo.findByName("enable_sand_quick").isEmpty()) {
+            sysConfigRepo.save(SysConfig.builder()
+                    .name("enable_sand_quick")
+                    .desc("使用衫德h5快捷支付")
+                    .type(SysConfig.ValueType.BOOLEAN)
+                    .value("FALSE")
+                    .build());
+        }
         SearchMode searchMode = SearchMode.valueOf(sysConfigRepo.findByName("default_search_mode").get().getValue());
         JpaUtils.setDefaultSearchMode(searchMode);
     }

+ 9 - 0
src/main/java/com/izouma/nineth/web/OrderPayController.java

@@ -10,6 +10,7 @@ import com.izouma.nineth.enums.OrderStatus;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.OrderRepo;
 import com.izouma.nineth.service.*;
+import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
@@ -99,6 +100,14 @@ public class OrderPayController {
         return "PayOrderPC";
     }
 
+    @ApiOperation("衫德h5快捷")
+    @RequestMapping(value = "/sandQuick", method = RequestMethod.GET, produces = "text/html")
+    @ResponseBody
+    public String sandQuick(@RequestParam Long id, Model model) throws BaseAdaPayException {
+//        return (String) orderService.payAdapay(id, "alipay_wap", null);
+        return sandPayService.payOrderQuick(id);
+    }
+
     @RequestMapping(value = "/gift/alipay_h5", method = RequestMethod.GET)
     @ResponseBody
     public String payGiftOrderAlipayH5(Long id, Model model) throws BaseAdaPayException {

+ 1 - 6
src/main/java/com/izouma/nineth/web/SandPayController.java

@@ -2,7 +2,6 @@ package com.izouma.nineth.web;
 
 import cn.com.sandpay.cashier.sdk.CertUtil;
 import cn.com.sandpay.cashier.sdk.CryptoUtil;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.enums.PayMethod;
@@ -10,22 +9,18 @@ import com.izouma.nineth.event.OrderNotifyEvent;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.service.GiftOrderService;
 import com.izouma.nineth.service.MintOrderService;
-import com.izouma.nineth.service.OrderService;
 import com.izouma.nineth.service.SandPayService;
-import com.izouma.nineth.utils.SecurityUtils;
 import com.izouma.nineth.utils.SnowflakeIdWorker;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
-import java.time.LocalDateTime;
 
 @RestController
 @RequestMapping("/sandpay")
@@ -42,7 +37,7 @@ public class SandPayController {
 
     @GetMapping(value = "/testUnion", produces = "text/html")
     public String testUnion() {
-        JSONObject res = sandPayService.requestUnion(snowflakeIdWorker.nextId() + "", new BigDecimal("0.01"),
+        JSONObject res = sandPayService.requestQuick(snowflakeIdWorker.nextId() + "", new BigDecimal("0.01"),
                 "话费充值", "话费充值", 180, "", "https://test.raex.vip/9th/home");
         if (res.getJSONObject("head").getString("respCode").equals("000000")) {
             return res.getJSONObject("body").getString("credential");

+ 5 - 0
src/main/java/com/izouma/nineth/web/SysConfigController.java

@@ -58,6 +58,11 @@ public class SysConfigController extends BaseController {
         return sysConfigRepo.findByName(id).orElseThrow(new BusinessException("无记录"));
     }
 
+    @GetMapping("/getValue/{id}")
+    public String getValue(@PathVariable String id) {
+        return sysConfigRepo.findByName(id).map(SysConfig::getValue).orElse(null);
+    }
+
     @GetMapping("/getDecimal/{id}")
     public BigDecimal getDecimal(@PathVariable String id) {
         return sysConfigService.getBigDecimal(id);