using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Web.Script.Serialization; namespace NetLibrary.Express { public class BelgiumApi { public string url { get; set; } /// /// 授权码 /// public string authenticate { get; set; } JavaScriptSerializer JsonConvert = null; public BelgiumApi() { JsonConvert = new JavaScriptSerializer(); } #region 发货 public string SendGoods(Belgium_Order model, string authenticate, out string ErrorMessage) { if (string.IsNullOrEmpty(authenticate) == true) { ErrorMessage = "校验码不能为空"; return ""; } List ListHeader = new List(); ListHeader.Add("Authorization:" + authenticate); // ListHeader.Add("Content-Type:text/json;charset=utf-8"); string postmessage = JsonConvert.Serialize(model); //UTF8Encoding encoding = new UTF8Encoding(); byte[] data = Encoding.UTF8.GetBytes(postmessage); string XmlContent = CustomIO.HttpRequest2("http://114.55.90.117/api/LvsParcels", "POST", "text/json;charset=utf-8", ListHeader, HttpVersion.Version10, data, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return ""; Belgium_Order_Result model2 = JsonConvert.Deserialize(XmlContent); if (model2 == null || model2.ProductBarcode == null || model2.ProductBarcode == "") ErrorMessage = XmlContent; return model2.ProductBarcode; } #endregion #region 运费估算 public Belgium_Fee GetFee(Belgium_Fee model, string authenticate, out string ErrorMessage) { if (string.IsNullOrEmpty(authenticate) == true) { ErrorMessage = "校验码不能为空"; return null; } List ListHeader = new List(); ListHeader.Add("Authorization:" + authenticate); ListHeader.Add("charset=utf-8"); string postmessage = JsonConvert.Serialize(model); UTF8Encoding encoding = new UTF8Encoding(); byte[] data = encoding.GetBytes(postmessage); string XmlContent = CustomIO.HttpRequest2(url + "/api/ShippingPrice", "POST", "text/json", ListHeader, HttpVersion.Version10, data, out ErrorMessage); model = JsonConvert.Deserialize(XmlContent); string[] ss=model.ShippingPrice.Split(':'); model.currencyCode = ss[0]; model.fee = Convert.ToDecimal(ss[1]); return model; } #endregion } #region 订单 public class Belgium_Order { /// /// 永远用1 /// public int ContractId { get; set; } /// /// 订单号 /// public string OrderNumber { get; set; } /// /// 追踪条形码(用户自定义,可为空) /// public string ProductBarcode { get; set; } /// /// 接收人姓名 /// public string RecipientName { get; set; } /// /// 接收人所在街道 /// public string RecipientStreet { get; set; } /// /// 接收人所在房子号码N /// public string RecipientHouseNumber { get; set; } /// /// 公交车号码N /// public string RecipientBusnumber { get; set; } /// /// 接收人邮编 /// public string RecipientZipCode { get; set; } /// /// 接收人所在城市 /// public string RecipientCity { get; set; } /// /// 接收人所在省/州N /// public string RecipientState { get; set; } /// /// MiniPak EU写EU27, 接收人所在国家全名或者2位缩写 /// public string RecipientCountry { get; set; } /// /// 接收人电话N /// public string PhoneNumber { get; set; } /// /// 接收人邮箱N /// public string Email { get; set; } /// /// 寄件人姓名N /// public string SenderName { get; set; } /// /// 寄件人地址N /// public string SenderAddress { get; set; } /// /// 会写在发票上N /// public string SenderSequence { get; set; } public bool IsSure { get; set; } public List Customs { get; set; } public Belgium_Order() { ContractId = 1; IsSure = true; Customs = new List(); } } #endregion #region 物品信息 public class Belgium_Goods { /// /// 物品号码 /// public string Sku { get; set; } /// /// 物品的中文描述 /// public string ChineseContentDescription { get; set; } /// /// 物品描述 /// public string ItemContent { get; set; } /// /// 包裹里不同物品的总数 /// public int ItemCount { get; set; } /// /// 客户为了物品付款数目 (excl 快递) : 如果礼物或样品-> 真实价值! 使用英文逗号不要用中文逗号! MiniPak EU 小于22欧元 /// public int Value { get; set; } /// /// 货币种类: LVS:EUR, GBP, USD /// public string Currency { get; set; } /// /// 净重(克) (1 kg = 1000 gr) – 米进制.最大值: 1999 /// public int Weight { get; set; } /// /// 在标签和发票上的SKU 信息N /// public string SkuInInvoice { get; set; } } #endregion #region 运费估算 public class Belgium_Fee { /// /// 重量信息,单位为克 /// public int Weight { get; set; } /// /// 物品价值 /// public int Value { get; set; } /// /// 货币种类 EUR ,GBP,USD.DDU : EUR, GBP, JPY, CNY, HKD, USD, MYR /// public string Currency { get; set; } /// /// 目的地国家 /// public string Country { get; set; } /// /// 包裹种类 (MiniPack 或者 TrackPack). /// public string ProductName { get; set; } /// /// 包裹运费 /// public string ShippingPrice { get; set; } /// /// 估算费用货币代码 /// public string currencyCode { get; set; } /// /// 估算费用 /// public decimal fee { get; set; } /// /// 错误信息 /// public string Error { get; set; } } #endregion #region 订单返回结果 public class Belgium_Order_Result { public string ProductBarcode { get; set; } } #endregion }