private static void GetInfoFromWebKvgo(ref int ProvinceID, ref int CityID, string areNo) { string str = ""; try { str = GetAndPostWeb.PostDataToUrl("type=json&number=" + areNo, "http://sj.kvgo.net"); //str = GetAndPostWeb.GetDataToUrl("type=json&number=" + areNo, "http://sj.kvgo.net"); JavaScriptSerializer serializer = new JavaScriptSerializer(); var mm = serializer.Deserialize <MobileModel>(str); if (string.IsNullOrEmpty(mm.city) || mm.city == "未知") { string errStr = "在http://sj.kvgo.net查询【" + areNo + "】时,没有查询到归属地"; //BLL.Util.SendErrorEmail(errStr, @"\BitAuto.ISDC.CC2012.BLL\PhoneNumDataDict.cs", @"\BitAuto.ISDC.CC2012.BLL\PhoneNumDataDict.cs"); } else { //插入到自己的数据库 AddToMyDb(mm.province + "-" + mm.city, mm.mobile, mm.area_code, ref ProvinceID, ref CityID); } } catch (Exception ex) { string errStr = "在http://sj.kvgo.net查询【" + areNo + "】时出错:" + ex.Message.ToString(); Loger.Log4Net.Error(errStr, ex); ProvinceID = CityID = 0; //BLL.Util.SendErrorEmail(errStr, ex.Source, ex.StackTrace); //BLL.Util.SendEmailAsync(errStr, ex.Source, ex.StackTrace); //实例委托 //AsyncEventHandler asy = new AsyncEventHandler(BLL.Util.SendErrorEmail); ////异步调用开始 //IAsyncResult ia = asy.BeginInvoke(errStr, ex.Source, ex.StackTrace, null, null); ////异步结束 //asy.EndInvoke(ia); } }
/// <summary> /// 从http://www.023001.com网站获取数据 /// </summary> /// <param name="ProvinceID"></param> /// <param name="CityID"></param> /// <param name="areNo"></param> private static void GetInfoFromWeb023001(ref int ProvinceID, ref int CityID, string areNo) { #region 如果没有在数据库中找到,去网站查询电话归属地 string html = ""; try { html = GetAndPostWeb.HttpPost("http://www.023001.com/inc/phone.asp", "m=" + areNo, "gb2312"); //替换掉没用的字符 html = html.Replace("</br>", "").Replace("\r\n", "").Replace("\"", "\'").Replace(" width=460 border='1' align='center' cellpadding='4' bordercolor=#1488bb style='border-collapse: collapse'", "").ToUpper(); //将返回的html以XML格式放入XmlDocument XmlDocument doc = new XmlDocument(); doc.LoadXml(html); string Location = doc.SelectNodes("//TABLE//TR")[1].SelectNodes("TD")[1].InnerText;//归属地 if (Location != "未知-未知") { //如果找到了归属地 string MoileNum = doc.SelectNodes("//TABLE//TR")[0].SelectNodes("TD")[1].InnerText; //手机号 string CardType = doc.SelectNodes("//TABLE//TR")[2].SelectNodes("TD")[1].InnerText; //手机号类型 string AreaCode = doc.SelectNodes("//TABLE//TR")[3].SelectNodes("TD")[1].InnerText; //座机区号 string ZipCode = doc.SelectNodes("//TABLE//TR")[4].SelectNodes("TD")[1].InnerText; //邮政编码 AddToMyDb(Location, MoileNum, AreaCode); } } catch (Exception ex) { ProvinceID = 0; CityID = 0; } #endregion }