zhangjian
2023-08-04 e9f67a375a12358326a1d37d8e7cb3ee7b2da565
去掉uavauth注解
已修改3个文件
40 ■■■■■ 文件已修改
ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/java/com/ruoyi/utils/forest/UavClient.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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.*;
ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java
@@ -28,6 +28,7 @@
    //token 登陆后每次请求,在header中携带
    private String token;//登录成功返回的token
    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();
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);
}