| | |
| | | |
| | | private String salt; //盐 |
| | | |
| | | private String host;//uav服务器 |
| | | private String host;//uav服务器11 |
| | | |
| | | |
| | | private Map uavUser;//登录的用户信息 |
| | |
| | | |
| | | private void getUavConfig() { |
| | | this.host = ConfigUtils.getConfigValue("uav_host"); |
| | | this.username = ConfigUtils.getConfigValue("uav_username"); |
| | | this.password = ConfigUtils.getConfigValue("uav_password"); |
| | | this.salt = ConfigUtils.getConfigValue("uav_salt"); |
| | | if (StringUtils.isEmpty(this.host) || StringUtils.isEmpty(this.username) || StringUtils.isEmpty(this.password) || StringUtils.isEmpty(this.salt)) { |
| | | throw new RuntimeException("无人机参数配置缺失:"); |
| | |
| | | } |
| | | |
| | | public String doUavRequest(HttpMethod method, String url, String data) { |
| | | |
| | | getUavConfig(); |
| | | String res = null; |
| | | Method requestMethod = null; |
| | | //获取method |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | //执行method |
| | | this.getToken();//获取token验证,验证token有效性 |
| | | // this.getToken();//获取token验证,验证token有效性 |
| | | try { |
| | | String token = this.getToken(); |
| | | res = (String) requestMethod.invoke(this.uavClient, this.host + url, token, data); |
| | | } catch (IllegalAccessException e) { |
| | | System.out.println("doUavRequest 访问失败" + e.getMessage()); |
| | | log.error("doUavRequest 访问失败" + e.getMessage()); |
| | | } catch (InvocationTargetException e) { |
| | | System.out.println("doUavRequest 执行失败" + e.getMessage()); |
| | | log.error("doUavRequest 执行失败" + e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | |
| | | //验证token有效性 |
| | | try { |
| | | String res = uavClient.GET(this.host+"manage/api/v1/devices", token, "{}"); |
| | | System.out.println(res); |
| | | res+=""; |
| | | //System.out.println(res); |
| | | } catch (ForestNetworkException fe) { |
| | | if (fe.getStatusCode() == 401) {//token失效,重新登录 |
| | | this.login(); |
| | |
| | | log.debug("登录无人机外部接口"); |
| | | String codedPassword = this.Encrypt(password, salt); |
| | | String body = "{\"username\":\"" + username + "\",\"password\":\"" + codedPassword + "\"}"; |
| | | System.out.println("body:" + body); |
| | | log.debug("body:" + body); |
| | | try { |
| | | //uavClient.GET("logout", null, "{}"); |
| | | String res = uavClient.POST(this.host+"login", null, body); |