From db7fa6a91b9534ac90e219b6f554c54c43c83a5a Mon Sep 17 00:00:00 2001 From: liujie <liujie> Date: 星期三, 16 八月 2023 09:28:15 +0800 Subject: [PATCH] update --- driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/juhe/WeatherUtil.java | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/juhe/WeatherUtil.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/juhe/WeatherUtil.java index 3c19f2e..33c664c 100644 --- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/juhe/WeatherUtil.java +++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/juhe/WeatherUtil.java @@ -9,6 +9,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; + /** * 天气工具类 @@ -84,4 +86,34 @@ } 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; + } + } -- Gitblit v1.7.1