public Weather Weather(string province, string city) { int ticker = Environment.TickCount; try { if (!string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(province)) { string url = _baseUri + "position/weather?province=" + HttpUtility.UrlEncode(province) + "&city=" + HttpUtility.UrlEncode(city); var client = new RestClient(url); var req = new RestRequest(Method.GET); var result = client.Execute(req); if (Logger.IsDebugEnabled) { Logger.Debug(String.Format("获取到天气结果:{0} ,原始数据:{1},{2}", result.Content, province, city)); } if (result.IsSuccessful && !string.IsNullOrEmpty(result.Content)) { string res = result.Content; JObject weather = JObject.Parse(res); if (weather != null && "1".Equals(Utils.GetJObjVal(weather["code"]))) { //var dataSK = {"nameen":"shenzhen","cityname":"深圳","city":"101280601","temp":"24","tempf":"75","WD":"东风","wde":"E ","WS":"3级","wse":"<12km/h","SD":"82%","time":"17:00","weather":"多云","weathere":"Cloudy","weathercode":"d01","qy":"1007.1","njd":"13145","sd":"82%","rain":"0","rain24h":"0","aqi":"57","limitnumber":"","aqi_pm25":"57","date":"03月30日(星期四)"} weather = JObject.FromObject(weather["body"]); Weather wea = new Weather() { Province = province, City = city, CityName = Utils.GetJObjVal(weather["cityName"]), CityCode = Utils.GetJObjVal(weather["cityCode"]), WeatherCont = Utils.GetJObjVal(weather["weather"]), Temp = Utils.GetJObjVal(weather["temp"]), Humidity = Utils.GetJObjVal(weather["humidity"]), Pm25 = Utils.GetJObjVal(weather["pm25"]), Wind = Utils.GetJObjVal(weather["wind"]), WindGrade = Utils.GetJObjVal(weather["windGrade"]) }; return(wea); } } Logger.Error(String.Format("获取天气失败,结果:{0} ,原始数据:{1},{2}", result.Content, province, city)); } } catch (Exception ex) { Logger.Error(ex); } Logger.Error("TQ-查询天气失败 province:" + province + "city:" + city); RECORD_INFO record = new RECORD_INFO(); record.set('1', "weather", "", 0, Environment.TickCount - ticker, 1); CPhotoStat.GetInstance().add_info(record); return(null); }
public static extern int MR_SetRecordInfo(IntPtr pObject, ref RECORD_INFO recordInfo);