Example #1
0
        /// <summary>
        /// 查询物流记录
        /// </summary>
        /// <param name="company"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        public static DeliveryTransation Query(string company, string number)
        {
            String code = ServiceContainer.GetService <DeliveryCompanyService>().GetDeliveryCompany(company).PopMapKuaidi100;
            Dictionary <string, string> para = new Dictionary <string, string>();

            para["type"]   = code;
            para["postid"] = number;
            para["temp"]   = "0." + r.Next() + "" + r.Next();
            var content = MsHttpRestful.GetUrlEncodeBodyReturnString(APIURL, para, Encoding.UTF8, null, "http://www.kuaidi100.com/", "*/*");
            var ret     = Newtonsoft.Json.JsonConvert.DeserializeObject <Kuaidi100DeliveryResult>(content);
            var item    = new DeliveryTransation();

            item.IsSigned = ret.ischeck == "1" ? true : false;
            if (ret.message.ToUpper().Equals("OK") == false)
            {
                throw new Exception(ret.message);
            }
            item.Items = new List <DeliveryTransationItem>();
            foreach (var o in ret.data)
            {
                item.Items.Add(new DeliveryTransationItem {
                    Time = DateTime.Parse(o.ftime), Description = o.context
                });
            }

            return(item);
        }
Example #2
0
        private HtmlAgilityPack.HtmlDocument GetHtmlDocWithRetry(string url)
        {
            string html = MsHttpRestful.GetUrlEncodeBodyReturnString(url, null);

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(html);
            return(doc);
        }
Example #3
0
        public override Vendor GetVendorInfoByUrl(string url)
        {
            var vendor = new Vendor {
                Alias = "", AveragePrice = 0, Comment = "", Count = 0, CreateTime = DateTime.Now, HomePage = "", Id = 0, MarketAddress = "", MarketAddressShort = "", Name = "", PingyingName = "", Watch = false
            };
            string html = MsHttpRestful.GetUrlEncodeBodyReturnString(url, null);

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(html);

            var title = doc.DocumentNode.SelectSingleNode("//div[@class='name']/a");

            if (title == null)
            {
                throw new Exception("未找到名称 //div[@class='name']/a");
            }
            vendor.Name     = title.InnerText.Trim();
            vendor.HomePage = title.GetAttributeValue("href", "").TrimEnd('/');

            var adds = doc.DocumentNode.SelectNodes("//div[@class = 'site_right']/div");

            if (adds == null || adds.Count < 1)
            {
                throw new Exception("未找到地址 div[@class = 'site_right']/div ");
            }
            foreach (var addN in adds)
            {
                var add = addN.InnerText.Trim().Replace(":", "").Replace(":", "").Replace(";", "").Replace(";", "").Replace("&nbsp", "");
                if (add.StartsWith("地址"))
                {
                    add = add.Substring(2);
                    vendor.MarketAddress = add.Trim();
                    break;
                }
            }

            return(vendor);
        }
Example #4
0
        public override Goods GetGoodsInfoByUrl(string url, ref string vendorHomePage, ref string videoUrl, bool raiseExceptionOnGoodsNotSale)
        {
            Goods g = new Goods {
                Comment = "", CreateTime = DateTime.Now, Image = "", Number = "", Price = 0, Type = 0, UpdateEnabled = true, UpdateTime = DateTime.Now, Url = url, VendorId = 0, Weight = 0, Id = 0, Colors = "", CreateOperator = "", Flag = ColorFlag.UN_LABEL, IgnoreEdtion = false, ImageDir = "", Material = "", Shops = new List <GoodsShop>(), Star = 0, VideoType = GoodsVideoType.NONE, Shipper = "WL"
            };
            string html = MsHttpRestful.GetUrlEncodeBodyReturnString(url, null);

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(html);

            //厂家网址
            var title = doc.DocumentNode.SelectSingleNode("//div[@class='name']/a");

            if (title == null)
            {
                throw new Exception("未找到名称 //div[@class='name']/a");
            }
            vendorHomePage = title.GetAttributeValue("href", "").TrimEnd('/');

            //货号
            var hnNumber = doc.DocumentNode.SelectSingleNode("//div[@class='huohao']");

            if (hnNumber == null)
            {
                throw new Exception("未找到货号 //div[@class='huohao']");
            }
            g.Number = hnNumber.InnerText.Split(new string[] { "&amp;" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim();

            //价格
            var hnPrice = doc.DocumentNode.SelectSingleNode("//span[@class='sku-price']");

            if (hnPrice == null)
            {
                throw new Exception("未找到价格 //span[@class='sku-price']");
            }
            g.Price = float.Parse(hnPrice.InnerText.Trim());

            //商品图片
            var hnImages = doc.DocumentNode.SelectSingleNode("//ul[@class='tb-thumb']/li/div/a/img");

            if (hnImages == null)
            {
                throw new Exception("未找到主图 //ul[@class='tb-thumb']/li/div/a/img");
            }
            g.Image = hnImages.GetAttributeValue("src", "");

            //类型
            var hnTypes = doc.DocumentNode.SelectNodes("//div[@class='category']/span");

            if (hnTypes == null || hnTypes.Count < 1)
            {
                throw new Exception("未找到类型结点 //div[@class='category']/span");
            }
            var type = hnTypes.First().InnerText.Replace("类型:", "");

            g.Type = EnumUtil.GetEnumValueByDesc <GoodsType>(type);
            //主图视频

            //颜色
            var hnColors = doc.DocumentNode.SelectNodes("//div[@class='default-color']/div/span/a");

            if (hnColors != null && hnColors.Count > 0)
            {
                string[] colors = hnColors.Select(obj => obj.InnerText.Trim()).ToArray();
                g.Colors = string.Join(",", colors);
            }
            else
            {
                hnColors = doc.DocumentNode.SelectNodes("//div[@class='color_box']/div/p");
                if (hnColors != null && hnColors.Count > 0)
                {
                    string[] colors = hnColors.Select(obj => obj.InnerText.Trim()).ToArray();
                    g.Colors = string.Join(",", colors);
                }
            }
            //帮面材质
            var hnPropertys = doc.DocumentNode.SelectNodes("//div[@class='shoes_info']/span[@class='text_box']");

            if (hnPropertys != null)
            {
                foreach (var v in hnPropertys)
                {
                    if (v.InnerText.Contains("帮面材质"))
                    {
                        var hnA = v.SelectSingleNode("a");
                        if (hnA != null)
                        {
                            g.Material = hnA.InnerText.Trim();
                            break;
                        }
                    }
                }
            }
            return(g);
        }