zhangjian
2023-07-11 7c2578e6a5b451a4c1c129b678b23cdb36c1620f
ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java
@@ -20,7 +20,7 @@
import java.util.Map;
@Service
public class UavService implements IUavService {
public class UavService {
    public static final String USERNAME = "ardbailu";//用户名
    public static final String PASSWORD = "ardkj12345";//密码
    public static final String SALT = "0123456789012345";//盐
@@ -36,7 +36,6 @@
        this.login();
    }
    @Override
    public String doUavRequest(HttpMethod method, String url, String data) {
        String res = null;
        Method requestMethod = null;
@@ -57,9 +56,9 @@
            try {//再次调用接口
                res = (String) requestMethod.invoke(this.uavClient, url, this.token, data);
            } catch (IllegalAccessException ex) {
                throw new RuntimeException(ex);
                ex.printStackTrace();
            } catch (InvocationTargetException ex) {
                throw new RuntimeException(ex);
                ex.printStackTrace();
            }
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
@@ -68,7 +67,6 @@
        return res;
    }
    @Override
    public void login() {
        String codedPassword = this.Encrypt(PASSWORD, SALT);
        String body = "{\"username\":\"" + USERNAME + "\",\"password\":\"" + codedPassword + "\"}";
@@ -82,21 +80,19 @@
        } catch (ForestNetworkException e) {
            e.printStackTrace();
        } catch (JsonMappingException e) {
            throw new RuntimeException(e);
            e.printStackTrace();
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
            e.printStackTrace();
        }
    }
    public String Encrypt(String sSrc, String sKey) {
        if (sKey == null) {
            System.out.print("Key为空null");
            return null;
        }
        // 判断Key是否为16位
        if (sKey.length() != 16) {
            System.out.print("Key长度不是16位");
            return null;
        }
        byte[] encrypted = null;
@@ -108,7 +104,6 @@
            encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
        } catch (Exception e) {
            e.printStackTrace();
            ;
        }
        return new Base64().encodeToString(encrypted);//此处使用BASE64做转码功能,同时能起到2次加密的作用。
    }