Esempio n. 1
0
        public static GetItemPromoPrice.TaobaoPromoPriceEntity GetTaobaoItemPromoPrice(string onlineKey)
        {
            GetItemPromoPrice.TaobaoPromoPriceEntity result = null;
            string url             = "http://a.m.taobao.com/ajax/sku.do?item_id=" + onlineKey;
            string responseContent = GetItemPromoPrice.GetResponseContent(url, Encoding.GetEncoding("Utf-8"));

            try
            {
                if (!string.IsNullOrEmpty(responseContent))
                {
                    result = JsonConvert.DeserializeObject <GetItemPromoPrice.TaobaoPromoPriceEntity>(responseContent);
                }
            }
            catch (Exception ex)
            {
                Log.WriteLog(ex);
            }
            return(result);
        }
Esempio n. 2
0
        public static GetItemPromoPrice.TaobaoPromoPriceEntity GetTaobaoItemPromoPrice2(string onlineKey)
        {
            GetItemPromoPrice.TaobaoPromoPriceEntity taobaoPromoPriceEntity = new GetItemPromoPrice.TaobaoPromoPriceEntity();
            string format   = "http://detailskip.taobao.com/json/sib.htm?itemId={0}&u=1&p=1&chnl=pc";
            string format2  = "http://item.taobao.com/item.htm?id={0}";
            string strUrl   = string.Format(format, onlineKey);
            string refreUrl = string.Format(format2, onlineKey);
            string text     = GetItemPromoPrice.Invoke(strUrl, refreUrl, Encoding.GetEncoding("gb2312"));

            if (!string.IsNullOrEmpty(text.Trim()))
            {
                Regex  regex = new Regex("(?is)g_config.PromoData=(.*?}\\s*?);");
                Match  match = regex.Match(text.Trim());
                string value = string.Empty;
                if (match.Success)
                {
                    value = match.Groups[1].Value;
                }
                if (!string.IsNullOrEmpty(value))
                {
                    try
                    {
                        Dictionary <string, List <GetItemPromoPrice.PromoEntity> > dictionary = JsonConvert.DeserializeObject <Dictionary <string, List <GetItemPromoPrice.PromoEntity> > >(value);
                        if (dictionary != null && dictionary.Count >= 0)
                        {
                            foreach (KeyValuePair <string, List <GetItemPromoPrice.PromoEntity> > current in dictionary)
                            {
                                if (current.Value != null && current.Value.Count > 0)
                                {
                                    string key = current.Key.Trim(new char[]
                                    {
                                        ';'
                                    });
                                    decimal num = 0m;
                                    foreach (GetItemPromoPrice.PromoEntity current2 in current.Value)
                                    {
                                        if (!string.IsNullOrEmpty(current2.Price))
                                        {
                                            if (num == 0m)
                                            {
                                                num = DataConvert.ToDecimal(current2.Price);
                                            }
                                            else
                                            {
                                                if (num > DataConvert.ToDecimal(current2.Price))
                                                {
                                                    num = DataConvert.ToDecimal(current2.Price);
                                                }
                                            }
                                        }
                                    }
                                    if (num != 0m)
                                    {
                                        if (taobaoPromoPriceEntity.availSKUs == null)
                                        {
                                            taobaoPromoPriceEntity.availSKUs = new Dictionary <string, GetItemPromoPrice.AvailSKU>();
                                        }
                                        taobaoPromoPriceEntity.availSKUs[key]            = new GetItemPromoPrice.AvailSKU();
                                        taobaoPromoPriceEntity.availSKUs[key].promoPrice = DataConvert.ToString(num);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLog(ex);
                    }
                }
            }
            return(taobaoPromoPriceEntity);
        }