//天气路径
public static final String WEATHER_PATH=“http://t.weather.sojson.com/api/weather/city/”;
//天气返回的模板
public static String WEATHER_RESULT=“今天是{0},{1},天气{2},{3},{4},风向{5},风力{6},日出时间{7},日落时间{8},注意{9}”;
public String findweather(String cityCode){
Object weather = redisTemplate.opsForValue().get(ConstantConf.WEATHER_CITY+cityCode);
String string="";
if(weather==null||weather.equals("")) {
string = HttpClientUtil.get2(ConstantConf.WEATHER_PATH,cityCode);
redisTemplate.opsForValue().set(ConstantConf.WEATHER_LOCK+cityCode, “lock”, ConstantConf.WEATHER_TIME, TimeUnit.SECONDS);
}else {
weather = redisTemplate.opsForValue().get(ConstantConf.WEATHER_CITY+cityCode);
}
JSONObject parseObject = JSON.parseObject(string);
JSONObject data = parseObject.getJSONObject(“data”);
JSONArray forecast = data.getJSONArray(“forecast”);
WeatherBean object = forecast.getObject(0, WeatherBean.class);
String format = MessageFormat.format(ConstantConf.WEATHER_RESULT, object.getYmd(),object.getWeek(),object.getType(),object.getHigh(),object.getLow(),object.getFx(),object.getFl(),object.getSunrise(),object.getSunset(),object.getNotice());
return format;
}