示例#1
0
        public long GetRegionByIPInTaobao(string ip)
        {
            string str = "http://ip.taobao.com/service/getIpInfo.php?ip={0}";
            long   num = 0;

            str = string.Format(str, ip);
            try
            {
                TaobaoIpDataModel taobaoIpDataModel = JsonConvert.DeserializeObject <TaobaoIpDataModel>(WebHelper.GetRequestData(str, ""));
                if (taobaoIpDataModel != null && taobaoIpDataModel.code == 0 && !string.IsNullOrWhiteSpace(taobaoIpDataModel.data.region))
                {
                    long regionIdByName = GetRegionIdByName(taobaoIpDataModel.data.region);
                    if (regionIdByName > 0)
                    {
                        long cityIdByName = 0;
                        if (!string.IsNullOrWhiteSpace(taobaoIpDataModel.data.city))
                        {
                            cityIdByName = GetCityIdByName(taobaoIpDataModel.data.city, regionIdByName, true);
                        }
                        num = cityIdByName;
                    }
                }
            }
            catch (Exception exception)
            {
            }
            return(num);
        }
示例#2
0
        /// <summary>
        /// 通过IP取地区信息
        /// <para>(数据来源:淘宝)</para>
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public long GetRegionByIPInTaobao(string ip)
        {
            if (Core.Cache.Exists(ip))
            {
                return(Cache.Get <long>(ip));
            }
            string RequestUrl = "http://ip.taobao.com/service/getIpInfo.php?ip={0}";
            long   result     = 0;

            RequestUrl = string.Format(RequestUrl, ip);
            try
            {
                string            requestdata = Himall.Core.Helper.WebHelper.GetRequestData(RequestUrl, "");
                TaobaoIpDataModel tbipdata    = JsonConvert.DeserializeObject <TaobaoIpDataModel>(requestdata);
                if (tbipdata != null && tbipdata.code == 0)
                {
                    if (!string.IsNullOrWhiteSpace(tbipdata.data.city))
                    {
                        var city = GetRegionByName(tbipdata.data.city, Region.RegionLevel.City);
                        if (city != null)
                        {
                            return(city.Id);
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(tbipdata.data.region))
                    {
                        var province = GetRegionByName(tbipdata.data.region, Region.RegionLevel.Province);
                        if (province != null)
                        {
                            return(province.Id);
                        }
                    }
                }
            }
            catch
            {
            }
            Cache.Insert(ip, result);
            return(result);
        }