From 7c733388b5e071fedd9b6b2ab4b000f0a5416784 Mon Sep 17 00:00:00 2001
From: Administrator <1101184511@qq.com>
Date: 星期一, 17 二月 2025 01:22:17 +0800
Subject: [PATCH] 口令提交过渡页

---
 src/main/java/com/taoke/autopay/controller/WebApiController.java |  111 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 88 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/taoke/autopay/controller/WebApiController.java b/src/main/java/com/taoke/autopay/controller/WebApiController.java
index 7b930dd..e453bcd 100644
--- a/src/main/java/com/taoke/autopay/controller/WebApiController.java
+++ b/src/main/java/com/taoke/autopay/controller/WebApiController.java
@@ -9,6 +9,7 @@
 import com.taoke.autopay.exception.KeyOrderException;
 import com.taoke.autopay.exception.KeyVerifyException;
 import com.taoke.autopay.exception.WxOrderCountException;
+import com.taoke.autopay.manager.PayCountVerifyManager;
 import com.taoke.autopay.service.KeyOrderService;
 import com.taoke.autopay.service.SystemConfigService;
 import com.taoke.autopay.service.WxUserService;
@@ -17,6 +18,7 @@
 import net.sf.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -47,20 +49,22 @@
 
     @Resource
     private SystemConfigService systemConfigService;
+    @Autowired
+    private PayCountVerifyManager payCountVerifyManager;
 
 
-    private void addKey(SubmitKeyInfo keyInfo, Long wxUid) throws KeyVerifyException, KeyOrderException, WxOrderCountException {
+    private KeyOrder addKey(SubmitKeyInfo keyInfo, Long wxUid) throws KeyVerifyException, KeyOrderException, WxOrderCountException {
 
         // 鏌ヨ娌℃湁澶勭悊鐨勬暟閲�
-        long notProcessCount = keyOrderService.countUserNotDoOrder(wxUid, new Date(System.currentTimeMillis() - 1000*60*30));
-        if(notProcessCount>0){
+        long notProcessCount = keyOrderService.countUserNotDoOrder(wxUid, new Date(System.currentTimeMillis() - 1000 * 60 * 30));
+        if (notProcessCount > 0) {
             throw new WxOrderCountException("涓婁竴涓彛浠ゅ皻鏈鐞嗗畬锛�");
         }
 
         // 瑙f瀽閾炬帴
         List<String> urllist = UrlUtils.parseUrlsFromText(keyInfo.getKey());
         String verifyAlipayKey = systemConfigService.getValueCache(SystemConfigKeyEnum.ALIPAY_KEY_VERIFY);
-        DYOrderDto orderDto =null;
+        DYOrderDto orderDto = null;
         int orderType = Constant.ORDER_TYPE_UNKNOWN;
         if (verifyAlipayKey != null && verifyAlipayKey.trim().equalsIgnoreCase("1")) {
             try {
@@ -97,7 +101,7 @@
                 throw new KeyVerifyException(KeyVerifyException.CODE_COMMON, e.getMessage());
             }
         }
-        KeyOrder order = keyOrderService.addKeyOrder(keyInfo, wxUid, TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT),orderType, orderDto);
+        KeyOrder order = keyOrderService.addKeyOrder(keyInfo, wxUid, TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT), orderType, orderDto);
         Long uid = keyOrderService.getCanDistributeUid(Constant.MAX_PAY_ACCOUNT_QUEUE_SIZE);
         if (uid != null) {
             KeyOrder orderUpdate = new KeyOrder();
@@ -106,8 +110,7 @@
             orderUpdate.setDistributeTime(new Date());
             keyOrderService.update(orderUpdate);
         }
-
-
+        return order;
     }
 
     private void verifySubmitKey(String key) throws Exception {
@@ -120,7 +123,8 @@
         }
     }
 
-    private Map<String, IPUtil.IPInfo> ipInfoMap=new HashMap<>();
+    private Map<String, IPUtil.IPInfo> ipInfoMap = new HashMap<>();
+
     @ResponseBody
     @RequestMapping(value = "submitKeyV4")
     public String submitKeyV4(SubmitKeyInfo keyInfo, HttpSession session, HttpServletRequest request) {
@@ -132,9 +136,9 @@
         }
         String ip = IPUtil.getRemotIP(request);
         keyInfo.setIp(ip);
-        if(!ipInfoMap.containsKey(ip)){
+        if (!ipInfoMap.containsKey(ip)) {
             try {
-                IPUtil.IPInfo ipInfo =  IPUtil.getLocalIPInfo(ip);
+                IPUtil.IPInfo ipInfo = IPUtil.getLocalIPInfo(ip);
                 ipInfoMap.put(ip, ipInfo);
             } catch (Exception e) {
                 throw new RuntimeException(e);
@@ -142,13 +146,13 @@
         }
         keyInfo.setIpInfo(ipInfoMap.get(ip));
 
-        String citys =  systemConfigService.getValueCache(SystemConfigKeyEnum.FORBIDDEN_SUBMIT_CITYS);
-        if(citys!=null&&ipInfoMap.get(ip)!=null){
-           List<String> cityList = Arrays.asList(citys.split(","));
-           if(cityList.contains(ipInfoMap.get(ip).getCity())){
-               LogUtil.loggerDebug.warn("鍖哄煙灞忚斀锛歿}-{}", ip, new Gson().toJson(ipInfoMap.get(ip)));
-               return JsonUtil.loadFalseResult("鏆傛椂鏃犳硶涓婁紶鍙d护");
-           }
+        String citys = systemConfigService.getValueCache(SystemConfigKeyEnum.FORBIDDEN_SUBMIT_CITYS);
+        if (citys != null && ipInfoMap.get(ip) != null) {
+            List<String> cityList = Arrays.asList(citys.split(","));
+            if (cityList.contains(ipInfoMap.get(ip).getCity())) {
+                LogUtil.loggerDebug.warn("鍖哄煙灞忚斀锛歿}-{}", ip, new Gson().toJson(ipInfoMap.get(ip)));
+                return JsonUtil.loadFalseResult("鏆傛椂鏃犳硶涓婁紶鍙d护");
+            }
         }
 
         try {
@@ -184,10 +188,12 @@
             return JsonUtil.loadTrueResult(Constant.RESULT_CODE_NEED_LOGIN, root);
         }
         wxLogger.info("寰俊鏈夋巿鏉�:" + session.getId());
-        LogUtil.loggerDebug.warn("GEO淇℃伅锛歿}-{}-{}", user.getId(),ip, new Gson().toJson(ipInfoMap.get(ip)));
+        LogUtil.loggerDebug.warn("GEO淇℃伅锛歿}-{}-{}", user.getId(), ip, new Gson().toJson(ipInfoMap.get(ip)));
         try {
-            addKey(keyInfo, user.getId());
-            return JsonUtil.loadTrueResult("");
+            KeyOrder order = addKey(keyInfo, user.getId());
+            JSONObject data = new JSONObject();
+            data.put("id", order.getId());
+            return JsonUtil.loadTrueResult(data);
         } catch (KeyOrderException e) {
             e.printStackTrace();
             return JsonUtil.loadFalseResult(e.getMessage());
@@ -246,9 +252,9 @@
 
                 wxLogger.info("浠巗ession璇诲彇鍒発ey锛歿}", alipayKeyInfo);
                 if (alipayKeyInfo != null) {
-                    if(!ipInfoMap.containsKey(alipayKeyInfo.getIp())){
+                    if (!ipInfoMap.containsKey(alipayKeyInfo.getIp())) {
                         try {
-                            IPUtil.IPInfo ipInfo =  IPUtil.getLocalIPInfo(alipayKeyInfo.getIp());
+                            IPUtil.IPInfo ipInfo = IPUtil.getLocalIPInfo(alipayKeyInfo.getIp());
                             ipInfoMap.put(alipayKeyInfo.getIp(), ipInfo);
                         } catch (Exception e) {
                             throw new RuntimeException(e);
@@ -260,7 +266,6 @@
                 return;
             }
         } catch (Exception e) {
-            e.printStackTrace();
             wxLogger.error("鎺堟潈澶辫触锛歿}", e.getMessage());
             if (!StringUtil.isNullOrEmpty(referer)) {
                 Map<String, String> params = HttpUtil.getPramsFromUrl(referer);
@@ -271,4 +276,64 @@
         response.sendRedirect(failLink);
     }
 
+
+    /**
+     * 鏌ヨ鍙d护鎻愪氦缁撴灉
+     *
+     * @param id
+     * @param request
+     * @return
+     */
+    @ResponseBody
+    @RequestMapping(value = "queryKeyResult")
+    public String queryKeyResult(String id, HttpServletRequest request) {
+        KeyOrder keyOrder = keyOrderService.selectById(id);
+        if (keyOrder == null) {
+            return JsonUtil.loadFalseResult("鍙d护涓嶅瓨鍦�");
+        }
+        String desc = "";
+        switch (keyOrder.getState()) {
+            case KeyOrder.STATE_NOT_PROCESS:
+                if (keyOrder.getDistributeClientUid() == null) {
+                    desc = "鍙d护宸叉彁浜わ紝绛夊緟鏀粯涓�...";
+                } else {
+                    desc = "鏀粯鎺掗槦涓�...";
+                }
+                break;
+            case KeyOrder.STATE_NOT_PAY:
+                desc = "姝e湪鏀粯...";
+                break;
+            case KeyOrder.STATE_PAY:
+                desc = "鏀粯鎴愬姛";
+                break;
+            case KeyOrder.STATE_REJECT_PAY:
+                desc = keyOrder.getStateDesc();
+                break;
+        }
+        JSONObject data = new JSONObject();
+        data.put("state_desc", desc);
+        data.put("finish", keyOrder.getState() == KeyOrder.STATE_PAY || keyOrder.getState() == KeyOrder.STATE_REJECT_PAY ? 1 : 0);
+        return JsonUtil.loadTrueResult(data);
+    }
+
+    /**
+     * 鏌ヨ鏀粯鍓╀綑娆℃暟
+     *
+     * @param session
+     * @param request
+     * @return
+     */
+
+    @ResponseBody
+    @RequestMapping(value = "queryPayLeftCount")
+    public String queryPayLeftCount(HttpSession session, HttpServletRequest request) {
+        WxUserInfo user = (WxUserInfo) session.getAttribute(Constant.SESSION_KEY_USER);
+        if (user == null || user.getId() == null) {
+            return JsonUtil.loadFalseResult("鐢ㄦ埛灏氭湭鐧诲綍");
+        }
+        // 鏌ヨ鏀粯鍓╀綑娆℃暟
+        Map<Integer, Long> map = payCountVerifyManager.computeUserLeftPayCount(user.getId());
+        return JsonUtil.loadTrueResult(new Gson().toJson(map));
+    }
+
 }

--
Gitblit v1.8.0