获取token

 public static String httpPost(Map requestBody, Map requestHead, String url){
        //发送post请求并接收响应数据
        return cn.hutool.http.HttpUtil.createPost(url).addHeaders(requestHead).form(requestBody).execute().body();
    }



        public static void main(String[] args) {
        Map tokenBody = null;
        Map requestHead = new HashMap<>();
        String url = "http://api.user.mmcuav.cn/api/mmcuav/get-token";
        tokenBody = new HashMap<>();
        tokenBody.put("username","GSantai");
        tokenBody.put("password","[email protected]");
        String tokenResult = httpPost(tokenBody, requestHead, url);
        System.out.println(tokenResult);
        JSONObject result = JSONObject.parseObject(tokenResult);
        String token = result.getString("token");
        System.out.println("token: " + token);

//        result.getJSONArray()
        HashMap header = new HashMap<>();
        header.put("token", token);
        System.out.println(httpPost(null, header, "http://api.user.mmcuav.cn/api/mmcuav/getuavlist"));

        HashMap body = new HashMap<>();
        body.put("deviceHardId","3769037989820971086");
        System.out.println(httpPost(body, header, "http://api.user.mmcuav.cn/api/mmcuav/getuavdata"));

    }

你可能感兴趣的:(java)