| | |
| | | Integer cityCode = cityConfigWeatherForecast.getCityCode(); |
| | | Integer locationId = cityConfigWeatherForecast.getLocationId(); |
| | | //Map<String, Object> data = restTemplate.getForObject("https://api.qweather.com/v7/weather/72h?key=da05c6c4852d4f7aa3364a9236ee9e26&gzip=n&location={1}", Map.class, locationId); |
| | | Map<String, Object> data = restTemplate.getForObject("https://devapi.qweather.com/v7/weather/24h?location="+locationId+"&key=2430ab9e636c4950a686fbd84e3ccb3a", Map.class); |
| | | Map<String, Object> data = restTemplate.getForObject("https://api.qweather.com/v7/weather/72h?key=5c27e3442bee4a0891eae34afca125f3&gzip=n&location={1}", Map.class, locationId); |
| | | //Map<String, Object> data = restTemplate.getForObject(url,Map.class); |
| | | List<Map<String, Object>> hourly = (List<Map<String, Object>>) data.get("hourly"); |
| | | for (Map<String, Object> hourlyMap : hourly) { |
| | | String fxTime = hourlyMap.get("fxTime").toString(); |
| | | String dayTime = fxTime.split("T")[0]; |
| | | //if (dayTime.equals(nextTime)) { |
| | | if (dayTime.equals(nextTime)) { |
| | | String hourTime = fxTime.substring(0, 17).replaceAll("T", " "); |
| | | CityWeatherForecast cityWeatherForecast = new CityWeatherForecast(); |
| | | cityWeatherForecast.setCityCode(cityCode); |
| | | cityWeatherForecast.setTime(DateUtils.getDate(hourTime, DateUtils.yyyy_MM_dd_HH_EN)); |
| | | cityWeatherForecast.setValue(JSONObject.toJSONString(hourlyMap)); |
| | | cityWeatherForecasts.add(cityWeatherForecast); |
| | | //} |
| | | } |
| | | } |
| | | } |
| | | cityWeatherForecastMapper.insertCityWeatherForecast(cityWeatherForecasts); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String url = "https://devapi.qweather.com/v7/weather/24h?location=101010100&key=2430ab9e636c4950a686fbd84e3ccb3a"; //此处换为自己的地址 |
| | | RestTemplate restTemplate = new RestTemplate( |
| | | new HttpComponentsClientHttpRequestFactory()); // 使用HttpClient,支持GZIP |
| | | restTemplate.getMessageConverters().set(1, |
| | | new StringHttpMessageConverter(StandardCharsets.UTF_8)); |
| | | Map<String, Object> data = restTemplate.getForObject(url,Map.class); |
| | | /* String url = "https://devapi.qweather.com/v7/weather/24h?location=101010100&key=2430ab9e636c4950a686fbd84e3ccb3a"; //此处换为自己的地址 |
| | | |
| | | Map<String, Object> data = restTemplate.getForObject(url,Map.class);*/ |
| | | /*RestTemplate restTemplate = new RestTemplate();*/ |
| | | Map<String, Object> data = restTemplate.getForObject("https://api.qweather.com/v7/weather/72h?key=5c27e3442bee4a0891eae34afca125f3&gzip=n&location={1}", Map.class, 101010100); |
| | | |
| | | List<Map<String, Object>> hourly = (List<Map<String, Object>>) data.get("hourly"); |
| | | int i = 0; |
| | | |