根据省市区区域代码查询天气,调用高德开放平台,每天能查询30W次,基本满足需求。
String weatherUrl = "https://restapi.amap.com/v3/weather/weatherInfo?city=330100&key=KEY";
ResponseEntity<String> weatherEntity = restTemplate.getForEntity(weatherUrl, String.class);
String weatherBody = weatherEntity.getBody();
JSONObject weatherObject = JSONObject.parseObject(weatherBody);
System.out.println(weatherObject);
city传入省市区的行政区域代码,key传入你创建的应用ID,获取到json数据,根据业务做相应处理。
结果如图所示:
官网地址:https://lbs.amap.com/api/webservice/guide/api/weatherinfo/