From e9f67a375a12358326a1d37d8e7cb3ee7b2da565 Mon Sep 17 00:00:00 2001
From: zhangjian <zhangjianrock@163.com>
Date: 星期五, 04 八月 2023 17:28:03 +0800
Subject: [PATCH] 去掉uavauth注解

---
 ard-work/src/main/java/com/ruoyi/utils/forest/UavClient.java                 |   11 +++++------
 ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java |   14 --------------
 ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java          |   15 ++++++++++++---
 3 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java b/ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java
index 076f54f..a8f40e1 100644
--- a/ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java
+++ b/ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java
@@ -1,30 +1,16 @@
 package com.ruoyi.device.uav.controller;
 
-import com.dtflys.forest.exceptions.ForestNetworkException;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.github.pagehelper.util.StringUtil;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.device.uav.service.UavService;
-import com.ruoyi.utils.forest.UavClient;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.codec.binary.StringUtils;
-import org.jetbrains.annotations.Nullable;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpMethod;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.PostConstruct;
-import javax.crypto.Cipher;
-import javax.crypto.spec.SecretKeySpec;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.*;
 
-import org.apache.commons.codec.binary.Base64;
 
 import static org.springframework.http.HttpMethod.*;
 
diff --git a/ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java b/ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java
index f2d3986..5af9367 100644
--- a/ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java
+++ b/ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java
@@ -28,6 +28,7 @@
 
     //token 鐧婚檰鍚庢瘡娆¤姹�,鍦╤eader涓惡甯�
     private String token;//鐧诲綍鎴愬姛杩斿洖鐨則oken
+    private Map uavUser;//鐧诲綍鐨勭敤鎴蜂俊鎭�
     private ObjectMapper om = new ObjectMapper();
     @Autowired
     private UavClient uavClient;
@@ -68,15 +69,23 @@
         return res;
     }
 
+    public Map getUavUser() {
+        if (this.uavUser==null){
+            this.login();
+        }
+        return this.uavUser;
+    }
+
     public void login() {
+        System.out.println("鐧诲綍鏃犱汉鏈哄閮ㄦ帴鍙�");
         String codedPassword = this.Encrypt(PASSWORD, SALT);
         String body = "{\"username\":\"" + USERNAME + "\",\"password\":\"" + codedPassword + "\"}";
         try {
             String res = uavClient.POST("login", null, body);
             Map resMap = om.readValue(res, Map.class);
-            Map data = (Map) resMap.get("data");
-            if (data != null) {
-                this.token = (String) data.get("access_token");
+            this.uavUser = (Map) resMap.get("data");
+            if (this.uavUser != null) {
+                this.token = (String) this.uavUser.get("access_token");
             }
         } catch (ForestNetworkException e) {
             e.printStackTrace();
diff --git a/ard-work/src/main/java/com/ruoyi/utils/forest/UavClient.java b/ard-work/src/main/java/com/ruoyi/utils/forest/UavClient.java
index 09179fe..8fcd0ad 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/forest/UavClient.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/forest/UavClient.java
@@ -11,16 +11,15 @@
 
     public static String IP = "http://112.98.126.2:6100/";
 
-    @UavAuth(token = "${token}")
     @Get(IP + "${url}")
-    String GET(@Var("url") String url, @Var("token") String token, @JSONBody String body);
+    String GET(@DataVariable("url") String url, @Header("x-auth-token") String token, @JSONBody String body);
 
-    @UavAuth(token = "${token}")
     @Post(IP + "${url}")
-    String POST(@Var("url") String url, @Var("token") String token, @JSONBody String body);
-    @UavAuth(token = "${token}")
+    String POST(@DataVariable("url") String url,  @Header("x-auth-token")  String token, @JSONBody String body);
+
     @Post(IP + "${url}")
-    String DELETE(@Var("url") String url, @Var("token") String token, @JSONBody String body);
+    String DELETE(@DataVariable("url") String url,  @Header("x-auth-token") String token, @JSONBody String body);
+
 
 
 }

--
Gitblit v1.9.3