[JS]天气预报服务含PM2.5,紫外线指数
[JS]天气预报服务含PM2.5,紫外线指数
接口实现的程序代码片断
- try
- {
- string jsoncallback = Request["jsoncallback"];
- string ip = getClientIp();
- string[] ipips = ip.Split(',');
- ip = ips[ips.Length - 1];
- ip = String.IsNullOrEmpty(Request["ip"]) ? ip : Request["ip"];
- ///获取详细地址
- string area = IPLocation.IPLocate(_helper.GetQQWryDataPath(), ip);
- ///根据地址分析出省
- Regex zzq = new Regex(String.Format("({0})", _helper.GetProvinces()));
- Match mzzq = zzq.Match(area);
- ///根扬地址分析出所在地区
- Regex shi = new Regex(String.Format("({0})", _helper.GetCityNames()));
- Match mshi = shi.Match(area);
- SortedList citys = new SortedList();
- object o = _cached.Get("citys");
- if (null != o)
- {
- citys = o as SortedList;
- }
- else
- {
- string[] cityCodes = _helper.GetCityCodes().Split('|');
- foreach (string city in cityCodes)
- {
- string[] c = city.Split('-');
- if (!citys.ContainsKey(c[0]))
- citys.Add(c[0], c[1]);
- }
- _cached.Set("citys", citys);
- }
- string weatId = "1";
- ///是否存在省的天气
- weatId = citys.ContainsKey(mzzq.Value) ? Convert.ToString(citys[mzzq.Value]) : weatId;
- ///是否存在市的天气
- weatId = citys.ContainsKey(mshi.Value) ? Convert.ToString(citys[mshi.Value]) : weatId;
- string keyName = String.Format("weather_{0}", weatId);
- o = _cached.Get(keyName);
- resultJson result = null;
- if (null == o)
- {
- TY.Web web = new TY.Web();
- string ret = web.getHtml(String.Format("http://api.k780.com:88/?app=weather.today&weaid={0}&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json", weatId), TY.EnCoding.UTF8);
- result = JsonConvert.DeserializeObject<resultJson>(ret);
- _cached.Set(keyName, result, 30);
- }
- else
- {
- result = o as resultJson;
- }
- Response.Write(jsoncallback + "({\"week\":\"" + result.result.week + "\", \"citynm\":\"" + result.result.citynm + "\", \"temp\":\"" + result.result.temperature + "\",\"weather\":\"" + result.result.weather + "\" });");
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("Tools.Web::weather", ex.Message);
- }
热门文章推荐
- [JS]window.location获取url各项参数详解
- [JS]jQuery,javascript获得网页的高度和宽度
- [JS]视频弹窗视频弹出层videoLightBox(含三种播放器的用法)
- [JS]JS提交中文encodeURI两次转码
- [JS]js版方面encodeURI转码和decodeURI解码的用法实例
- [JS]js取当前机子的时间戳实例
- [JS]AES加密(基于crypto-js)PHP后端解密
- [JS]data:image/png;base64写法的用途及说明
请稍候...