2016-10-13 00:16:48 点击量:124 标签: 收藏本文
接口实现的程序代码片断
- 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);
- }
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室