From 7f8ea22902fe145fb266df3cf69cbd533d768fbb Mon Sep 17 00:00:00 2001
From: Administrator <1101184511@qq.com>
Date: 星期三, 12 二月 2025 23:56:07 +0800
Subject: [PATCH] 区域封禁

---
 src/main/java/com/taoke/autopay/controller/WebApiController.java |   37 ++++++++++++++++++++++++++++++++-----
 1 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/taoke/autopay/controller/WebApiController.java b/src/main/java/com/taoke/autopay/controller/WebApiController.java
index 07aa96b..76d23cd 100644
--- a/src/main/java/com/taoke/autopay/controller/WebApiController.java
+++ b/src/main/java/com/taoke/autopay/controller/WebApiController.java
@@ -49,7 +49,7 @@
     private SystemConfigService systemConfigService;
 
 
-    private void addKey(SubmitKeyInfo keyInfo, Long wxUid) throws KeyVerifyException, KeyOrderException, WxOrderCountException {
+    private void addKey(SubmitKeyInfo keyInfo, Long wxUid, String ip, IPUtil.IPInfo ipInfo) throws KeyVerifyException, KeyOrderException, WxOrderCountException {
 
         // 鏌ヨ娌℃湁澶勭悊鐨勬暟閲�
         long notProcessCount = keyOrderService.countUserNotDoOrder(wxUid, new Date(System.currentTimeMillis() - 1000*60*30));
@@ -97,8 +97,6 @@
                 throw new KeyVerifyException(KeyVerifyException.CODE_COMMON, e.getMessage());
             }
         }
-
-
         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) {
@@ -122,6 +120,7 @@
         }
     }
 
+    private Map<String, IPUtil.IPInfo> ipInfoMap=new HashMap<>();
     @ResponseBody
     @RequestMapping(value = "submitKeyV4")
     public String submitKeyV4(SubmitKeyInfo keyInfo, HttpSession session, HttpServletRequest request) {
@@ -130,6 +129,25 @@
         WxUserInfo user = (WxUserInfo) session.getAttribute(Constant.SESSION_KEY_USER);
         if (StringUtil.isNullOrEmpty(keyInfo.getKey())) {
             return JsonUtil.loadFalseResult("璇蜂笂浼爇ey");
+        }
+        String ip = IPUtil.getRemotIP(request);
+        keyInfo.setIp(ip);
+        if(!ipInfoMap.containsKey(ip)){
+            try {
+                IPUtil.IPInfo ipInfo =  IPUtil.getLocalIPInfo(ip);
+                ipInfoMap.put(ip, ipInfo);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        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 {
@@ -165,8 +183,9 @@
             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)));
         try {
-            addKey(keyInfo, user.getId());
+            addKey(keyInfo, user.getId(),ip, ipInfoMap.get(ip));
             return JsonUtil.loadTrueResult("");
         } catch (KeyOrderException e) {
             e.printStackTrace();
@@ -226,7 +245,15 @@
 
                 wxLogger.info("浠巗ession璇诲彇鍒発ey锛歿}", alipayKeyInfo);
                 if (alipayKeyInfo != null) {
-                    addKey(alipayKeyInfo, user.getId());
+                    if(!ipInfoMap.containsKey(alipayKeyInfo.getIp())){
+                        try {
+                            IPUtil.IPInfo ipInfo =  IPUtil.getLocalIPInfo(alipayKeyInfo.getIp());
+                            ipInfoMap.put(alipayKeyInfo.getIp(), ipInfo);
+                        } catch (Exception e) {
+                            throw new RuntimeException(e);
+                        }
+                    }
+                    addKey(alipayKeyInfo, user.getId(),alipayKeyInfo.getIp(),ipInfoMap.get(alipayKeyInfo.getIp()));
                 }
                 response.sendRedirect(successLink);
                 return;

--
Gitblit v1.8.0