h5ctywhr.api.moji.com/fc40
https://h5ctywhr.api.moji.com/weatherDetail
{"cityId":"280000","cityType":0}:
/*城市搜索*/
var searchBaseUrl = "https://ssch.api.moji.com/citymanage/json/h5/searchCity";
'keyWord': cityName
/**城市列表 */
var cityListBase = "https://h5ctywhr.api.moji.com/weatherthird/cityList";
/**省对应城市id接口 */
var mapCityBase = "https://h5ctywhr.api.moji.com/weatherthird/provincialList";
/**预警列表接口 */
var alertBase = "https://h5ctywhr.api.moji.com/weatherthird/alertPage";
/**首页预警接口*/
var alertIndexBase = "https://h5ctywhr.api.moji.com/weatherthird/alert";
{"aqi":{"desc":"优","level":1,"value":16},"cityId":280000,"cityName":"深圳市龙华区","code":0,"condition":{"humidity":94,"icon":31,"mslp":0,"pressure":0,"realFeel":26,"temp":23,"tips":"","updateTime":1731675249,"weather":"多云","weatherId":82,"windDir":"北风","windLevel":2,"wspd":2.31},"countryName":"中国","forecastDays":{"forecastDay":[{"aqiDesc":"优","aqiLevel":1,"aqiValue":16,"festival":"","humidity":89,"iconDay":3,"iconNight":33,"predictDate":1731513600,"realFeel":0,"sunDown":1731577200,"sunRise":1731537360,"tempHigh":26,"tempLow":23,"weatherDay":"阵雨","weatherNight":"阵雨","weatherType":0,"windDirDay":"东北风","windDirNight":"东北风","windLevelDay":"3","windLevelNight":"2","wspdDay":4.4,"wspdNight":2.4},{"aqiDesc":"优","aqiLevel":1,"aqiValue":19,"festival":"","humidity":85,"iconDay":8,"iconNight":33,"predictDate":1731600000,"realFeel":0,"sunDown":1731663600,"sunRise":1731623820,"tempHigh":27,"tempLow":23,"weatherDay":"中雨","weatherNight":"阵雨","weatherType":2,"windDirDay":"东北风","windDirNight":"东北风","windLevelDay":"1","windLevelNight":"1","wspdDay":0.9,"wspdNight":0.9},{"aqiDesc":"优","aqiLevel":1,"aqiValue":37,"festival":"","humidity":79,"iconDay":1,"iconNight":31,"predictDate":1731686400,"realFeel":0,"sunDown":1731750000,"sunRise":1731710280,"tempHigh":30,"tempLow":23,"weatherDay":"多云","weatherNight":"多云","weatherType":0,"windDirDay":"西北风","windDirNight":"东北风","windLevelDay":"2","windLevelNight":"2","wspdDay":2.4,"wspdNight":2.4},{"aqiDesc":"优","aqiLevel":1,"aqiValue":43,"festival":"","humidity":74,"iconDay":3,"iconNight":31,"predictDate":1731772800,"realFeel":0,"sunDown":1731836340,"sunRise":1731796680,"tempHigh":28,"tempLow":22,"weatherDay":"阵雨","weatherNight":"多云","weatherType":2,"windDirDay":"东北风","windDirNight":"东北风","windLevelDay":"2","windLevelNight":"2","wspdDay":2.4,"wspdNight":2.4},{"aqiDesc":"优","aqiLevel":1,"aqiValue":36,"festival":"","humidity":64,"iconDay":1,"iconNight":33,"predictDate":1731859200,"realFeel":0,"sunDown":1731922740,"sunRise":1731883140,"tempHigh":27,"tempLow":19,"weatherDay":"多云","weatherNight":"阵雨","weatherType":2,"windDirDay":"东北风","windDirNight":"东北风","windLevelDay":"2","windLevelNight":"2","wspdDay":2.4,"wspdNight":2.4},{"aqiDesc":"优","aqiLevel":1,"aqiValue":34,"festival":"","humidity":62,"iconDay":1,"iconNight":7,"predictDate":1731945600,"realFeel":0,"sunDown":1732009140,"sunRise":1731969600,"tempHigh":22,"tempLow":18,"weatherDay":"多云","weatherNight":"小雨","weatherType":2,"windDirDay":"东北风","windDirNight":"东北风","windLevelDay":"3","windLevelNight":"2","wspdDay":4.4,"wspdNight":2.4},{"aqiDesc":"优","aqiLevel":1,"aqiValue":28,"festival":"","humidity":65,"iconDay":7,"iconNight":7,"predictDate":1732032000,"realFeel":0,"sunDown":1732095540,"sunRise":1732056000,"tempHigh":21,"tempLow":17,"weatherDay":"小雨","weatherNight":"小雨","weatherType":2,"windDirDay":"东北风","windDirNight":"东北风","windLevelDay":"2","windLevelNight":"2","wspdDay":2.4,"wspdNight":2.4}],"forecastDay40":{"fallTrendDesc":[{"briefDesc":"6天降水","desc":"预计未来40天将出现6天降雨","type":2}],"tempTrendDesc":[{"desc":"预计未来40天平均最高温为22℃","type":3}]}},"forecastHours":{"forecastHour":[{"aqiDesc":"优","aqiLevel":1,"aqiValue":21,"humidity":94,"icon":31,"predictTime":1731675600,"pressure":0,"realFeel":29,"temp":23,"uvi":"1","weather":"多云","windDesc":"旋转风","windDir":"N","windLevel":"2","wspd":2.31},{"aqiDesc":"优","aqiLevel":1,"aqiValue":23,"humidity":96,"icon":31,"predictTime":1731679200,"pressure":0,"realFeel":29,"temp":24,"uvi":"1","weather":"多云","windDesc":"西南风","windDir":"SSW","windLevel":"1","wspd":0.8},{"aqiDesc":"优","aqiLevel":1,"aqiValue":25,"humidity":96,"icon":31,"predictTime":1731682800,"pressure":0,"realFeel":29,"temp":25,"uvi":"1","weather":"多云","windDesc":"西北风","windDir":"WNW","windLevel":"1","wspd":0.8},{"aqiDesc":"优","aqiLevel":1,"aqiValue":27,"humidity":94,"icon":31,"predictTime":1731686400,"pressure":0,"realFeel":29,"temp":24,"uvi":"1","weather":"多云","windDesc":"西北风","windDir":"NW","windLevel":"1","wspd":0.9},{"aqiDesc":"优","aqiLevel":1,"aqiValue":30,"humidity":92,"icon":31,"predictTime":1731690000,"pressure":0,"realFeel":28,"temp":24,"uvi":"1","weather":"多云","windDesc":"西北风","windDir":"WNW","windLevel":"1","wspd":1.0},{"aqiDesc":"优","aqiLevel":1,"aqiValue":32,"humidity":91,"icon":31,"predictTime":1731693600,"pressure":0,"realFeel":28,"temp":24,"uvi":"1","weather":"少云","windDesc":"西北风","windDir":"WNW","windLevel":"1","wspd":0.9},{"aqiDesc":"优","aqiLevel":1,"aqiValue":33,"humidity":90,"icon":31,"predictTime":1731697200,"pressure":0,"realFeel":28,"temp":24,"uvi":"1","weather":"多云","windDesc":"西北风","windDir":"NW","windLevel":"1","wspd":0.8},{"aqiDesc":"优","aqiLevel":1,"aqiValue":33,"humidity":90,"icon":31,"predictTime":1731700800,"pressure":0,"realFeel":27,"temp":23,"uvi":"1","weather":"多云","windDesc":"西北风","windDir":"NW","windLevel":"1","wspd":1.1},{"aqiDesc":"优","aqiLevel":1,"aqiValue":33,"humidity":89,"icon":31,"predictTime":1731704400,"pressure":0,"realFeel":27,"temp":23,"uvi":"1","weather":"多云","windDesc":"西北风","windDir":"NNW","windLevel":"1","wspd":1.1},{"aqiDesc":"优","aqiLevel":1,"aqiValue":34,"humidity":94,"icon":31,"predictTime":1731708000,"pressure":0,"realFeel":28,"temp":23,"uvi":"1","weather":"多云","windDesc":"西北风","windDir":"NW","windLevel":"1","wspd":0.9},{"aqiDesc":"优","aqiLevel":1,"aqiValue":34,"humidity":90,"icon":1,"predictTime":1731711600,"pressure":0,"realFeel":28,"temp":24,"uvi":"1","weather":"多云","windDesc":"旋转风","windDir":"N","windLevel":"1","wspd":0.9},{"aqiDesc":"优","aqiLevel":1,"aqiValue":34,"humidity":86,"icon":1,"predictTime":1731715200,"pressure":0,"realFeel":28,"temp":23,"uvi":"1","weather":"多云","windDesc":"东北风","windDir":"NNE","windLevel":"1","wspd":1.0},{"aqiDesc":"优","aqiLevel":1,"aqiValue":34,"humidity":82,"icon":1,"predictTime":1731718800,"pressure":0,"realFeel":29,"temp":25,"uvi":"2","weather":"少云","windDesc":"东北风","windDir":"NNE","windLevel":"1","wspd":1.1},{"aqiDesc":"优","aqiLevel":1,"aqiValue":34,"humidity":76,"icon":1,"predictTime":1731722400,"pressure":0,"realFeel":29,"temp":28,"uvi":"3","weather":"多云","windDesc":"西北风","windDir":"WNW","windLevel":"1","wspd":1.5},{"aqiDesc":"优","aqiLevel":1,"aqiValue":35,"humidity":73,"icon":1,"predictTime":1731726000,"pressure":0,"realFeel":30,"temp":30,"uvi":"4","weather":"多云","windDesc":"西北风","windDir":"WNW","windLevel":"2","wspd":1.7},{"aqiDesc":"优","aqiLevel":1,"aqiValue":36,"humidity":69,"icon":1,"predictTime":1731729600,"pressure":0,"realFeel":32,"temp":30,"uvi":"4","weather":"多云","windDesc":"西北风","windDir":"NW","windLevel":"2","wspd":1.9},{"aqiDesc":"优","aqiLevel":1,"aqiValue":37,"humidity":66,"icon":1,"predictTime":1731733200,"pressure":0,"realFeel":32,"temp":29,"uvi":"4","weather":"多云","windDesc":"西北风","windDir":"NW","windLevel":"2","wspd":2.0},{"aqiDesc":"优","aqiLevel":1,"aqiValue":38,"humidity":62,"icon":1,"predictTime":1731736800,"pressure":0,"realFeel":32,"temp":29,"uvi":"3","weather":"多云","windDesc":"西北风","windDir":"WNW","windLevel":"2","wspd":1.8},{"aqiDesc":"优","aqiLevel":1,"aqiValue":38,"humidity":63,"icon":3,"predictTime":1731740400,"pressure":0,"realFeel":32,"temp":29,"uvi":"2","weather":"阵雨","windDesc":"西北风","windDir":"WNW","windLevel":"2","wspd":1.7},{"aqiDesc":"优","aqiLevel":1,"aqiValue":39,"humidity":65,"icon":3,"predictTime":1731744000,"pressure":0,"realFeel":31,"temp":29,"uvi":"1","weather":"阵雨","windDesc":"东北风","windDir":"NNE","windLevel":"2","wspd":1.6},{"aqiDesc":"优","aqiLevel":1,"aqiValue":40,"humidity":67,"icon":1,"predictTime":1731747600,"pressure":0,"realFeel":30,"temp":28,"uvi":"1","weather":"多云","windDesc":"东北风","windDir":"NE","windLevel":"2","wspd":1.6},{"aqiDesc":"优","aqiLevel":1,"aqiValue":42,"humidity":70,"icon":31,"predictTime":1731751200,"pressure":0,"realFeel":29,"temp":28,"uvi":"1","weather":"多云","windDesc":"东北风","windDir":"NE","windLevel":"1","wspd":1.4},{"aqiDesc":"优","aqiLevel":1,"aqiValue":43,"humidity":72,"icon":31,"predictTime":1731754800,"pressure":0,"realFeel":28,"temp":28,"uvi":"1","weather":"多云","windDesc":"东北风","windDir":"NE","windLevel":"1","wspd":1.2},{"aqiDesc":"优","aqiLevel":1,"aqiValue":45,"humidity":31,"icon":30,"predictTime":1731758400,"pressure":0,"realFeel":29,"temp":28,"uvi":"1","weather":"晴","windDesc":"东北风","windDir":"NE","windLevel":"1","wspd":1.0}]},"lat":22.724442,"lon":114.055193,"provinceName":"广东省","rc":{"c":0},"timezone":8}
def get_city_weather(cityId):url='https://h5ctywhr.api.moji.com/weatherDetail'headers={'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}data={"cityId":cityId,"cityType":0}r=requests.post(url,headers=headers,json=data)result=r.json()# today forecastforecastToday=dict(humidity=f"{result['condition']['humidity']}%",temp=f"{result['condition']['temp']}°C",realFeel=f"{result['condition']['realFeel']}°C",weather=result['condition']['weather'],wind=f"{result['condition']['windDir']}{result['condition']['windLevel']}级",updateTime=(datetime.datetime.fromtimestamp(result['condition']['updateTime'])+datetime.timedelta(hours=8)).strftime('%H:%M:%S'))# 24 hours forecastforecastHours=[]for i in result['forecastHours']['forecastHour']:tmp={}tmp['PredictTime']=(datetime.datetime.fromtimestamp(i['predictTime'])+datetime.timedelta(hours=8)).strftime('%H:%M')tmp['Temperature']=i['temp']tmp['Body Temperature']=i['realFeel']tmp['Humidity']=i['humidity']tmp['Weather']=i['weather']tmp['Wind']=f"{i['windDesc']}{i['windLevel']}级"forecastHours.append(tmp)df_forecastHours=pd.DataFrame(forecastHours).set_index('PredictTime')# 7 days forecastforecastDays=[]day_format={1:'昨天',0:'今天',-1:'明天',-2:'后天'}for i in result['forecastDays']['forecastDay']:tmp={}now=datetime.datetime.fromtimestamp(i['predictDate'])+datetime.timedelta(hours=8)diff=(st.session_state.date_time-now).daysfestival=i['festival']tmp['PredictDate']=(day_format[diff] if diff in day_format else now.strftime('%m/%d')) + (f' {festival}' if festival != '' else '')tmp['Temperature']=f"{i['tempLow']}~{i['tempHigh']}°C"tmp['Humidity']=f"{i['humidity']}%"tmp['WeatherDay']=i['weatherDay']tmp['WeatherNight']=i['weatherNight']tmp['WindDay']=f"{i['windDirDay']}{i['windLevelDay']}级"tmp['WindNight']=f"{i['windDirNight']}{i['windLevelNight']}级"forecastDays.append(tmp)df_forecastDays=pd.DataFrame(forecastDays).set_index('PredictDate')return forecastToday,df_forecastHours,df_forecastDays
def get_sky(cityName):url = 'https://ssch.api.moji.com/citymanage/json/h5/searchCity'data = {'keyWord': cityName}res = requests.post(url, data=data)try:cityId = res.json()['city_list'][0]['cityId']except:return 'cty_name error'url = 'https://h5ctywhr.api.moji.com/weatherDetail'data = {"cityId": cityId, "cityType": 0}res = requests.post(url, json=data)obj = res.json()temp = obj['condition']['temp']humidity = obj['condition']['humidity']weather = obj['condition']['weather']wind = obj['condition']['windDir'] + ' ' + str(obj['condition']['windLevel']) + '级'tips = obj['condition']['tips']city = f"{obj['provinceName']}-{obj['cityName']}"return f'''地区:{city}
温度:{temp} 湿度:{humidity}
天气:{weather} 风向:{wind}
提示:{tips}'''
public static List<AlertPO> queryAlert(Integer cityId) {try {Map<String, Object> paramMap = new HashMap<>();String url = "https://h5ctywhr.api.moji.com/weatherthird/alert";paramMap.put("cityId", cityId);String jsonString = JSON.toJSONString(paramMap);String result = HttpUtil.post(url, jsonString);JSONObject jsonObject = JSON.parseObject(result);List<AlertPO> resultList = new ArrayList<>();JSONArray alert = jsonObject.getJSONArray("alert");if (alert == null) {return null;}for (Object o : alert) {JSONObject item = (JSONObject) o;AlertPO build = AlertPO.builder().alertType(item.getInteger("alertTypeId")).level(item.getInteger("level")).content(item.getString("content")).publishTime(item.getLong("publishTime")).reliveTime(item.getLong("reliveTime")).publishSector(item.getString("publishSector")).name(item.getString("name")).build();resultList.add(build);}return resultList;} catch (Exception e) {log.error("获取预警信息失败 ! cityId {}", cityId);log.error("", e);}return null;}public static void main(String[] args) {queryAlert(2543);}
}