示例#1
0
        public static SfResponse SubmitSf(OrderSfModel model, string authorization)
        {
            var response = new SfResponse();

            if (model == null)
            {
                response.ErrorMsg = "对象为空";
                return(response);
            }
            if (string.IsNullOrWhiteSpace(authorization))
            {
                response.ErrorMsg = "账号信息错误";
                return(response);
            }
            if (!model.Applications.Any())
            {
                response.ErrorMsg = "申报信息不能为空";
                return(response);
            }

            foreach (var app in model.Applications)
            {
                AbstractValidator <ApplicationSfModel> appValidator = new ApplicationSfModelValidator();
                ValidationResult results = appValidator.Validate(app);
                if (!results.IsValid)
                {
                    response.ErrorMsg += string.Join(Environment.NewLine, results.Errors.Select(p => p.ErrorMessage));
                }
            }
            if (!response.ErrorMsg.IsNullOrWhiteSpace())
            {
                return(response);
            }
            AbstractValidator <OrderSfModel> oValidator = new OrderSfModelValidator();
            ValidationResult result = oValidator.Validate(model);

            if (!result.IsValid)
            {
                response.ErrorMsg += string.Join(Environment.NewLine, result.Errors.Select(p => p.ErrorMessage));
                return(response);
            }
            return(PlaceTheOrder(model, authorization));
        }
示例#2
0
        /// <summary>
        /// 提交到顺丰
        /// </summary>
        /// <param name="model"></param>
        /// <param name="authorization"></param>
        /// <returns></returns>
        public static SfResponse PlaceTheOrder(OrderSfModel model, string authorization)
        {
            var    response    = new SfResponse();
            string strXML      = @"<Request service='OrderService' lang='en'>
                                         <Head>" + authorization + @"</Head>
                                         <Body>
                                             <Order orderid='" + model.OrderId.Trim() + @"' 
                                                             express_type='" + model.ExpressType + @"' 
                                                             j_province='Guangdong province' 
                                                             j_city='Shenzhen' 
                                                             j_county='Longgang District' 
                                                             j_company='Lightake' 
                                                             j_contact='cadi'
                                                             j_address='Lightake 5 B102 Jinguanghua Logistics Park 49 Wuhe road south Wuhe community Bantian street,Longgang District,Shenzhen,China'
                                                             j_post_code='518100' 
                                                             j_country='CN'
                                                             j_tel='13923866547'  
                                                             d_contact='" + (model.ShippingName).Trim().ToDBC().StripXML() + @"'
                                                             d_company='" + (model.ShippingCompany ?? model.ShippingName).Trim().ToDBC().StripXML() + @"'  
                                                             d_tel='" + (model.ShippingTel.GetNumber() == "" ? "-" : model.ShippingTel.GetNumber()) + @"'
                                                             d_mobile='" + (model.ShippingPhone.GetNumber() == "" ? "-" : model.ShippingPhone.GetNumber()) + @"'
                                                             d_address='" + model.ShippingAddress.ToDBC().StripXML() + @"' 
                                                             parcel_quantity='" + model.ParcelQuantity + @"' 
                                                             pay_method='1'
                                                             d_province='" + (model.ShippingState ?? "").Trim().ToDBC().StripXML() + @"'
                                                             d_city='" + (model.ShippingCity ?? "-").Trim().ToDBC().StripXML() + @"'  
                                                             declared_value='" + model.ApplicationTotalPrice.ToString("F3") + @"' 
                                                             declared_value_currency ='USD' 
                                                             custid ='7555291632'
                                                             d_country='" + model.CountryCode.Trim() + @"'
                                                             d_deliverycode='MOW' 
                                                             d_post_code='" + model.ShippingZip + @"'
                                                             cargo_total_weight='" + model.ApplicationTotalWeight.ToString("F3") + @"'
                                                             remark='" + model.Remark + @"'
                                                            >
                                             {0}
                                         </Body>
                                    </Request>";
            string application = string.Empty;

            foreach (var app in model.Applications)
            {
                application += "<Cargo name='" + app.ApplicationName.Trim().ToDBC().StripXML() + "' count='" + app.Qty +
                               "'  unit='U' weight='" + app.UnitWeight.ToString("F3") + "'  amount='" +
                               app.UnitPrice.ToString("F2") + @"'  currency='USD'  source_area='China'/>  </Order>";
            }
            string      responseResult = SfCommonService(strXML.FormatWith(application));
            XmlDocument xdoc           = new XmlDocument();

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

            if (root != null && root.InnerText == "OK")
            {
                XmlNode o = xdoc.SelectSingleNode("/Response/Body/OrderResponse");
                if (o != null && o.Attributes != null)
                {
                    if (o.Attributes["mailno"] != null)
                    {
                        response.Model.MailNo = o.Attributes["mailno"].Value.Trim();
                    }
                    if (o.Attributes["remark"] != null)
                    {
                        response.Model.Remark = o.Attributes["remark"].Value.Trim();
                    }
                    if (o.Attributes["agent_mailno"] != null)
                    {
                        response.Model.AgentMailNo = o.Attributes["agent_mailno"].Value.Trim();
                    }
                    if (o.Attributes["origincode"] != null)
                    {
                        response.Model.OriginCode = o.Attributes["origincode"].Value;
                    }
                    if (o.Attributes["destcode"] != null)
                    {
                        response.Model.DestCode = o.Attributes["destcode"].Value;
                    }
                    if (o.Attributes["orderid"] != null)
                    {
                        response.Model.OrderId = o.Attributes["orderid"].Value.Trim();
                    }
                    if (o.Attributes["filter_result"] != null)
                    {
                        response.Model.FilterResult = o.Attributes["filter_result"].Value.Trim();
                    }
                    if (o.Attributes["return_tracking_no"] != null)
                    {
                        response.Model.TrackNumber = o.Attributes["return_tracking_no"].Value.Trim();
                    }
                    return(response);
                }
            }
            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) && err.Attributes["code"].Value != "8016")
                    {
                        var errmsg = new List <string>();
                        err.Attributes["code"].Value.Split(',')
                        .ToList()
                        .ForEach(
                            p =>
                            errmsg.Add(
                                ErrorCode.ResourceManager
                                .GetString(p).IsNullOrWhiteSpace() ? "[{0}]数据格式验证失败".FormatWith(p) : "[{0}]{1}".FormatWith(p, ErrorCode.ResourceManager
                                                                                                                           .GetString(p))));
                        Log.Error("运单号为:{2}提交俄罗斯顺丰API错误代码为:{0},错误信息:{1}".FormatWith(err.Attributes["code"].Value,
                                                                                    string.Join(",", errmsg),
                                                                                    model.OrderId));
                        response.ErrorMsg = string.Join(",", errmsg);
                        return(response);
                    }
                    else if (err.Attributes["code"].Value == "8016")
                    {
                        response.Model = SearchOrderInfo(model.OrderId, authorization);
                        if (!response.Model.MailNo.IsNullOrWhiteSpace())
                        {
                            return(response);
                        }
                        else
                        {
                            response.ErrorMsg = ErrorCode.ResourceManager
                                                .GetString(err.Attributes["code"].Value).IsNullOrWhiteSpace()
                                                    ? "[{0}]数据格式验证失败".FormatWith(err.Attributes["code"].Value)
                                                    : "[{0}]{1}".FormatWith(err.Attributes["code"].Value,
                                                                            ErrorCode.ResourceManager
                                                                            .GetString(
                                                                                err.Attributes["code"].Value));
                        }
                    }
                }
            }
            return(response);
        }
示例#3
0
        //预报顺E宝
        public static void SubmitSebOrder()
        {
            Log.Info("开始预报顺E宝俄罗斯挂号,平邮");
            var list = SebController.GetLithuaniaWayBillNumberList();

            if (list.Any())
            {
                const int pagesize  = 50;//分批查询
                int       pageindex = 1;
                do
                {
                    var waybillList = SebController.GetWayBillSfModelList(list.Skip((pageindex - 1) * pagesize).Take(pagesize).ToList());
                    if (waybillList.Any())
                    {
                        foreach (var wayBillSfModel in waybillList)
                        {
                            try
                            {
                                var model = new OrderSfModel()
                                {
                                    OrderId     = wayBillSfModel.WayBillNumber,
                                    ExpressType =
                                        _LithuaniaShippingMethodID.Split(new string[] { "," },
                                                                         StringSplitOptions.RemoveEmptyEntries)
                                        [0] == wayBillSfModel.ShippingMethodId.ToString()
                                                ? 10
                                                : 9,
                                    ShippingName          = wayBillSfModel.ShippingName,
                                    ShippingCompany       = wayBillSfModel.ShippingCompany,
                                    ShippingTel           = wayBillSfModel.ShippingPhone,
                                    ShippingPhone         = wayBillSfModel.ShippingPhone,
                                    ShippingAddress       = wayBillSfModel.ShippingAddress,
                                    ParcelQuantity        = wayBillSfModel.PackageNumber,
                                    ShippingState         = wayBillSfModel.ShippingState,
                                    ShippingCity          = wayBillSfModel.ShippingCity,
                                    CountryCode           = wayBillSfModel.CountryCode,
                                    ShippingZip           = wayBillSfModel.ShippingZip,
                                    ApplicationTotalPrice =
                                        wayBillSfModel.ApplicationInfo.Sum(p => p.Qty * p.UnitPrice),
                                    ApplicationTotalWeight =
                                        wayBillSfModel.ApplicationInfo.Sum(p => p.Qty * p.UnitWeight)
                                };

                                if (!wayBillSfModel.ApplicationInfo.Any())
                                {
                                    SebController.SubmitFailure(wayBillSfModel.WayBillNumber, "没有申报信息");
                                    continue;
                                }
                                else
                                {
                                    wayBillSfModel.ApplicationInfo.ForEach(p => model.Applications.Add(new ApplicationSfModel()
                                    {
                                        ApplicationName = p.ApplicationName,
                                        Qty             = p.Qty,
                                        UnitPrice       = p.UnitPrice,
                                        UnitWeight      = p.UnitWeight
                                    }));
                                }
                                var parcel = LMSSFCommon.SubmitSf(model, _authorization);
                                if (parcel.ErrorMsg.IsNullOrWhiteSpace() && parcel.Model != null &&
                                    !parcel.Model.OrderId.IsNullOrWhiteSpace() &&
                                    !parcel.Model.MailNo.IsNullOrWhiteSpace())
                                {
                                    //if (LMSSFCommon.SfConfirm(parcel.Model.OrderId, parcel.Model.MailNo, _authorization))
                                    //{
                                    //记录成功
                                    SebController.SubmitSuccess(parcel.Model);
                                    //}
                                    //else
                                    //{
                                    //    //取消订单
                                    //    LMSSFCommon.SfConfirm(parcel.Model.OrderId, parcel.Model.MailNo, _authorization,
                                    //                          2);
                                    //}
                                }
                                else
                                {
                                    SebController.SubmitFailure(wayBillSfModel.WayBillNumber, parcel.ErrorMsg);
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Error("运单号:{0} 提交顺E宝API异常信息:{1}".FormatWith(wayBillSfModel.WayBillNumber, ex.Message));
                            }
                        }
                    }
                    pageindex++;
                } while (list.Count > (pageindex - 1) * pagesize);
            }
            Log.Info("完成预报顺E宝俄罗斯挂号,平邮");
            SebController.UpdateOutShippingMethod();
        }