puzhibing
2023-02-25 4ba348b700fd7f461f754a283eaeeba3fc9ff36c
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;
    }
}