|
|
|
|
using NetLibrary;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web.Script.Serialization;
|
|
|
|
|
using System.Net.Security;
|
|
|
|
|
using System.Security.Authentication;
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
namespace NetLibrary.OnlineTrade
|
|
|
|
|
{
|
|
|
|
|
public class CDiscountAPI
|
|
|
|
|
{
|
|
|
|
|
JavaScriptSerializer JsonConvert = null;
|
|
|
|
|
public CDiscountAPI()
|
|
|
|
|
{
|
|
|
|
|
//验证服务器证书回调自动验证
|
|
|
|
|
ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate;
|
|
|
|
|
JsonConvert = new JavaScriptSerializer();
|
|
|
|
|
}
|
|
|
|
|
private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public List<OrderModel> GetOrders(string Username,string password,string xml, out string ErrorMessage)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
List<OrderModel> ListModel = new List<OrderModel>();
|
|
|
|
|
string str = xml.Replace("@Token@", GetTokenInteg2(Username, password));
|
|
|
|
|
string XmlContent = PostSend2(str);
|
|
|
|
|
|
|
|
|
|
XmlContent = XmlContent.Replace("<s:", "<").Replace("</s:", "</").Replace("xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"", "")
|
|
|
|
|
.Replace("xmlns=\"http://www.cdiscount.com\"", "").Replace("xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"", "")
|
|
|
|
|
.Replace("i:nil=\"true\" xmlns=\"http://schemas.datacontract.org/2004/07/Cdiscount.Framework.Core.Communication.Messages\"", "")
|
|
|
|
|
.Replace("xmlns=\"http://schemas.datacontract.org/2004/07/Cdiscount.Framework.Core.Communication.Messages\"", "")
|
|
|
|
|
.Replace(" i:nil=\"true\"", "");
|
|
|
|
|
|
|
|
|
|
XElement root = XElement.Parse(XmlContent);
|
|
|
|
|
if (root.Element("Body").Element("GetOrderListResponse").Element("GetOrderListResult").Element("OperationSuccess").Value == "true")
|
|
|
|
|
{
|
|
|
|
|
foreach (XElement item in root.Element("Body").Element("GetOrderListResponse").Element("GetOrderListResult").Element("OrderList").Elements("Order"))
|
|
|
|
|
{
|
|
|
|
|
if (item.Element("OrderNumber").Value == "1601281426HLSQU")
|
|
|
|
|
{
|
|
|
|
|
string ttt = "";
|
|
|
|
|
}
|
|
|
|
|
OrderModel model = new OrderModel();
|
|
|
|
|
model.OrderCode = item.Element("OrderNumber").Value;//订单编号
|
|
|
|
|
model.PlatOrderCode = item.Element("OrderNumber").Value;//OrderLineItemID
|
|
|
|
|
|
|
|
|
|
Decimal totalprice = 0;
|
|
|
|
|
model.MoneyCode = "EUR";//币种
|
|
|
|
|
if (item.Element("CreationDate") != null)
|
|
|
|
|
model.OrderDate = Convert.ToDateTime(item.Element("CreationDate").Value.Substring(0, 18).Replace("T", " "));
|
|
|
|
|
model.BuyerID = item.Element("Customer").Element("CustomerId").Value;//EB买家ID
|
|
|
|
|
model.BuyerName = item.Element("ShippingAddress").Element("FirstName").Value + " " + item.Element("ShippingAddress").Element("LastName").Value;
|
|
|
|
|
model.BuyerCountry = item.Element("ShippingAddress").Element("Country").Value;
|
|
|
|
|
model.BuyerAddr = "";
|
|
|
|
|
if (string.IsNullOrEmpty(item.Element("ShippingAddress").Element("CompanyName").Value) == false)
|
|
|
|
|
{
|
|
|
|
|
if (item.Element("ShippingAddress").Element("CompanyName").Value != "")
|
|
|
|
|
{
|
|
|
|
|
model.BuyerAddr += item.Element("ShippingAddress").Element("CompanyName").Value + ",";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(item.Element("ShippingAddress").Element("Instructions").Value) == false)
|
|
|
|
|
{
|
|
|
|
|
if (item.Element("ShippingAddress").Element("Instructions").Value != "")
|
|
|
|
|
{
|
|
|
|
|
model.BuyerAddr += item.Element("ShippingAddress").Element("Instructions").Value + ",";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(item.Element("ShippingAddress").Element("ApartmentNumber").Value) == false)
|
|
|
|
|
{
|
|
|
|
|
if (item.Element("ShippingAddress").Element("ApartmentNumber").Value != "")
|
|
|
|
|
{
|
|
|
|
|
model.BuyerAddr += "Appartement " + item.Element("ShippingAddress").Element("ApartmentNumber").Value + ",";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(item.Element("ShippingAddress").Element("Building").Value) == false)
|
|
|
|
|
{
|
|
|
|
|
if (item.Element("ShippingAddress").Element("Building").Value != "")
|
|
|
|
|
{
|
|
|
|
|
model.BuyerAddr += "bâtiment " + item.Element("ShippingAddress").Element("Building").Value + ",";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(item.Element("ShippingAddress").Element("Address1").Value) == false)
|
|
|
|
|
{
|
|
|
|
|
model.BuyerAddr += item.Element("ShippingAddress").Element("Address1").Value+",";
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(item.Element("ShippingAddress").Element("Address2").Value) == false)
|
|
|
|
|
{
|
|
|
|
|
if (item.Element("ShippingAddress").Element("Address2").Value!="")
|
|
|
|
|
model.BuyerAddr += item.Element("ShippingAddress").Element("Address2").Value + ",";
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(item.Element("ShippingAddress").Element("Street").Value) == false)
|
|
|
|
|
{
|
|
|
|
|
if (item.Element("ShippingAddress").Element("Street").Value != "")
|
|
|
|
|
{
|
|
|
|
|
model.BuyerAddr = model.BuyerAddr.Replace(item.Element("ShippingAddress").Element("Street").Value,"");
|
|
|
|
|
model.BuyerAddr += item.Element("ShippingAddress").Element("Street").Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(item.Element("ShippingAddress").Element("PlaceName").Value) == false)
|
|
|
|
|
{
|
|
|
|
|
if (item.Element("ShippingAddress").Element("PlaceName").Value != "")
|
|
|
|
|
{
|
|
|
|
|
model.BuyerAddr += ","+item.Element("ShippingAddress").Element("PlaceName").Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//if (string.IsNullOrEmpty(item.Element("ShippingAddress").Element("County").Value) == false)
|
|
|
|
|
//{
|
|
|
|
|
// model.BuyerAddr += item.Element("ShippingAddress").Element("County").Value;
|
|
|
|
|
//}
|
|
|
|
|
if (string.IsNullOrEmpty(item.Element("Customer").Element("Phone").Value) == false)
|
|
|
|
|
{
|
|
|
|
|
model.BuyerPhone = item.Element("Customer").Element("Phone").Value;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(item.Element("Customer").Element("MobilePhone").Value) == false)
|
|
|
|
|
{
|
|
|
|
|
model.BuyerMobile = item.Element("Customer").Element("MobilePhone").Value;
|
|
|
|
|
}
|
|
|
|
|
model.BuyerMail = "";//电子邮件
|
|
|
|
|
|
|
|
|
|
model.BuyerFax = "";
|
|
|
|
|
model.BuyerZip = item.Element("ShippingAddress").Element("ZipCode").Value;
|
|
|
|
|
model.BuyerProvince = item.Element("ShippingAddress").Element("City").Value;
|
|
|
|
|
model.BuyerCity = item.Element("ShippingAddress").Element("City").Value;
|
|
|
|
|
model.BuyerArea = "";
|
|
|
|
|
|
|
|
|
|
model.OrderRemark = ""; //memo
|
|
|
|
|
model.LeaveWord = "";
|
|
|
|
|
if (item.Element("CreationDate") != null)
|
|
|
|
|
model.PayDate = Convert.ToDateTime(item.Element("CreationDate").Value.Substring(0, 18).Replace("T", " "));//到账时间
|
|
|
|
|
model.OutOrderDate = null;
|
|
|
|
|
|
|
|
|
|
model.ListModel = new List<OrderDetailModel>();
|
|
|
|
|
|
|
|
|
|
foreach (XElement item2 in item.Element("OrderLineList").Elements("OrderLine"))
|
|
|
|
|
{
|
|
|
|
|
OrderDetailModel model2 = new OrderDetailModel();
|
|
|
|
|
model2.GoodsNum = Convert.ToInt32(item2.Element("Quantity").Value);
|
|
|
|
|
model2.GoodsPrice = Convert.ToDecimal(item2.Element("PurchasePrice").Value);
|
|
|
|
|
totalprice += Convert.ToDecimal(item2.Element("PurchasePrice").Value);
|
|
|
|
|
|
|
|
|
|
model2.MoneyCode = model.MoneyCode;
|
|
|
|
|
|
|
|
|
|
model2.GoodsName = item2.Element("ProductCondition").Value;
|
|
|
|
|
|
|
|
|
|
model2.GoodsSKU = item2.Element("SellerProductId").Value;
|
|
|
|
|
if (item2.Element("ProductId").Value == "INTERETBCA") continue;
|
|
|
|
|
model.ListModel.Add(model2);
|
|
|
|
|
}
|
|
|
|
|
model.TotalPrice = totalprice - Convert.ToDecimal(item.Element("SiteCommissionValidatedAmount").Value) + Convert.ToDecimal(item.Element("ValidatedTotalShippingCharges").Value);
|
|
|
|
|
ListModel.Add(model);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//string ordertemp=root.Element
|
|
|
|
|
return ListModel;
|
|
|
|
|
}
|
|
|
|
|
public string SendTrack(string Username,string password,string xml)
|
|
|
|
|
{
|
|
|
|
|
string str = xml.Replace("@Token@", GetTokenInteg2(Username, password));
|
|
|
|
|
string XmlContent = PostSend3(str);
|
|
|
|
|
return XmlContent;
|
|
|
|
|
}
|
|
|
|
|
public string PostSend3(string output)
|
|
|
|
|
{
|
|
|
|
|
string strReturn = "";
|
|
|
|
|
byte[] obtPostData = Encoding.UTF8.GetBytes(output.ToString());
|
|
|
|
|
|
|
|
|
|
ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };
|
|
|
|
|
|
|
|
|
|
var webRequest = (HttpWebRequest)WebRequest.Create("https://wsvc.cdiscount.com/MarketplaceAPIService.svc");
|
|
|
|
|
webRequest.Headers.Add("SOAPAction", String.Format("\"{0}\"", "http://www.cdiscount.com/IMarketplaceAPIService/ValidateOrderList"));
|
|
|
|
|
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
|
|
|
|
|
webRequest.Accept = "text/xml;charset=UTF-8";
|
|
|
|
|
webRequest.Method = "POST";
|
|
|
|
|
|
|
|
|
|
//orqRequest.Headers.Add("Authorization", string.Format("Basic={0}", encoded));
|
|
|
|
|
|
|
|
|
|
Stream stream;
|
|
|
|
|
using (stream = webRequest.GetRequestStream())
|
|
|
|
|
{
|
|
|
|
|
stream.Write(obtPostData, 0, obtPostData.Length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HttpWebResponse orsResponse = (HttpWebResponse)webRequest.GetResponse();
|
|
|
|
|
|
|
|
|
|
using (Stream responseStream = orsResponse.GetResponseStream())
|
|
|
|
|
{
|
|
|
|
|
using (StreamReader streamRead = new StreamReader(responseStream, Encoding.UTF8))
|
|
|
|
|
{
|
|
|
|
|
strReturn = streamRead.ReadToEnd();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return strReturn;
|
|
|
|
|
}
|
|
|
|
|
public string PostSend2(string output)
|
|
|
|
|
{
|
|
|
|
|
string strReturn = "";
|
|
|
|
|
byte[] obtPostData = Encoding.UTF8.GetBytes(output.ToString());
|
|
|
|
|
|
|
|
|
|
ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };
|
|
|
|
|
|
|
|
|
|
var webRequest = (HttpWebRequest)WebRequest.Create("https://wsvc.cdiscount.com/MarketplaceAPIService.svc");
|
|
|
|
|
webRequest.Headers.Add("SOAPAction", String.Format("\"{0}\"", "http://www.cdiscount.com/IMarketplaceAPIService/GetOrderList"));
|
|
|
|
|
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
|
|
|
|
|
webRequest.Accept = "text/xml;charset=UTF-8";
|
|
|
|
|
webRequest.Method = "POST";
|
|
|
|
|
|
|
|
|
|
//orqRequest.Headers.Add("Authorization", string.Format("Basic={0}", encoded));
|
|
|
|
|
|
|
|
|
|
Stream stream;
|
|
|
|
|
using (stream = webRequest.GetRequestStream())
|
|
|
|
|
{
|
|
|
|
|
stream.Write(obtPostData, 0, obtPostData.Length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HttpWebResponse orsResponse = (HttpWebResponse)webRequest.GetResponse();
|
|
|
|
|
|
|
|
|
|
using (Stream responseStream = orsResponse.GetResponseStream())
|
|
|
|
|
{
|
|
|
|
|
using (StreamReader streamRead = new StreamReader(responseStream, Encoding.UTF8))
|
|
|
|
|
{
|
|
|
|
|
strReturn = streamRead.ReadToEnd();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return strReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetTokenInteg2(string username, string password)
|
|
|
|
|
{
|
|
|
|
|
const string svcIssue = "https://sts.cdiscount.com/users/httpIssue.svc";
|
|
|
|
|
const string svcToCall = "https://wsvc.cdiscount.com/MarketplaceAPIService.svc";
|
|
|
|
|
string strReturn = "";
|
|
|
|
|
|
|
|
|
|
ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };
|
|
|
|
|
|
|
|
|
|
string encoded = Convert.ToBase64String(Encoding.Default.GetBytes(string.Format("{0}:{1}", username, password)));
|
|
|
|
|
|
|
|
|
|
var stsUri = new Uri(string.Format("{0}/?realm={1}", svcIssue, svcToCall));
|
|
|
|
|
|
|
|
|
|
HttpWebRequest orqRequest = (HttpWebRequest)WebRequest.Create(stsUri);
|
|
|
|
|
orqRequest.Timeout = 3000;
|
|
|
|
|
|
|
|
|
|
orqRequest.Method = "GET";
|
|
|
|
|
orqRequest.ContentType = "text/xml; charset=utf-8";
|
|
|
|
|
orqRequest.Headers.Add("Authorization", string.Format("Basic={0}", encoded));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HttpWebResponse orsResponse = (HttpWebResponse)orqRequest.GetResponse();
|
|
|
|
|
|
|
|
|
|
using (Stream responseStream = orsResponse.GetResponseStream())
|
|
|
|
|
{
|
|
|
|
|
using (StreamReader streamRead = new StreamReader(responseStream, Encoding.UTF8))
|
|
|
|
|
{
|
|
|
|
|
strReturn = streamRead.ReadToEnd();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string[] tokenlist = strReturn.Split('>');
|
|
|
|
|
string[] list2 = tokenlist[1].Split('<');
|
|
|
|
|
|
|
|
|
|
return list2[0];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CDOrder
|
|
|
|
|
{
|
|
|
|
|
public string ArchiveParcelList { get; set; }
|
|
|
|
|
public string order_id { get; set; }
|
|
|
|
|
//public CDOrderShippingAddress ShippingAddress { get; set; }
|
|
|
|
|
public string CreationDate { get; set; }
|
|
|
|
|
public CDOrderCustomer Customer { get; set; }
|
|
|
|
|
public string HasClaims { get; set; }
|
|
|
|
|
public string InitialTotalAmount { get; set; }
|
|
|
|
|
public string InitialTotalShippingChargesAmount { get; set; }
|
|
|
|
|
public string LastUpdatedDate { get; set; }
|
|
|
|
|
public string ModifiedDate { get; set; }
|
|
|
|
|
public string Offer { get; set; }
|
|
|
|
|
public List<CDOrderGood> OrderLineList { get; set; }
|
|
|
|
|
public string OrderNumber { get; set; }
|
|
|
|
|
public string OrderState { get; set; }
|
|
|
|
|
public string ShippedTotalAmount { get; set; }
|
|
|
|
|
public string ShippedTotalShippingCharges { get; set; }
|
|
|
|
|
public CDOrderShippingAddress ShippingAddress { get; set; }
|
|
|
|
|
public string ShippingCode { get; set; }
|
|
|
|
|
public string SiteCommissionPromisedAmount { get; set; }
|
|
|
|
|
public string SiteCommissionShippedAmount { get; set; }
|
|
|
|
|
public string SiteCommissionValidatedAmount { get; set; }
|
|
|
|
|
public string Status { get; set; }
|
|
|
|
|
public string ValidatedTotalAmount { get; set; }
|
|
|
|
|
public string ValidatedTotalShippingCharges { get; set; }
|
|
|
|
|
public string ValidationStatus { get; set; }
|
|
|
|
|
public CDOrderCorporation Corporation { get; set; }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public class CDOrderBillAddress
|
|
|
|
|
{
|
|
|
|
|
public string Address1 { get; set; }
|
|
|
|
|
public string Address2 { get; set; }
|
|
|
|
|
public string ApartmentNumber { get; set; }
|
|
|
|
|
public string Building { get; set; }
|
|
|
|
|
public string City { get; set; }
|
|
|
|
|
public string Civility { get; set; }
|
|
|
|
|
public string CompanyName { get; set; }
|
|
|
|
|
public string Country { get; set; }
|
|
|
|
|
public string FirstName { get; set; }
|
|
|
|
|
public string Instructions { get; set; }
|
|
|
|
|
public string LastName { get; set; }
|
|
|
|
|
public string PlaceName { get; set; }
|
|
|
|
|
public string Street { get; set; }
|
|
|
|
|
public string ZipCode { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public class CDOrderCustomer
|
|
|
|
|
{
|
|
|
|
|
public string Civility { get; set; }
|
|
|
|
|
public string CustomerId { get; set; }
|
|
|
|
|
public string FirstName { get; set; }
|
|
|
|
|
public string LastName { get; set; }
|
|
|
|
|
public string MobilePhone { get; set; }
|
|
|
|
|
public string Phone { get; set; }
|
|
|
|
|
}
|
|
|
|
|
public class CDOrderGood
|
|
|
|
|
{
|
|
|
|
|
public CDOrderGoodDetail OrderLine { get; set; }
|
|
|
|
|
}
|
|
|
|
|
public class CDOrderGoodDetail
|
|
|
|
|
{
|
|
|
|
|
public string AcceptationState { get; set; }
|
|
|
|
|
public string CategoryCode { get; set; }
|
|
|
|
|
public string DeliveryDateMax { get; set; }
|
|
|
|
|
public string DeliveryDateMin { get; set; }
|
|
|
|
|
public string HasClaim { get; set; }
|
|
|
|
|
public string IsCDAV { get; set; }
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string OrderLineChildList { get; set; }
|
|
|
|
|
public string ProductCondition { get; set; }
|
|
|
|
|
public string ProductEan { get; set; }
|
|
|
|
|
public string ProductId { get; set; }
|
|
|
|
|
public string PurchasePrice { get; set; }
|
|
|
|
|
public string Quantity { get; set; }
|
|
|
|
|
public string RowId { get; set; }
|
|
|
|
|
public string SellerProductId { get; set; }
|
|
|
|
|
public string ShippingDateMax { get; set; }
|
|
|
|
|
public string ShippingDateMin { get; set; }
|
|
|
|
|
public string Sku { get; set; }
|
|
|
|
|
public string SkuParent { get; set; }
|
|
|
|
|
public string UnitAdditionalShippingCharges { get; set; }
|
|
|
|
|
public string UnitShippingCharges { get; set; }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public class CDOrderShippingAddress
|
|
|
|
|
{
|
|
|
|
|
public string Address1 { get; set; }
|
|
|
|
|
public string Address2 { get; set; }
|
|
|
|
|
public string ApartmentNumber { get; set; }
|
|
|
|
|
public string Building { get; set; }
|
|
|
|
|
public string City { get; set; }
|
|
|
|
|
public string Civility { get; set; }
|
|
|
|
|
public string CompanyName { get; set; }
|
|
|
|
|
public string Country { get; set; }
|
|
|
|
|
public string FirstName { get; set; }
|
|
|
|
|
public string Instructions { get; set; }
|
|
|
|
|
public string LastName { get; set; }
|
|
|
|
|
public string PlaceName { get; set; }
|
|
|
|
|
public string Street { get; set; }
|
|
|
|
|
public string ZipCode { get; set; }
|
|
|
|
|
}
|
|
|
|
|
public class CDOrderCorporation
|
|
|
|
|
{
|
|
|
|
|
public string CorporationId { get; set; }
|
|
|
|
|
public string CorporationName { get; set; }
|
|
|
|
|
public string BusinessUnitId { get; set; }
|
|
|
|
|
public string IsMarketPlaceActive { get; set; }
|
|
|
|
|
public string CorporationCode { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|