c#根据手机号查归属地

可调用接口参考地址(没有免费的午餐):

选后者,API地址: http://v.showji.com/Locating/showji.com2016234999234.aspx?m={0}&output=json

示例代码:

/// <summary>
        /// 
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public List<object> GetInfos(string mobile)
        {
            List<object> obj = new List<object>();

            try
            {
                Utils.WriteLog(string.Format("开始获取信息手机号:{0}", mobile));

                HttpClient client = new HttpClient();
                string bdUrl = string.Format(url, mobile);
                string result = client.GetStringAsync(bdUrl).Result;
                JObject jResult = (JObject)JsonConvert.DeserializeObject(result);
                if (Convert.ToBoolean(jResult["QueryResult"]) == false)
                    return null;

                obj.Add(Convert.ToString(jResult["Mobile"]));
                obj.Add(Convert.ToString(jResult["Corp"]));
                obj.Add(Convert.ToString(jResult["Province"]));
                obj.Add(Convert.ToString(jResult["City"]));
                obj.Add(Convert.ToString(jResult["AreaCode"]));
                obj.Add(Convert.ToString(jResult["PostCode"]));
            }
            catch (Exception ex)
            {
                Utils.WriteLog(string.Format("处理数据异常,信息如下:", ex.Message));
            }

            return obj;
        }
View Code
原文地址:https://www.cnblogs.com/tgzhu/p/8037848.html