Parcourir la source

美盛对接完成

lzk il y a 1 semaine
Parent
commit
87201a3e8a

+ 164 - 0
3.Service/XYY.Service.Standard.ChannelApi/HW_ShengMei/Api.cs

@@ -0,0 +1,164 @@
+using Newtonsoft.Json;
+using RestSharp;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Channels;
+using System.Threading.Tasks;
+using System.Xml;
+using XYY.Common.Standard;
+using XYY.Model.Standard.Channel;
+using XYY.Model.Standard.Order;
+using XYY.Service.Standard.ChannelApi.Base;
+using XYY.Service.Standard.ChannelApi.myDHL;
+using XYY.Service.Standard.ChannelApi.WiSh;
+
+namespace XYY.Service.Standard.ChannelApi.HW_ShengMei
+{
+    public class Api : IBaseApi
+    {
+        public string ServiceName => "MeiSheng";
+
+        public Api()
+        {
+        }
+        public async Task<UploadResult> DataUpload(Order_Order order, List<Order_OrderGoods> goods, Logistics_Channel channel, ExtendArg arg)
+        {
+            var body = await ConvertRequestBody(order, goods, channel, arg.AgentIOSS);
+            string json = JsonConvert.SerializeObject(body);
+            RestClient client = new RestClient(channel.ApiHost + "/WebService/PublicService.asmx/CreateOrder");//+ ActioinUrl
+            RestRequest request = new RestRequest(Method.POST);
+            request.AddParameter("Token", channel.ApiSecret);
+            request.AddParameter("ParamsJson", json);
+
+            var response = client.Execute(request);
+            if (response.StatusCode == System.Net.HttpStatusCode.OK)
+            {
+                XmlDocument doc = new XmlDocument();
+                doc.LoadXml(response.Content);
+                string resultJson = doc.InnerText;
+                var result = JsonConvert.DeserializeObject<BaseResult>(resultJson);
+                if (result.code == "0")
+                {
+                    var uploadResult = new UploadResult
+                    {
+                        IsSuccess = true,
+                        DownloadUrl = result.LabelUrl,
+                        ServiceOrderNumber = result.OrderNo,
+                        TrackingNumber = result.TrackingNo,
+                        ServiceOrderNumber3 = body.CsRefNo,
+                    };
+                    return uploadResult;
+                }
+                else
+                {
+                    throw new Exception($"下单[{body.CsRefNo}]失败:{result.msg}");
+                }
+            }
+            else
+            {
+                throw new Exception($"下单[{body.CsRefNo}]异常:{response.Content ?? response.ErrorMessage}");
+            }
+        }
+        public async Task<byte[]> DrawPdfLabel(UploadResult result, Logistics_Channel channel, Order_Order order, List<Order_OrderGoods> orderGoods)
+        {
+            return new WebClient().DownloadData(result.DownloadUrl);
+        }
+        public async Task CannelOrdersByModel(logistics_ChannelCancel logistics_ChannelCancel)
+        {
+            RestClient client = new RestClient(logistics_ChannelCancel.ApiHost + "/WebService/PublicService.asmx/CreateOrder");//+ ActioinUrl
+            RestRequest request = new RestRequest(Method.POST);
+            request.AddParameter("Token", logistics_ChannelCancel.ApiSecret);
+            request.AddParameter("OrderNo", logistics_ChannelCancel.ServicesOrderNo);
+
+            var response = client.Execute(request);
+            if (response.StatusCode == System.Net.HttpStatusCode.OK)
+            {
+                XmlDocument doc = new XmlDocument();
+                doc.LoadXml(response.Content);
+                string resultJson = doc.InnerText;
+                var result = JsonConvert.DeserializeObject<BaseResult>(resultJson);
+                if (result.code != "0")
+                {
+                    throw new Exception("订单取消失败:" + result.msg);
+                }
+            }
+            else
+            {
+                throw new Exception($"订单取消[{logistics_ChannelCancel.SystemNo}]异常:{response.Content ?? response.ErrorMessage}");
+            }
+
+        }
+        public async Task<List<BagDeclareErrosResult>> BagDeclare(BagDeclareRequest bagDeclareRequest)
+        {
+            throw new NotImplementedException();
+        }
+
+
+        public Task<List<string>> Confims(List<OrderConfimRequest> order, Logistics_Channel channel)
+        {
+
+            throw new NotImplementedException();
+        }
+        public Task<string> GetTrackingNumber(string SystemNo, string TrackingNumber, string ServiceOrderNo, Logistics_Channel channel)
+        {
+            throw new NotImplementedException();
+        }
+        public Task CannelOrders(List<String> systemNO)
+        {
+            throw new NotImplementedException();
+        }
+        private async Task<DataUploadRequest> ConvertRequestBody(Order_Order order, List<Order_OrderGoods> goods, Logistics_Channel channel, bool AgentIOSS)
+        {
+            var addressArr = XYY.Core.Standard.ExtendMethods.StringExtendMethods.ToArray(order.ReceiverStreet, 50);
+            if (addressArr.Count() > 2) { throw new Exception("地址长度超过100个字符"); }
+
+            DataUploadRequest dataUploadRequest = new DataUploadRequest()
+            {
+                CsRefNo = order.SystemNo.Replace("XYY", "").Replace("YQ", ""),
+                ShipperService = channel.ServiceChannelCode,
+
+                //发件人信息
+                ShipperName = channel.SenderName,
+                ShipperAddress = channel.SenderStreet,
+                ShipperPhone = channel.SenderPhone,
+                ShipperCity = channel.SenderCity,
+                ShipperState = channel.SenderState,
+                ShipperZipCode = channel.SenderZipCode,
+
+                //收件人信息
+                ConsigneeName = order.ReceiverName,
+                CountryCode = order.ReceiverCountryCode,
+                State = order.ReceiverState,
+                City = order.ReceiverCity,
+                Zipcode = order.ReceiverZipCode,
+                Address1 = addressArr[0],
+                Address2 = addressArr.Length > 1 ? addressArr[1] : null,
+                Contact = order.ReceiverPhone,
+                Email = order.ReceiverEmail,
+                Company = order.ReceiverCompany,
+            };
+            var unitWeight = order.CustomerWeight / goods.Sum(x => x.Quantity);
+            dataUploadRequest.OrderDetail = new List<OrderDetailItem>();
+            foreach (var item in goods.GroupBy(x => x.EnName))
+            {
+                OrderDetailItem orderDetailItem = new OrderDetailItem()
+                {
+                    EnName = item.Key,
+                    CnName = item.FirstOrDefault().CnName,
+                    Quantity = item.Sum(x => x.Quantity).ToString(),
+                    Weight = item.FirstOrDefault().Weight != 0 ? (item.FirstOrDefault().Weight / 1000.0m).ToString("0.000") : (unitWeight / 1000.0m).ToString("0.000"),
+                    Price = item.FirstOrDefault().DeclareFee.ToString("0.00"),
+                    HSCode = item.FirstOrDefault().HsCode,
+                    Length = 1,
+                    Width = 1,
+                    High = 1,
+                };
+                dataUploadRequest.OrderDetail.Add(orderDetailItem);
+            }
+            return dataUploadRequest;
+        }
+    }
+}

+ 37 - 0
3.Service/XYY.Service.Standard.ChannelApi/HW_ShengMei/BaseResult.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace XYY.Service.Standard.ChannelApi.HW_ShengMei
+{
+    public class BaseResult
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        public string code { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string msg { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string OrderNo { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string CsRefNo { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string TrackingNo { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string LabelUrl { get; set; }
+    }
+
+}

+ 164 - 0
3.Service/XYY.Service.Standard.ChannelApi/HW_ShengMei/DataUploadRequest.cs

@@ -0,0 +1,164 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace XYY.Service.Standard.ChannelApi.HW_ShengMei
+{
+    public class OrderDetailItem
+    {
+        /// <summary>
+        /// 杯子
+        /// </summary>
+        public string CnName { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string EnName { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string SKU { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string Quantity { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string Weight { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public int Length { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public int Width { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public int High { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string Price { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string HSCode { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string Origin { get; set; }
+    }
+
+    public class OrderBagsItem
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        public int Weight { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public int Length { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public int Width { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public int Height { get; set; }
+    }
+
+    public class DataUploadRequest
+    {
+        /// <summary>
+        /// 	1仓储/2转运订单
+        /// </summary>
+        public string Style { get; set; } = "2";
+        /// <summary>
+        /// 
+        /// </summary>
+        public string ShipperName { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string ShipperAddress { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string ShipperPhone { get; set; }
+        public string ShipperState { get; set; }
+
+        public string ShipperCity { get; set; }
+        public string ShipperZipCode { get; set; }
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public string CsRefNo { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string ConsigneeName { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string CountryCode { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string ShipperService { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string Zipcode { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string State { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string City { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string Address1 { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string Address2 { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string Contact { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string Email { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string Company { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string StockID { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public List<OrderDetailItem> OrderDetail { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        //public List<OrderBagsItem> OrderBags { get; set; }
+    }
+
+
+}