|  |  |  | 
|---|
|  |  |  | import javax.annotation.PostConstruct; | 
|---|
|  |  |  | import javax.crypto.Cipher; | 
|---|
|  |  |  | import javax.crypto.spec.SecretKeySpec; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.lang.reflect.InvocationTargetException; | 
|---|
|  |  |  | import java.lang.reflect.Method; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //token 登陆后每次请求,在header中携带 | 
|---|
|  |  |  | private String token;//登录成功返回的token | 
|---|
|  |  |  | private Map uavUser;//登录的用户信息 | 
|---|
|  |  |  | private ObjectMapper om = new ObjectMapper(); | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UavClient uavClient; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } catch (JsonProcessingException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|