Exemplo n.º 1
0
        /// <summary>
        /// 获取京东运费
        /// </summary>
        /// <param name="getShippingOptionRequest"></param>
        /// <returns></returns>
        private decimal GetJdFright(GetShippingOptionRequest getShippingOptionRequest)
        {
            try
            {
                var freightObj = new JDFetchFreightIn()
                {
                    Province = getShippingOptionRequest.ShippingAddress.JDAddrLevel1,
                    City     = getShippingOptionRequest.ShippingAddress.JDAddrLevel2,
                    County   = getShippingOptionRequest.ShippingAddress.JDAddrLevel3,
                    Town     = getShippingOptionRequest.ShippingAddress.JDAddrLevel4,
                    Skus     = getShippingOptionRequest.Items.Where(p => p.ShoppingCartItem.Product.JDSkuId.HasValue)
                               .Select(p => new JDFetchFreightIn_Skus()
                    {
                        SkuId = p.ShoppingCartItem.Product.JDSkuId.Value,
                        Num   = p.ShoppingCartItem.Quantity
                    }).ToList()
                };

                var result = _jdService.FetchFreight(freightObj);

                return(result.Freight);
            }
            catch (Exception e)
            {
                //log
                return(0);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 抓取运费
        /// </summary>
        /// <returns></returns>
        public JDFetchFreightOut FetchFreight(JDFetchFreightIn freightIn)
        {
            JDFetchFreightOut result = null;

            freightIn.NullCheck("freightIn");
            (freightIn.Skus.Count > 50).TrueThrow("最多支持50种商品");

            string str = CallApi("https://bizapi.jd.com/api/order/getFreight",
                                 $"token={JDCommonToken.Access_Token}&sku={JsonConvert.SerializeObject(freightIn.Skus)}&province={freightIn.Province}&city={freightIn.City}&county={freightIn.County}&town={freightIn.Town}&paymentType={freightIn.PaymentType}");

            JDFreightResult json = JsonConvert.DeserializeObject <JDFreightResult>(str);

            if (json != null && json.success)
            {
                result = json.result.ToJDFetchFreightOut();
            }
            else
            {
                _log.InsertLog(LogLevel.Error, "京东-获取运费失败", str);
            }

            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 抓取运费
 /// </summary>
 /// <returns></returns>
 public ActionResult FetchFreight(JDFetchFreightIn freightIn)
 {
     return(Content(JsonConvert.SerializeObject(_jdService.FetchFreight(freightIn))));
 }