| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.aliyun.oss.ServiceException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.ApplicationArguments; |
| | | import org.springframework.boot.ApplicationRunner; |
| | |
| | | @Component |
| | | public class GDFalconUtil implements ApplicationRunner { |
| | | |
| | | private String key = "94fb3bba5b141c701cbdcab72fe9d9cf"; |
| | | private String key = "5053ca611c0106e01a665ce7ab84ff26"; |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | |
| | | */ |
| | | @Override |
| | | public void run(ApplicationArguments args) throws Exception { |
| | | this.init(); |
| | | // this.init(); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * 初始化创建服务 |
| | | */ |
| | | public void init(){ |
| | | if(serverId == null){ |
| | | JSONArray jsonArray = this.selectServer(); |
| | | if(null == jsonArray){ |
| | | serverId = this.createServer("server"); |
| | | }else{ |
| | | serverId = jsonArray.getJSONObject(0).getString("sid"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | // public void init(){ |
| | | // if(serverId == null){ |
| | | // JSONArray jsonArray = this.selectServer(); |
| | | // if(null == jsonArray){ |
| | | // serverId = this.createServer("server"); |
| | | // }else{ |
| | | // serverId = jsonArray.getJSONObject(0).getString("sid"); |
| | | // } |
| | | // } |
| | | // |
| | | // } |
| | | |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public String selectTerminal(String name){ |
| | | String url = "https://tsapi.amap.com/v1/track/terminal/list?key=" + key + "&sid=" + serverId + "&name=" + name; |
| | | String url = "https://tsapi.amap.com/v1/track/terminal/list?key=" + key + "&name=" + name; |
| | | String forObject = restTemplate.getForObject(url, String.class); |
| | | JSONObject jsonObject = JSON.parseObject(forObject); |
| | | if(jsonObject.getIntValue("errcode") == 10000){ |
| | |
| | | System.err.println(jsonObject.getString("errmsg")); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询轨迹 |
| | | * @param tid 终端id |
| | | */ |
| | | public String selectTrack(String tid, String trid,Integer page){ |
| | | String url = "https://tsapi.amap.com/v1/track/terminal/trsearch?key=" + key + "&sid=" + serverId + "&tid=" + tid + "&trid=" + trid + "&page=" + page + "&pagesize=" + 999; |
| | | // String url = "https://tsapi.amap.com/v1/track/terminal/trsearch?key=" + key + "&sid=" + serverId + "&tid=" + tid + "&starttime=1708410190000" + "&endtime=1708419641315"; |
| | | //将请求头部和参数合成一个请求 |
| | | String s = restTemplate.getForObject(url , String.class); |
| | | JSONObject jsonObject = JSON.parseObject(s); |
| | | if(jsonObject.getIntValue("errcode") == 10000){ |
| | | return jsonObject.getString("data"); |
| | | } |
| | | System.err.println(jsonObject.getString("errmsg")); |
| | | if(jsonObject.getIntValue("errcode") != 10000){ |
| | | throw new ServiceException(jsonObject.getString("errmsg")); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | // |