From 44f2a0a32c096bdb05d4cc0ac162cdc1eb14c3ed Mon Sep 17 00:00:00 2001
From: Administrator <1144154118@qq.com>
Date: 星期四, 10 八月 2023 13:14:29 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)
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..14acb4d 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
@@ -1,10 +1,12 @@
package com.ruoyi.device.uav.service;
import com.dtflys.forest.exceptions.ForestNetworkException;
+import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.utils.forest.UavClient;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
@@ -21,6 +23,7 @@
import java.util.Map;
@Service
+@Slf4j(topic = "uav")
public class UavService {
public static final String USERNAME = "ardbailu";//鐢ㄦ埛鍚�
public static final String PASSWORD = "ardkj12345";//瀵嗙爜
@@ -28,6 +31,7 @@
//token 鐧婚檰鍚庢瘡娆¤姹�,鍦╤eader涓惡甯�
private String token;//鐧诲綍鎴愬姛杩斿洖鐨則oken
+ private Map uavUser;//鐧诲綍鐨勭敤鎴蜂俊鎭�
private ObjectMapper om = new ObjectMapper();
@Autowired
private UavClient uavClient;
@@ -68,18 +72,26 @@
return res;
}
+ public Map getUavUser() {
+ if (this.uavUser == null) {
+ this.login();
+ }
+ return this.uavUser;
+ }
+
public void login() {
+ log.debug("鐧诲綍鏃犱汉鏈哄閮ㄦ帴鍙�");
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();
+ } catch (ForestRuntimeException e) {
+ log.error("鏃犱汉鏈鸿繛鎺ヨ秴鏃�" + e.getMessage());
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (JsonProcessingException e) {
--
Gitblit v1.9.3