| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * 天气工具类 |
| | |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取支持城市列表 |
| | | * @return |
| | | */ |
| | | public static List<WeatherCityInfo> queryCityList(){ |
| | | String url = "http://apis.juhe.cn/simpleWeather/cityList?key=" + key; |
| | | HttpResult httpResult = null; |
| | | try { |
| | | httpResult = httpClientUtil.pushHttpRequset("GET", url, null, null, "json"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if(httpResult.getCode() != 200){ |
| | | logger.debug("查询支持城市失败:" + httpResult.getData()); |
| | | return null; |
| | | } |
| | | String data = httpResult.getData(); |
| | | JSONObject jsonObject = JSON.parseObject(data); |
| | | Integer error_code = jsonObject.getInteger("error_code"); |
| | | if(0 != error_code){ |
| | | logger.debug("查询支持城失败:" + jsonObject.getString("reason")); |
| | | return null; |
| | | } |
| | | JSONArray result = jsonObject.getJSONArray("result"); |
| | | List<WeatherCityInfo> weatherCities = result.toJavaList(WeatherCityInfo.class); |
| | | return weatherCities; |
| | | } |
| | | |
| | | } |