From 5f92b2034f84caeab9cb6efc61ecbe22407935b4 Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期二, 16 一月 2024 12:14:03 +0800
Subject: [PATCH] 优化主库协议,支持路由

---
 src/main/java/com/fzzy/gateway/hx2023/controller/GatewayController.java |   58 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/fzzy/gateway/hx2023/controller/GatewayController.java b/src/main/java/com/fzzy/gateway/hx2023/controller/GatewayController.java
index 8ad1617..fd4433d 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/controller/GatewayController.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/controller/GatewayController.java
@@ -4,12 +4,17 @@
 import com.fzzy.api.utils.ContextUtil;
 import com.fzzy.api.utils.RedisConst;
 import com.fzzy.api.utils.RedisUtil;
+import com.fzzy.gateway.entity.GatewayConf;
 import com.fzzy.gateway.hx2023.data.GatewayAuthData;
+import com.fzzy.gateway.service.GatewayConfService;
+import com.ld.license.LicenseVerify;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.util.List;
+import java.util.UUID;
 
 /**
  *
@@ -21,6 +26,9 @@
 
     @Resource
     private RedisUtil redisUtil;
+    @Resource
+    private GatewayConfService confService;
+
 
     /**
      * 閴存潈鎺ュ彛
@@ -39,29 +47,59 @@
     public @ResponseBody
     JSONObject authorize(@RequestBody GatewayAuthData data) {
 
-        log.debug("============閴存潈==========={}--{}", data.getUsername(), data.getPassword());
+
+        List<GatewayConf> list = confService.getCacheConfList();
+
+        JSONObject json = new JSONObject();
+        json.put("timestamp", System.currentTimeMillis());
+        if (null == list || list.isEmpty()) {
+            json.put("code", 500);
+            json.put("message", "鏈幏鍙栫綉鍏充俊鎭�");
+            return json;
+        }
+
+        String gatewayId = null;
+        for (GatewayConf conf : list) {
+            if (data.getUsername().equals(conf.getGatewayUsername()) && data.getPassword().equals(conf.getGatewayPassword())) {
+                gatewayId = conf.getGatewayId();
+                break;
+            }
+        }
+
+        if (null == gatewayId) {
+            json.put("code", 500);
+            json.put("message", "鏈尮閰嶅埌鐢ㄦ埛鍚嶅拰瀵嗙爜");
+            return json;
+        }
 
 
-        //TODO 楠岃瘉鐢ㄦ埛鍚嶅拰瀵嗙爜
+        String token = "fzzy-" + UUID.randomUUID();
 
-
-        String token = ContextUtil.getUUID();
+        log.debug("============閴存潈==========={}--{}--{}", data.getUsername(), data.getPassword(), token);
 
         this.updateGatewayToken(token, data.getUsername());
 
-        JSONObject json = new JSONObject();
-
         JSONObject result = new JSONObject();
-
         result.put("token", token);
-
         json.put("result", result);
         json.put("message", "鎴愬姛");
         json.put("status", 0);
         json.put("code", 200);
-        json.put("timestamp", System.currentTimeMillis());
+        try{
+            LicenseVerify licenseVerify = new LicenseVerify();
+            //鏍¢獙璇佷功鏄惁鏈夋晥
+            boolean verifyResult = licenseVerify.verify();
 
-        return json;
+            if(verifyResult){
+                return json;
+            }else{
+                log.error("璇佷功楠岃瘉澶辫触!鎷掔粷璁块棶");
+                return null;
+            }
+        }catch (Exception e){
+            log.error("璇佷功楠岃瘉澶辫触:" + e.getMessage(),e);
+            return null;
+        }
     }
 
     public void updateGatewayToken(String token, String username) {

--
Gitblit v1.9.3