zhangnaisong
2024-03-05 6bf71e7423a7420d7cbb4bd0dbb19a95171efa32
ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java
@@ -82,14 +82,14 @@
    }
    private void getUavConfig() {
        /*this.host = ConfigUtils.getConfigValue("uav_host");
        this.host = ConfigUtils.getConfigValue("uav_host");
        this.username = ConfigUtils.getConfigValue("uav_username");
        this.password = ConfigUtils.getConfigValue("uav_password");
        this.salt = ConfigUtils.getConfigValue("uav_salt");*/
        this.host = "http://112.98.126.2:6100/";
        this.salt = ConfigUtils.getConfigValue("uav_salt");
        /*this.host = "http://112.98.126.2:6100/";
        this.username = "znstest";
        this.password = "znstest";
        this.salt = "0123456789012345";
        this.salt = "0123456789012345";*/
        if (StringUtils.isEmpty(this.host) || StringUtils.isEmpty(this.username) || StringUtils.isEmpty(this.password) || StringUtils.isEmpty(this.salt)) {
            throw new RuntimeException("无人机参数配置缺失:");
        }
@@ -744,4 +744,41 @@
            return new HashMap();
        }
    }
    public Object addAlarm(String url, Map<String,Object> data) {
        String token = this.getToken();
        url = this.host + url;
        data.put("userName",this.username);
        Map<String,Object> resultMap = addAlarm(url,token, data);
        return resultMap;
    }
    public Map<String,Object> addAlarm(String url,String access_token,Map<String,Object> map){
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        OkHttpClient okHttpClient = new OkHttpClient();
        RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
        Request request = new Request.Builder().url(url).post(body).addHeader("x-auth-token",access_token).build();
        Response response = null;
        try {
            response = okHttpClient.newCall(request).execute();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        ResponseBody responseBody = response.body();
        try {
            String message = responseBody.string();// 响应体
            Map<String,Object> map0 = (Map<String, Object>) JSON.parse(message);
            return map0;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return new HashMap();
        }
    }
}