/// <summary>获得淘宝商品的价格</summary>
        /// <param name="itemId">商品编号</param>
        /// <returns>价格和名称</returns>
        public static async Task <ItemPriceModel> GetTabaoPrice(string itemId)
        {
            IHttpProxyClient client = null;

            try
            {
                client = new HttpProxyClient();

                var result = await client.GetTaobaoPriceAsync(itemId);

                result.ThrowIfException(true);

                return(result.Result);
            }
            catch (Exception ex)
            {
                //Logger.Error(new LogModel { Message = "下载商品信息失败", RefNo = itemId }, ex);
                Logger.Info(new LogModel {
                    Message = ex.Message, RefNo = itemId
                });
                return(null);
            }
            finally
            {
                client?.Dispose();
            }
        }
        /// <summary>获得京东的价格</summary>
        /// <param name="itemId"></param>
        /// <returns>Item1:价格;Item2:是否促销;Item3:商品名称</returns>
        public static async Task <ItemPriceModel> GetJingDongPrice(string itemId)
        {
            IHttpProxyClient client = null;

            try
            {
                client = new HttpProxyClient();

                Logger.Info("开始获取京东商品价格: " + itemId);

                var result = await client.GetJingdongPriceAsync(itemId);

                result.ThrowIfException(true);

                if (result.Result != null)
                {
                    Logger.Info($"获取到的京东商品{itemId}的价格为{result.Result.Price},名称为:{result.Result.Title}");

                    return(result.Result);
                }

                Logger.Warn($"获取京东商品{itemId}价格失败");

                return(result.Result);
            }
            catch (Exception ex)
            {
                //Logger.Error(new LogModel { Message = "下载商品信息失败", RefNo = itemId }, ex);
                Logger.Info(new LogModel {
                    Message = ex.Message, RefNo = itemId
                });
                return(null);
            }
            finally
            {
                client?.Dispose();
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Create a new ProxyFilter instance.
 /// </summary>
 /// <param name="httpProxyClient">An IHttpProxyClient instance used to proxy requests.</param>
 public ProxyFilter(IHttpProxyClient httpProxyClient) => _httpProxyClient = httpProxyClient;