Exemplo n.º 1
0
        /// <summary>
        /// 向顺丰下订单
        /// </summary>
        /// <param name="wayBillInfo">订单信息</param>
        /// <returns></returns>
        public static NetherlandsParcelModel NlPost(WayBillSfModel wayBillInfo)
        {
            string strXML      = @"<Request service='OrderService' lang='en'>
                                         <Head>{0}</Head>
                                         <Body>
                                           <Order orderid='" + wayBillInfo.WayBillNumber.WayBillNumberReplace() + @"' 
                                                             express_type='A1' 
                                                             j_company='SHENZHEN ZONGTENG' 
                                                             j_contact='Summer'
                                                             j_tel='15818739473'
                                                             j_mobile='15818739473' 
                                                             j_address='2FL,Block C,Longjing Second industrial Park,Taoyuan Village,Nanshan District,Shenzhen,China'
                                                             d_company='" + (wayBillInfo.ShippingCompany ?? "-").Trim().ToDBC().StripXML() + @"'  
                                                             d_contact='" + (wayBillInfo.ShippingName ?? "").Trim().StripXML() + @"'
                                                             d_tel='" + (wayBillInfo.ShippingPhone.GetNumber() == "" ? "-" : wayBillInfo.ShippingPhone.GetNumber()) + @"'
                                                             d_mobile='" + (wayBillInfo.ShippingPhone.GetNumber() == "" ? "-" : wayBillInfo.ShippingPhone.GetNumber()) + @"'
                                                             d_address='" + wayBillInfo.ShippingAddress.Trim().ToDBC().StripXML() + @"' 
                                                             parcel_quantity='" + wayBillInfo.PackageNumber + @"' 
                                                             j_province='Guangdong province' 
                                                             j_city='Shenzhen' 
                                                             j_post_code='518055' 
                                                             j_country='CN'
                                                             d_country='" + wayBillInfo.CountryCode.Trim() + @"'      
                                                             d_post_code='" + wayBillInfo.ShippingZip.GetNumber() + @"'    
                                                             d_province='" + (wayBillInfo.ShippingState ?? "").Trim().ToDBC().StripXML() + @"'
                                                             d_city='" + (wayBillInfo.ShippingCity ?? "-").Trim().ToDBC().StripXML() + @"'
                                                             returnsign='" + (wayBillInfo.IsReturn ? "Y" : "N") + @"'       
                                                             cargo_total_weight='" + wayBillInfo.ApplicationInfo.Sum(p => p.Qty * p.UnitWeight).ToString("F3") + @"'    >                                     
                                           {1}
                                        </Order>
                                        </Body>
                                        </Request>";
            string application = string.Empty;

            foreach (var app in wayBillInfo.ApplicationInfo)
            {
                application += "<Cargo ename='" + app.ApplicationName.Trim().ToDBC().StripXML();
                if (app.HsCode.GetNumber() != "")
                {
                    application += "' hscode='" + app.HsCode.GetNumber();
                }
                application += "' count='" + app.Qty + "' unit='PCE' weight='" + app.UnitWeight + "'  amount='" +
                               app.UnitPrice.ToString("F2") + @"'> </Cargo> ";
            }
            string responseResult = LMSSFService.SfExpressService(strXML.FormatWith(ClientCode, application),
                                                                  (strXML.FormatWith(ClientCode, application) +
                                                                   SFCheckWord).MD5Encrypt());
            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml(responseResult);
            XmlNode root = xdoc.SelectSingleNode("/Response/Head");

            if (root != null && root.InnerText == "OK")
            {
                var     parcel = new NetherlandsParcelModel();
                XmlNode o      = xdoc.SelectSingleNode("/Response/Body/OrderResponse");
                if (o != null && o.Attributes != null)
                {
                    if (o.Attributes["mailno"] != null)
                    {
                        parcel.MailNo = o.Attributes["mailno"].Value.Trim();
                    }
                    if (o.Attributes["agent_mailno"] != null)
                    {
                        parcel.AgentMailNo = o.Attributes["agent_mailno"].Value.Trim();
                    }
                    if (o.Attributes["origincode"] != null)
                    {
                        parcel.OriginCode = o.Attributes["origincode"].Value;
                    }
                    if (o.Attributes["destcode"] != null)
                    {
                        parcel.DestCode = o.Attributes["destcode"].Value;
                    }
                    //if (o.Attributes["orderid"] != null)
                    //{
                    //    parcel.WayBillNumber = o.Attributes["orderid"].Value.Trim();
                    //}
                    parcel.WayBillNumber = wayBillInfo.WayBillNumber;
                    parcel.Status        = 1;
                    return(parcel);
                }
            }
            else if (root != null && root.InnerText == "ERR")
            {
                XmlNode err = xdoc.SelectSingleNode("/Response/ERROR");
                if (err != null && err.Attributes != null && err.Attributes["code"] != null && !err.Attributes["code"].Value.IsNullOrWhiteSpace())
                {
                    var regex = new Regex(@"^[0-9,]*$");
                    if (regex.IsMatch(err.Attributes["code"].Value))
                    {
                        var errmsg = new List <string>();
                        err.Attributes["code"].Value.Split(',')
                        .ToList()
                        .ForEach(
                            p =>
                            errmsg.Add(
                                LMS.Data.Express.NLPOST.ErrorCode.ResourceManager
                                .GetString(p) ?? p));
                        if (errmsg.Count == 1 && err.Attributes["code"].Value.Trim() == "9002")
                        {
                            //客户订单号存在重复
                            var parcel = SearchNlPost(wayBillInfo.WayBillNumber);
                            if (!parcel.AgentMailNo.IsNullOrWhiteSpace() && !parcel.Remark.IsNullOrWhiteSpace() &&
                                parcel.Remark == "A")
                            {
                                return(parcel);
                            }
                        }
                        else
                        {
                            Log.Error("运单号为:{2}提交顺丰API错误代码为:{0},错误信息:{1}".FormatWith(err.Attributes["code"].Value,
                                                                                     string.Join(",", errmsg),
                                                                                     wayBillInfo.WayBillNumber));

                            //拆入错误记录
                            WayBillController.SubmitFailure(wayBillInfo.WayBillNumber,
                                                            "错误代码为:{0},错误信息:{1}".FormatWith(
                                                                err.Attributes["code"].Value,
                                                                string.Join(",", errmsg)));
                        }
                    }
                    else
                    {
                        var parcel = SearchNlPost(wayBillInfo.WayBillNumber);
                        if (!parcel.AgentMailNo.IsNullOrWhiteSpace() && !parcel.Remark.IsNullOrWhiteSpace() &&
                            parcel.Remark == "A")
                        {
                            return(parcel);
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取需要提交到顺丰的运单信息
        /// </summary>
        /// <param name="wayBillNumbers">运单号集合</param>
        /// <returns></returns>
        public static List <WayBillSfModel> GetWayBillSfModelList(List <string> wayBillNumbers)
        {
            if (!wayBillNumbers.Any())
            {
                return(null);
            }
            DbUtility dbUtility = new SqlDbUtility(_lmsCon);
            DataTable dt        = dbUtility.ExecuteData("exec P_GetNlPostWayBillNumberInfoList N'" + string.Join(",", wayBillNumbers) + "'");
            var       list      = new List <WayBillSfModel>();

            if (dt != null && dt.Rows.Count > 0)
            {
                Log.Info("LMS获取需要提交到顺丰的运单信息总数是" + dt.Rows.Count);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    var model = new WayBillSfModel();
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        switch (dt.Columns[j].ColumnName)
                        {
                        case "WayBillNumber":
                            model.WayBillNumber = dt.Rows[i][j].ToString();
                            break;

                        case "ShippingCompany":
                            model.ShippingCompany = dt.Rows[i][j].ToString();
                            break;

                        case "ShippingName":
                            model.ShippingName = dt.Rows[i][j].ToString();
                            break;

                        case "ShippingPhone":
                            model.ShippingPhone = dt.Rows[i][j].ToString();
                            break;

                        case "ShippingAddress":
                            model.ShippingAddress = dt.Rows[i][j].ToString();
                            break;

                        case "PackageNumber":
                            model.PackageNumber = Int32.Parse(dt.Rows[i][j].ToString());
                            break;

                        case "CountryCode":
                            model.CountryCode = dt.Rows[i][j].ToString();
                            break;

                        case "ShippingZip":
                            model.ShippingZip = dt.Rows[i][j].ToString();
                            break;

                        case "ShippingState":
                            model.ShippingState = dt.Rows[i][j].ToString();
                            break;

                        case "ShippingCity":
                            model.ShippingCity = dt.Rows[i][j].ToString();
                            break;

                        case "IsReturn":
                            model.IsReturn = bool.Parse(dt.Rows[i][j].ToString());
                            break;

                        case "ApplicationInfo":
                            if (string.IsNullOrWhiteSpace(dt.Rows[i][j].ToString()))
                            {
                                continue;
                            }
                            model.ApplicationInfo = SerializeUtil.DeserializeFromXml <List <ApplicationInfoSfModel> >(dt.Rows[i][j].ToString());
                            break;
                        }
                    }
                    list.Add(model);
                }
            }
            Log.Info("LMS获取需要提交到顺丰的运单信息完毕!");
            return(list);
        }