|
@@ -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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|