|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using NetLibrary.OnlineTrade;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using NetLibrary;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Web.Script.Serialization;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using NetLibrary.Log;
|
|
|
|
|
using ApiNew;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace TradeManageNew
|
|
|
|
|
{
|
|
|
|
|
public class AmazonNewApi
|
|
|
|
|
{
|
|
|
|
|
public string SellerId { get; set; }
|
|
|
|
|
public string country { get; set; }
|
|
|
|
|
public string MWSAuthToken { get; set; }
|
|
|
|
|
public string SumoolToKen { get; set; }
|
|
|
|
|
public string MarketplaceId { get; set; }
|
|
|
|
|
|
|
|
|
|
// List<Alibaba_OrderCode> olist = new List<Alibaba_OrderCode>();
|
|
|
|
|
///解码
|
|
|
|
|
|
|
|
|
|
#region 读取订单列表
|
|
|
|
|
public List<OrderModel> GetOrdersNew(DateTime? StartDate, DateTime? StopDate, string FulfillmentChannel, List<Alibaba_OrderCode> olist, out string ErrorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (olist == null)
|
|
|
|
|
olist = new List<Alibaba_OrderCode>();
|
|
|
|
|
List<OrderModel> ListModel = new List<OrderModel>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
if (StartDate == null)
|
|
|
|
|
StartDate = DateTime.Today.AddDays(-3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string ServiceURL = "";
|
|
|
|
|
|
|
|
|
|
#region 设置市场所在地借口地址
|
|
|
|
|
switch (country)
|
|
|
|
|
{
|
|
|
|
|
case "美国":
|
|
|
|
|
ServiceURL = "https://sellingpartnerapi-na.amazon.com";
|
|
|
|
|
break;
|
|
|
|
|
case "加拿大":
|
|
|
|
|
ServiceURL = "https://sellingpartnerapi-na.amazon.com";
|
|
|
|
|
break;
|
|
|
|
|
case "欧洲":
|
|
|
|
|
ServiceURL = "https://mws-eu.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "日本":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.jp";
|
|
|
|
|
break;
|
|
|
|
|
case "中国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com.cn";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
string url = "http://api.sumool.com/AmazonProxy/NewSendRequest";
|
|
|
|
|
string str = "EndPoint=" + ServiceURL;
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
string body = "{\"CreatedAfter\":\"2022-02-25T07: 27:29.289Z\",\"OrderStatuses\":\"Shipped\",\"FulfillmentChannels\":\"MFN\",\"MarketplaceIds\":\"" + MarketplaceId + "\",\"MaxResultsPerPage\":5}";
|
|
|
|
|
byte[] bytes = Encoding.Default.GetBytes(body);
|
|
|
|
|
string bb= Convert.ToBase64String(bytes);
|
|
|
|
|
str += "&BodyContent="+bb;
|
|
|
|
|
str += "&Command=/orders/v0/orders";
|
|
|
|
|
str += "&HttpMethod=Get";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
|
|
|
|
|
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
|
|
|
|
|
|
|
|
AMResult model2 = JsonConvert.Deserialize<AMResult>(XmlContent);
|
|
|
|
|
if (model2.HasError == true)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = model2.Message;
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
string xml = model2.ResultObject.Replace("xmlns=\"https://mws.amazonservices.com/Orders/2013-09-01\"", "");
|
|
|
|
|
XElement xt = XElement.Parse(xml);
|
|
|
|
|
XElement xel = xt.Element("ListOrdersResult").Element("Orders"); // <ListOrdersResult>\n <Orders>\n
|
|
|
|
|
|
|
|
|
|
string nexttoken = "";
|
|
|
|
|
if (xt.Element("ListOrdersResult") != null && xt.Element("ListOrdersResult").Element("NextToken") != null)
|
|
|
|
|
nexttoken = xt.Element("ListOrdersResult").Element("NextToken").Value;
|
|
|
|
|
// GetNext(nexttoken);
|
|
|
|
|
|
|
|
|
|
foreach (XElement item in xel.Elements("Order"))
|
|
|
|
|
{
|
|
|
|
|
System.Threading.Thread.Sleep(1000);
|
|
|
|
|
if (item.Element("Canceled") != null && item.Element("OrderStatus").Value == "Canceled")
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (item.Element("OrderTotal") == null || item.Element("OrderTotal").Element("Amount") == null || item.Element("OrderTotal").Element("Amount").Value == "")
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
OrderModel model = new OrderModel();
|
|
|
|
|
model.OrderCode = item.Element("AmazonOrderId").Value;//订单编号
|
|
|
|
|
if (model.OrderCode == "113-1276800-3025014")
|
|
|
|
|
{
|
|
|
|
|
string a = "";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
model.PlatOrderCode = item.Element("AmazonOrderId").Value;//OrderLineItemID
|
|
|
|
|
if (model.PlatOrderCode == null || model.PlatOrderCode == "")
|
|
|
|
|
continue;
|
|
|
|
|
if (olist != null)
|
|
|
|
|
{
|
|
|
|
|
var amd = olist.Find(n => n.OrderCode == model.PlatOrderCode);
|
|
|
|
|
if (amd != null)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model.TotalPrice = Convert.ToDecimal(item.Element("OrderTotal").Element("Amount").Value);
|
|
|
|
|
model.MoneyCode = "USD";//币种
|
|
|
|
|
|
|
|
|
|
if (item.Element("PurchaseDate") != null)
|
|
|
|
|
model.OrderDate = Convert.ToDateTime(item.Element("PurchaseDate").Value.Substring(0, 18).Replace("T", " ")).AddHours(8);
|
|
|
|
|
if (item.Element("FulfillmentChannel") != null)
|
|
|
|
|
model.BuyerID = item.Element("FulfillmentChannel").Value;
|
|
|
|
|
else
|
|
|
|
|
model.BuyerID = "MFN";
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("Name") != null)
|
|
|
|
|
model.BuyerName = item.Element("ShippingAddress").Element("Name").Value;
|
|
|
|
|
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("CountryCode") != null && item.Element("ShippingAddress").Element("CountryCode").Value != "")
|
|
|
|
|
model.BuyerCountry = item.Element("ShippingAddress").Element("CountryCode").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressLine1") != null && item.Element("ShippingAddress").Element("AddressLine1").Value != "")
|
|
|
|
|
model.BuyerAddr = item.Element("ShippingAddress").Element("AddressLine1").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressLine2") != null && item.Element("ShippingAddress").Element("AddressLine2").Value != "")
|
|
|
|
|
model.BuyerAddr += " " + item.Element("ShippingAddress").Element("AddressLine2").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressLine3") != null && item.Element("ShippingAddress").Element("AddressLine3").Value != "")
|
|
|
|
|
model.BuyerAddr += " " + item.Element("ShippingAddress").Element("AddressLine3").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("County") != null && item.Element("ShippingAddress").Element("County").Value != "")
|
|
|
|
|
model.BuyerAddr += " " + item.Element("ShippingAddress").Element("County").Value;
|
|
|
|
|
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("Phone") != null && item.Element("ShippingAddress").Element("Phone").Value != "")
|
|
|
|
|
model.BuyerPhone = item.Element("ShippingAddress").Element("Phone").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("StateOrRegion") != null)
|
|
|
|
|
model.BuyerProvince = item.Element("ShippingAddress").Element("StateOrRegion").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("City") != null)
|
|
|
|
|
model.BuyerCity = item.Element("ShippingAddress").Element("City").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("District") != null && item.Element("ShippingAddress").Element("District").Value != "")
|
|
|
|
|
model.BuyerArea = item.Element("ShippingAddress").Element("District").Value;
|
|
|
|
|
model.BuyerMobile = "";
|
|
|
|
|
if (item.Element("BuyerEmail") != null)
|
|
|
|
|
model.BuyerMail = item.Element("BuyerEmail").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressType") != null)
|
|
|
|
|
model.BuyerFax = item.Element("ShippingAddress").Element("AddressType").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("PostalCode") != null)
|
|
|
|
|
model.BuyerZip = item.Element("ShippingAddress").Element("PostalCode").Value;
|
|
|
|
|
|
|
|
|
|
model.OrderRemark = "";
|
|
|
|
|
model.LeaveWord = "";
|
|
|
|
|
|
|
|
|
|
if (item.Element("LastUpdateDate") != null)
|
|
|
|
|
model.PayDate = Convert.ToDateTime(item.Element("LastUpdateDate").Value.Substring(0, 18).Replace("T", " ")).AddHours(8);
|
|
|
|
|
|
|
|
|
|
if (item.Element("LatestDeliveryDate") != null)
|
|
|
|
|
model.OutOrderDate = Convert.ToDateTime(item.Element("LatestDeliveryDate").Value.Substring(0, 18).Replace("T", " ")).AddHours(8);
|
|
|
|
|
if (model.OrderDate != null && model.OrderDate.Value <= Convert.ToDateTime("1753-01-01"))
|
|
|
|
|
{
|
|
|
|
|
model.OrderDate = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
if (model.PayDate != null && model.PayDate.Value <= Convert.ToDateTime("1753-01-01"))
|
|
|
|
|
{
|
|
|
|
|
model.PayDate = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
if (model.OutOrderDate != null && model.OutOrderDate.Value <= Convert.ToDateTime("1753-01-01"))
|
|
|
|
|
{
|
|
|
|
|
model.OutOrderDate = DateTime.Now.AddDays(7);
|
|
|
|
|
}
|
|
|
|
|
model.PostInfo = item.Element("ShipServiceLevel").Value;
|
|
|
|
|
model.ListModel = new List<OrderDetailModel>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
str = "EndPoint=" + ServiceURL;
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
str += "&MWSAuthToken=" + MWSAuthToken;
|
|
|
|
|
str += "&Action=ListOrderItems";
|
|
|
|
|
str += "&AmazonOrderId=" + model.PlatOrderCode;
|
|
|
|
|
str += "&SignatureVersion=2";
|
|
|
|
|
str += "&Version=2013-09-01";
|
|
|
|
|
str += "&Command=/Orders/2013-09-01";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
string XmlContent2 = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", "", ErrorMessage);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AMResult model3 = JsonConvert.Deserialize<AMResult>(XmlContent2);
|
|
|
|
|
if (model3.HasError == true)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = model3.Message;
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", "", ErrorMessage);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
string xml2 = model3.ResultObject.Replace("xmlns=\"https://mws.amazonservices.com/Orders/2013-09-01\"", "");
|
|
|
|
|
XElement xt2 = XElement.Parse(xml2);
|
|
|
|
|
XElement xel2 = xt2.Element("ListOrderItemsResult").Element("OrderItems");
|
|
|
|
|
model.escrowFee = 0;
|
|
|
|
|
foreach (XElement item2 in xel2.Elements("OrderItem"))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
OrderDetailModel gmodel = new OrderDetailModel();
|
|
|
|
|
gmodel.productImgUrl = item2.Element("ASIN").Value;//订单编号
|
|
|
|
|
|
|
|
|
|
if (item2.Element("ItemTax") != null && item2.Element("ItemTax").Element("Amount") != null)
|
|
|
|
|
model.escrowFee += Convert.ToDecimal(item2.Element("ItemTax").Element("Amount").Value);
|
|
|
|
|
|
|
|
|
|
if (item2.Element("ShippingTax") != null && item2.Element("ShippingTax").Element("Amount") != null)
|
|
|
|
|
model.escrowFee += Convert.ToDecimal(item2.Element("ShippingTax").Element("Amount").Value);
|
|
|
|
|
|
|
|
|
|
gmodel.GoodsNum = Convert.ToInt32(item2.Element("QuantityOrdered").Value);
|
|
|
|
|
if (item2.Element("ItemPrice") != null && item2.Element("ItemPrice").Element("Amount") != null)
|
|
|
|
|
{
|
|
|
|
|
gmodel.GoodsPrice = Convert.ToDecimal(item2.Element("ItemPrice").Element("Amount").Value);
|
|
|
|
|
gmodel.MoneyCode = item2.Element("ItemPrice").Element("CurrencyCode").Value;
|
|
|
|
|
}
|
|
|
|
|
gmodel.GoodsName = item2.Element("Title").Value;
|
|
|
|
|
gmodel.GoodsSKU = item2.Element("SellerSKU").Value;
|
|
|
|
|
gmodel.PostInfo = model.PostInfo;
|
|
|
|
|
gmodel.OrderItemId = item2.Element("OrderItemId").Value;
|
|
|
|
|
model.ListModel.Add(gmodel);
|
|
|
|
|
}
|
|
|
|
|
// model.TotalPrice = model.TotalPrice - model.escrowFee;
|
|
|
|
|
ListModel.Add(model);
|
|
|
|
|
}
|
|
|
|
|
while (nexttoken != "")
|
|
|
|
|
{
|
|
|
|
|
string NextToken2 = "";
|
|
|
|
|
System.Threading.Thread.Sleep(5000);
|
|
|
|
|
var nlist = GetNext(nexttoken, olist, out NextToken2);
|
|
|
|
|
if (nlist != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var md in nlist)
|
|
|
|
|
{
|
|
|
|
|
ListModel.Add(md);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nexttoken = NextToken2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ListModel;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", ex.StackTrace, ex.Message);
|
|
|
|
|
ErrorMessage = ex.Message;
|
|
|
|
|
return ListModel;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 创建报表
|
|
|
|
|
public string CreatRetuenReport(out string ErrorMessage)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
List<OrderModel> ListModel = new List<OrderModel>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string ServiceURL = "";
|
|
|
|
|
|
|
|
|
|
#region 设置市场所在地借口地址
|
|
|
|
|
switch (country)
|
|
|
|
|
{
|
|
|
|
|
case "美国":
|
|
|
|
|
ServiceURL = "https://sellingpartnerapi-na.amazon.com";
|
|
|
|
|
break;
|
|
|
|
|
case "加拿大":
|
|
|
|
|
ServiceURL = "https://sellingpartnerapi-na.amazon.com";
|
|
|
|
|
break;
|
|
|
|
|
case "欧洲":
|
|
|
|
|
ServiceURL = "https://mws-eu.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "日本":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.jp";
|
|
|
|
|
break;
|
|
|
|
|
case "中国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com.cn";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
string url = "http://api.sumool.com/AmazonProxy/NewSendRequest";
|
|
|
|
|
string str = "EndPoint=" + ServiceURL;
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
string stime = DateTime.Now.AddDays(-60).ToString("yyyy-MM-dd") + "T00: 00:00";
|
|
|
|
|
string etime = DateTime.Now.ToString("yyyy-MM-dd") + "T00: 00:00";
|
|
|
|
|
string body = "{\"reportType\":\"GET_XML_RETURNS_DATA_BY_RETURN_DATE\",\"marketplaceIds\":[\"" + MarketplaceId + "\"],\"dataStartTime\":\""+ stime+ "\",\"dataEndTime\":\"" + etime + "\"}";
|
|
|
|
|
byte[] bytes = Encoding.Default.GetBytes(body);
|
|
|
|
|
string bb = Convert.ToBase64String(bytes);
|
|
|
|
|
str += "&BodyContent=" + bb;
|
|
|
|
|
str += "&Command=/reports/2021-06-30/reports";
|
|
|
|
|
str += "&HttpMethod=Post";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
|
|
|
|
|
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", ex.StackTrace, ex.Message);
|
|
|
|
|
ErrorMessage = ex.Message;
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取报表
|
|
|
|
|
public string GetRetuenReport(string reportId,out string ErrorMessage)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
List<OrderModel> ListModel = new List<OrderModel>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string ServiceURL = "";
|
|
|
|
|
|
|
|
|
|
#region 设置市场所在地借口地址
|
|
|
|
|
switch (country)
|
|
|
|
|
{
|
|
|
|
|
case "美国":
|
|
|
|
|
ServiceURL = "https://sellingpartnerapi-na.amazon.com";
|
|
|
|
|
break;
|
|
|
|
|
case "加拿大":
|
|
|
|
|
ServiceURL = "https://sellingpartnerapi-na.amazon.com";
|
|
|
|
|
break;
|
|
|
|
|
case "欧洲":
|
|
|
|
|
ServiceURL = "https://mws-eu.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "日本":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.jp";
|
|
|
|
|
break;
|
|
|
|
|
case "中国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com.cn";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
string url = "http://api.sumool.com/AmazonProxy/NewSendRequest";
|
|
|
|
|
string str = "EndPoint=" + ServiceURL;
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
string body = "{\"reportType\":\"GET_XML_RETURNS_DATA_BY_RETURN_DATE\",\"marketplaceIds\":[\"" + MarketplaceId + "\"]}";
|
|
|
|
|
byte[] bytes = Encoding.Default.GetBytes(body);
|
|
|
|
|
string bb = Convert.ToBase64String(bytes);
|
|
|
|
|
// str += "&BodyContent=" + bb;
|
|
|
|
|
str += "&Command=/reports/2021-06-30/reports/"+ reportId;
|
|
|
|
|
str += "&HttpMethod=Get";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
|
|
|
|
|
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", ex.StackTrace, ex.Message);
|
|
|
|
|
ErrorMessage = ex.Message;
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 读取订单列表
|
|
|
|
|
public string GetSorts(out string ErrorMessage)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
List<OrderModel> ListModel = new List<OrderModel>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string ServiceURL = "";
|
|
|
|
|
|
|
|
|
|
#region 设置市场所在地借口地址
|
|
|
|
|
switch (country)
|
|
|
|
|
{
|
|
|
|
|
case "美国":
|
|
|
|
|
ServiceURL = "https://sellingpartnerapi-na.amazon.com";
|
|
|
|
|
break;
|
|
|
|
|
case "加拿大":
|
|
|
|
|
ServiceURL = "https://sellingpartnerapi-na.amazon.com";
|
|
|
|
|
break;
|
|
|
|
|
case "欧洲":
|
|
|
|
|
ServiceURL = "https://mws-eu.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "日本":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.jp";
|
|
|
|
|
break;
|
|
|
|
|
case "中国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com.cn";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
string url = "http://api.sumool.com/AmazonProxy/NewSendRequest";
|
|
|
|
|
string str = "EndPoint=" + ServiceURL;
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
string body ="" ;// "{\"reportType\":\"GET_XML_BROWSE_TREE_DATA\",\"marketplaceIds\":[\"" + MarketplaceId + "\"]}";
|
|
|
|
|
byte[] bytes = Encoding.Default.GetBytes(body);
|
|
|
|
|
string bb = Convert.ToBase64String(bytes);
|
|
|
|
|
str += "&BodyContent=" + bb;
|
|
|
|
|
str += "&Command=/reports/2021-06-30/documents/amzn1.spdoc.1.3.41aa9541-d277-4090-aafc-a8c5f6b522d5.T1P8HX91PAW6WL.400";
|
|
|
|
|
str += "&HttpMethod=Get";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
|
|
|
|
|
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", ex.StackTrace, ex.Message);
|
|
|
|
|
ErrorMessage = ex.Message;
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 读取订单列表
|
|
|
|
|
public List<OrderModel> GetOrders(DateTime? StartDate, DateTime? StopDate, string FulfillmentChannel,List<Alibaba_OrderCode> olist, out string ErrorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (olist == null)
|
|
|
|
|
olist = new List<Alibaba_OrderCode>();
|
|
|
|
|
List<OrderModel> ListModel = new List<OrderModel>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
if (StartDate == null)
|
|
|
|
|
StartDate = DateTime.Today.AddDays(-3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string ServiceURL = "";
|
|
|
|
|
|
|
|
|
|
#region 设置市场所在地借口地址
|
|
|
|
|
switch (country)
|
|
|
|
|
{
|
|
|
|
|
case "美国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "加拿大":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.ca";
|
|
|
|
|
break;
|
|
|
|
|
case "欧洲":
|
|
|
|
|
ServiceURL = "https://mws-eu.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "日本":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.jp";
|
|
|
|
|
break;
|
|
|
|
|
case "中国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com.cn";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
string url = "http://api.sumool.com/AmazonProxy/SendRequest";
|
|
|
|
|
string str = "EndPoint=" + ServiceURL;
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
str += "&MWSAuthToken=" + MWSAuthToken;
|
|
|
|
|
str += "&Action=ListOrders";
|
|
|
|
|
str += "&LastUpdatedAfter=" + StartDate.Value.ToString("yyyy-MM-dd") + "T00:00:00";
|
|
|
|
|
str += "&SignatureVersion=2";
|
|
|
|
|
str += "&Version=2013-09-01";
|
|
|
|
|
if (FulfillmentChannel == "AFN")
|
|
|
|
|
{
|
|
|
|
|
str += "&OrderStatus.Status.1=Shipped";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
str += "&OrderStatus.Status.1=Unshipped";
|
|
|
|
|
str += "&OrderStatus.Status.2=PartiallyShipped";
|
|
|
|
|
}
|
|
|
|
|
str += "&FulfillmentChannel.Channel.1=" + FulfillmentChannel;//MFN,AFN";
|
|
|
|
|
str += "&Command=/Orders/2013-09-01";
|
|
|
|
|
str += "&MarketplaceId.Id.1=" + MarketplaceId;
|
|
|
|
|
str += "&MaxResultsPerPage=50";
|
|
|
|
|
var data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
|
|
|
|
|
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
|
|
|
|
|
|
|
|
AMResult model2 = JsonConvert.Deserialize<AMResult>(XmlContent);
|
|
|
|
|
if (model2.HasError == true)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = model2.Message;
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
string xml = model2.ResultObject.Replace("xmlns=\"https://mws.amazonservices.com/Orders/2013-09-01\"", "");
|
|
|
|
|
XElement xt = XElement.Parse(xml);
|
|
|
|
|
XElement xel = xt.Element("ListOrdersResult").Element("Orders"); // <ListOrdersResult>\n <Orders>\n
|
|
|
|
|
|
|
|
|
|
string nexttoken = "";
|
|
|
|
|
if (xt.Element("ListOrdersResult")!= null&&xt.Element("ListOrdersResult").Element("NextToken")!= null)
|
|
|
|
|
nexttoken=xt.Element("ListOrdersResult").Element("NextToken").Value;
|
|
|
|
|
// GetNext(nexttoken);
|
|
|
|
|
|
|
|
|
|
foreach (XElement item in xel.Elements("Order"))
|
|
|
|
|
{
|
|
|
|
|
System.Threading.Thread.Sleep(1000);
|
|
|
|
|
if (item.Element("Canceled") != null && item.Element("OrderStatus").Value == "Canceled")
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (item.Element("OrderTotal") == null || item.Element("OrderTotal").Element("Amount") == null || item.Element("OrderTotal").Element("Amount").Value == "")
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
OrderModel model = new OrderModel();
|
|
|
|
|
model.OrderCode = item.Element("AmazonOrderId").Value;//订单编号
|
|
|
|
|
if (model.OrderCode == "113-1276800-3025014")
|
|
|
|
|
{
|
|
|
|
|
string a = "";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
model.PlatOrderCode = item.Element("AmazonOrderId").Value;//OrderLineItemID
|
|
|
|
|
if (model.PlatOrderCode == null || model.PlatOrderCode == "")
|
|
|
|
|
continue;
|
|
|
|
|
if (olist != null)
|
|
|
|
|
{
|
|
|
|
|
var amd = olist.Find(n => n.OrderCode == model.PlatOrderCode);
|
|
|
|
|
if (amd != null)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model.TotalPrice = Convert.ToDecimal(item.Element("OrderTotal").Element("Amount").Value);
|
|
|
|
|
model.MoneyCode = "USD";//币种
|
|
|
|
|
|
|
|
|
|
if (item.Element("PurchaseDate") != null)
|
|
|
|
|
model.OrderDate = Convert.ToDateTime(item.Element("PurchaseDate").Value.Substring(0, 18).Replace("T", " ")).AddHours(8);
|
|
|
|
|
if (item.Element("FulfillmentChannel") != null)
|
|
|
|
|
model.BuyerID = item.Element("FulfillmentChannel").Value;
|
|
|
|
|
else
|
|
|
|
|
model.BuyerID = "MFN";
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("Name") != null)
|
|
|
|
|
model.BuyerName = item.Element("ShippingAddress").Element("Name").Value;
|
|
|
|
|
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("CountryCode") != null && item.Element("ShippingAddress").Element("CountryCode").Value != "")
|
|
|
|
|
model.BuyerCountry = item.Element("ShippingAddress").Element("CountryCode").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressLine1") != null && item.Element("ShippingAddress").Element("AddressLine1").Value != "")
|
|
|
|
|
model.BuyerAddr = item.Element("ShippingAddress").Element("AddressLine1").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressLine2") != null && item.Element("ShippingAddress").Element("AddressLine2").Value != "")
|
|
|
|
|
model.BuyerAddr += " " + item.Element("ShippingAddress").Element("AddressLine2").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressLine3") != null && item.Element("ShippingAddress").Element("AddressLine3").Value != "")
|
|
|
|
|
model.BuyerAddr += " " + item.Element("ShippingAddress").Element("AddressLine3").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("County") != null && item.Element("ShippingAddress").Element("County").Value != "")
|
|
|
|
|
model.BuyerAddr += " " + item.Element("ShippingAddress").Element("County").Value;
|
|
|
|
|
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("Phone") != null && item.Element("ShippingAddress").Element("Phone").Value != "")
|
|
|
|
|
model.BuyerPhone = item.Element("ShippingAddress").Element("Phone").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("StateOrRegion") != null)
|
|
|
|
|
model.BuyerProvince = item.Element("ShippingAddress").Element("StateOrRegion").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("City") != null)
|
|
|
|
|
model.BuyerCity = item.Element("ShippingAddress").Element("City").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("District") != null && item.Element("ShippingAddress").Element("District").Value != "")
|
|
|
|
|
model.BuyerArea = item.Element("ShippingAddress").Element("District").Value;
|
|
|
|
|
model.BuyerMobile = "";
|
|
|
|
|
if (item.Element("BuyerEmail") != null)
|
|
|
|
|
model.BuyerMail = item.Element("BuyerEmail").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressType") != null)
|
|
|
|
|
model.BuyerFax = item.Element("ShippingAddress").Element("AddressType").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("PostalCode") != null)
|
|
|
|
|
model.BuyerZip = item.Element("ShippingAddress").Element("PostalCode").Value;
|
|
|
|
|
|
|
|
|
|
model.OrderRemark = "";
|
|
|
|
|
model.LeaveWord = "";
|
|
|
|
|
|
|
|
|
|
if (item.Element("LastUpdateDate") != null)
|
|
|
|
|
model.PayDate = Convert.ToDateTime(item.Element("LastUpdateDate").Value.Substring(0, 18).Replace("T", " ")).AddHours(8);
|
|
|
|
|
|
|
|
|
|
if (item.Element("LatestDeliveryDate") != null)
|
|
|
|
|
model.OutOrderDate = Convert.ToDateTime(item.Element("LatestDeliveryDate").Value.Substring(0, 18).Replace("T", " ")).AddHours(8);
|
|
|
|
|
if (model.OrderDate != null && model.OrderDate.Value <= Convert.ToDateTime("1753-01-01"))
|
|
|
|
|
{
|
|
|
|
|
model.OrderDate = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
if (model.PayDate != null && model.PayDate.Value <= Convert.ToDateTime("1753-01-01"))
|
|
|
|
|
{
|
|
|
|
|
model.PayDate = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
if (model.OutOrderDate != null && model.OutOrderDate.Value <= Convert.ToDateTime("1753-01-01"))
|
|
|
|
|
{
|
|
|
|
|
model.OutOrderDate = DateTime.Now.AddDays(7);
|
|
|
|
|
}
|
|
|
|
|
model.PostInfo = item.Element("ShipServiceLevel").Value;
|
|
|
|
|
model.ListModel = new List<OrderDetailModel>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
str = "EndPoint=" + ServiceURL;
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
str += "&MWSAuthToken=" + MWSAuthToken;
|
|
|
|
|
str += "&Action=ListOrderItems";
|
|
|
|
|
str += "&AmazonOrderId=" + model.PlatOrderCode;
|
|
|
|
|
str += "&SignatureVersion=2";
|
|
|
|
|
str += "&Version=2013-09-01";
|
|
|
|
|
str += "&Command=/Orders/2013-09-01";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
string XmlContent2 = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", "", ErrorMessage);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AMResult model3 = JsonConvert.Deserialize<AMResult>(XmlContent2);
|
|
|
|
|
if (model3.HasError == true)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = model3.Message;
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", "", ErrorMessage);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
string xml2 = model3.ResultObject.Replace("xmlns=\"https://mws.amazonservices.com/Orders/2013-09-01\"", "");
|
|
|
|
|
XElement xt2 = XElement.Parse(xml2);
|
|
|
|
|
XElement xel2 = xt2.Element("ListOrderItemsResult").Element("OrderItems");
|
|
|
|
|
model.escrowFee = 0;
|
|
|
|
|
foreach (XElement item2 in xel2.Elements("OrderItem"))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
OrderDetailModel gmodel = new OrderDetailModel();
|
|
|
|
|
gmodel.productImgUrl = item2.Element("ASIN").Value;//订单编号
|
|
|
|
|
|
|
|
|
|
if (item2.Element("ItemTax") != null && item2.Element("ItemTax").Element("Amount") != null)
|
|
|
|
|
model.escrowFee += Convert.ToDecimal(item2.Element("ItemTax").Element("Amount").Value);
|
|
|
|
|
|
|
|
|
|
if (item2.Element("ShippingTax") != null && item2.Element("ShippingTax").Element("Amount") != null)
|
|
|
|
|
model.escrowFee += Convert.ToDecimal(item2.Element("ShippingTax").Element("Amount").Value);
|
|
|
|
|
|
|
|
|
|
gmodel.GoodsNum = Convert.ToInt32(item2.Element("QuantityOrdered").Value);
|
|
|
|
|
if (item2.Element("ItemPrice") != null && item2.Element("ItemPrice").Element("Amount") != null)
|
|
|
|
|
{
|
|
|
|
|
gmodel.GoodsPrice = Convert.ToDecimal(item2.Element("ItemPrice").Element("Amount").Value);
|
|
|
|
|
gmodel.MoneyCode = item2.Element("ItemPrice").Element("CurrencyCode").Value;
|
|
|
|
|
}
|
|
|
|
|
gmodel.GoodsName = item2.Element("Title").Value;
|
|
|
|
|
gmodel.GoodsSKU = item2.Element("SellerSKU").Value;
|
|
|
|
|
gmodel.PostInfo = model.PostInfo;
|
|
|
|
|
gmodel.OrderItemId = item2.Element("OrderItemId").Value;
|
|
|
|
|
model.ListModel.Add(gmodel);
|
|
|
|
|
}
|
|
|
|
|
// model.TotalPrice = model.TotalPrice - model.escrowFee;
|
|
|
|
|
ListModel.Add(model);
|
|
|
|
|
}
|
|
|
|
|
while(nexttoken!="")
|
|
|
|
|
{
|
|
|
|
|
string NextToken2 = "";
|
|
|
|
|
System.Threading.Thread.Sleep(5000);
|
|
|
|
|
var nlist = GetNext(nexttoken,olist, out NextToken2);
|
|
|
|
|
if (nlist != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var md in nlist)
|
|
|
|
|
{
|
|
|
|
|
ListModel.Add(md);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nexttoken = NextToken2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ListModel;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetOrders", ex.StackTrace, ex.Message);
|
|
|
|
|
ErrorMessage = ex.Message;
|
|
|
|
|
return ListModel;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public bool UploadAMOrder2(List<Amzon_TrackBack> list, out string error)
|
|
|
|
|
{
|
|
|
|
|
long resultId = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var now = ToUTCDatetime(DateTime.Now);
|
|
|
|
|
|
|
|
|
|
string ServiceURL = "";
|
|
|
|
|
|
|
|
|
|
#region 设置市场所在地借口地址
|
|
|
|
|
switch (country)
|
|
|
|
|
{
|
|
|
|
|
case "美国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "加拿大":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.ca";
|
|
|
|
|
break;
|
|
|
|
|
case "欧洲":
|
|
|
|
|
ServiceURL = "https://mws-eu.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "日本":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.jp";
|
|
|
|
|
break;
|
|
|
|
|
case "中国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com.cn";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
string FileContent = "";
|
|
|
|
|
|
|
|
|
|
//<?xml version="1.0" encoding="UTF-8"?><AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd"><Header><DocumentVersion>1.01</DocumentVersion><MerchantIdentifier>A3CHOODG4BN7N0</MerchantIdentifier></Header><MessageType>OrderFulfillment</MessageType><Message><MessageID>1</MessageID><OrderFulfillment><AmazonOrderID>111-6291990-2499443</AmazonOrderID><FulfillmentDate>2020-08-06T04:07:54+08:00</FulfillmentDate><FulfillmentData><CarrierCode>FedEx</CarrierCode><ShippingMethod>Standard</ShippingMethod><ShipperTrackingNumber>61290989349120195308</ShipperTrackingNumber></FulfillmentData><Item><AmazonOrderItemCode>46111329146458</AmazonOrderItemCode><Quantity>1</Quantity></Item></OrderFulfillment></Message></AmazonEnvelope>
|
|
|
|
|
var xml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
|
|
|
|
xml.Append("<AmazonEnvelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"amzn-envelope.xsd\">");
|
|
|
|
|
xml.Append("<Header>");
|
|
|
|
|
xml.Append("<DocumentVersion>1.01</DocumentVersion>");
|
|
|
|
|
xml.AppendFormat("<MerchantIdentifier>{0}</MerchantIdentifier>", SellerId);
|
|
|
|
|
xml.Append("</Header>");
|
|
|
|
|
xml.Append("<MessageType>OrderFulfillment</MessageType>");
|
|
|
|
|
int i = 1;
|
|
|
|
|
foreach (var omd in list)
|
|
|
|
|
{
|
|
|
|
|
//if (omd.OrderDate != "" && DateTime.Now.AddHours(-8) <= Convert.ToDateTime(omd.OrderDate))
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
// now = ToUTCDatetime(Convert.ToDateTime(omd.OrderDate).AddHours(3));
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
foreach (var md in omd.BackGoodsList)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
xml.Append("<Message>");
|
|
|
|
|
xml.Append("<MessageID>" + i + "</MessageID>");
|
|
|
|
|
xml.Append("<OrderFulfillment>");
|
|
|
|
|
xml.AppendFormat("<AmazonOrderID>{0}</AmazonOrderID>", omd.PlatOrderCode);
|
|
|
|
|
xml.AppendFormat("<FulfillmentDate>{0}T{1}+08:00</FulfillmentDate>", now.ToString("yyyy-MM-dd"), now.ToString("hh:mm:ss"));
|
|
|
|
|
xml.Append("<FulfillmentData>");
|
|
|
|
|
//xml.AppendFormat("<CarrierName>{0}</CarrierName>", omd.serviceName);
|
|
|
|
|
//xml.AppendFormat("<ShippingMethod>Standard</ShippingMethod>");
|
|
|
|
|
if (omd.serviceName!=null&&omd.serviceName.Contains("UPS"))
|
|
|
|
|
xml.AppendFormat("<CarrierCode>UPS</CarrierCode>");
|
|
|
|
|
else
|
|
|
|
|
xml.AppendFormat("<CarrierCode>FedEx</CarrierCode>");
|
|
|
|
|
xml.AppendFormat("<ShippingMethod>Standard</ShippingMethod>");
|
|
|
|
|
xml.AppendFormat("<ShipperTrackingNumber>{0}</ShipperTrackingNumber>", omd.TrackCode);
|
|
|
|
|
xml.Append("</FulfillmentData>");
|
|
|
|
|
xml.Append("<Item>");
|
|
|
|
|
xml.AppendFormat("<AmazonOrderItemCode>{0}</AmazonOrderItemCode>", md.GoodsDesc);
|
|
|
|
|
xml.Append("<Quantity>" + md.GoodsNum + "</Quantity>");
|
|
|
|
|
xml.Append("</Item>");
|
|
|
|
|
xml.Append("</OrderFulfillment>");
|
|
|
|
|
xml.Append("</Message>");
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
xml.Append("</AmazonEnvelope>");
|
|
|
|
|
|
|
|
|
|
FileContent = EncodeBase64("utf-8", xml.ToString());
|
|
|
|
|
string url = "http://api.sumool.com/AmazonProxy/SendRequest";
|
|
|
|
|
string str = "EndPoint=" + ServiceURL;
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
str += "&MWSAuthToken=" + MWSAuthToken;
|
|
|
|
|
str += "&Action=SubmitFeed";
|
|
|
|
|
str += "&FileContent=" + FileContent;
|
|
|
|
|
str += "&FeedType=_POST_ORDER_FULFILLMENT_DATA_";
|
|
|
|
|
str += "&Version=2009-01-01";
|
|
|
|
|
str += "&SignatureVersion=2";
|
|
|
|
|
str += "&ContentType=text/xml";
|
|
|
|
|
str += "&Command=/";
|
|
|
|
|
str += "&MarketplaceId.Id.1=" + MarketplaceId;
|
|
|
|
|
// str += "&MaxResultsPerPage=2";
|
|
|
|
|
var data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
string ErrorMessage = "";
|
|
|
|
|
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetNext", "", ErrorMessage);
|
|
|
|
|
error = ErrorMessage;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
|
|
|
AMResult model3 = JsonConvert.Deserialize<AMResult>(XmlContent);
|
|
|
|
|
if (model3.HasError == true)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
error = model3.Message;
|
|
|
|
|
ErrorFollow.TraceWrite("GetNext", "", error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error = "";
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
error = ex.Message;
|
|
|
|
|
ErrorFollow.TraceWrite(ex.TargetSite.Name, ex.StackTrace, ex.Message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<AMGoodsPM> GetGoodsPM(List<AMGoodsPM> list)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string ErrorMessage = "";
|
|
|
|
|
string ServiceURL = "";
|
|
|
|
|
|
|
|
|
|
#region 设置市场所在地借口地址
|
|
|
|
|
switch (country)
|
|
|
|
|
{
|
|
|
|
|
case "美国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "加拿大":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.ca";
|
|
|
|
|
break;
|
|
|
|
|
case "欧洲":
|
|
|
|
|
ServiceURL = "https://mws-eu.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "日本":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.jp";
|
|
|
|
|
break;
|
|
|
|
|
case "中国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com.cn";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
string url = "http://api.sumool.com/AmazonProxy/SendRequest";
|
|
|
|
|
string str = "EndPoint=" + ServiceURL;
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
str += "&MWSAuthToken=" + MWSAuthToken;
|
|
|
|
|
str += "&Action=GetCompetitivePricingForASIN";
|
|
|
|
|
str += "&SignatureVersion=2";
|
|
|
|
|
str += "&Version=2011-10-01";
|
|
|
|
|
str += "&Command=/Products/2011-10-01";
|
|
|
|
|
str += "&MarketplaceId="+MarketplaceId;
|
|
|
|
|
int i = 0;
|
|
|
|
|
foreach (var md in list)
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
str += "&ASINList.ASIN." + i.ToString() + "=" + md.ASIN;
|
|
|
|
|
}
|
|
|
|
|
// str += "&ASINList.ASIN.2=B005WKJWD4";
|
|
|
|
|
var data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
|
|
|
|
|
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetGoodsPM", "", ErrorMessage);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
|
|
|
|
|
|
|
|
AMResult model2 = JsonConvert.Deserialize<AMResult>(XmlContent);
|
|
|
|
|
if (model2.HasError == true)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = model2.Message;
|
|
|
|
|
ErrorFollow.TraceWrite("GetGoodsPM", "", ErrorMessage);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string xml2 = model2.ResultObject.Replace("xmlns=\"http://mws.amazonservices.com/schema/Products/2011-10-01\"", "");
|
|
|
|
|
XElement xt2 = XElement.Parse(xml2);
|
|
|
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
|
|
|
xmlDoc.LoadXml(xml2);
|
|
|
|
|
XmlNodeList xnlNLFir = xmlDoc.SelectSingleNode("GetCompetitivePricingForASINResponse").SelectNodes("GetCompetitivePricingForASINResult");//得到根节点
|
|
|
|
|
if (xnlNLFir != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (XmlNode xnl in xnlNLFir)//遍历devset
|
|
|
|
|
{
|
|
|
|
|
XmlNode xn = xnl.SelectSingleNode("Product").SelectSingleNode("SalesRankings");
|
|
|
|
|
XmlNode xn2 = xnl.SelectSingleNode("Product").SelectSingleNode("Identifiers").SelectSingleNode("MarketplaceASIN").SelectSingleNode("ASIN");
|
|
|
|
|
string asin = "";
|
|
|
|
|
if (xn2 != null)
|
|
|
|
|
{
|
|
|
|
|
asin = xn2.InnerText;
|
|
|
|
|
}
|
|
|
|
|
var gmd = list.Find(n => n.ASIN == asin);
|
|
|
|
|
if (xn != null && gmd!=null)
|
|
|
|
|
{
|
|
|
|
|
XmlNodeList xnlNL = xn.SelectNodes("SalesRank");//得到根节点
|
|
|
|
|
if (xnlNL != null)
|
|
|
|
|
{
|
|
|
|
|
int j = 0;
|
|
|
|
|
foreach (XmlNode xnl2 in xnlNL)//遍历devset
|
|
|
|
|
{
|
|
|
|
|
j++;
|
|
|
|
|
var rank = xnl2.SelectSingleNode("Rank").InnerText;
|
|
|
|
|
|
|
|
|
|
if (rank != null && rank.ToString() != "")
|
|
|
|
|
{
|
|
|
|
|
int rk = Convert.ToInt32(rank);
|
|
|
|
|
if (j == 1)
|
|
|
|
|
gmd.PM1 = rk;
|
|
|
|
|
else if(gmd.PM2==0||rk < gmd.PM2)
|
|
|
|
|
gmd.PM2 = rk;
|
|
|
|
|
string ProductCategoryId = xnl2.SelectSingleNode("ProductCategoryId").InnerText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ErrorFollow.TraceWrite(ex.TargetSite.Name, ex.StackTrace, ex.Message);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetGoodsReturnRequest(DateTime sdt, DateTime edt)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string ErrorMessage = "";
|
|
|
|
|
string ServiceURL = "";
|
|
|
|
|
List<AMRepotResult> rlist = new List<AMRepotResult>();
|
|
|
|
|
#region 设置市场所在地借口地址
|
|
|
|
|
switch (country)
|
|
|
|
|
{
|
|
|
|
|
case "美国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "加拿大":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.ca";
|
|
|
|
|
break;
|
|
|
|
|
case "欧洲":
|
|
|
|
|
ServiceURL = "https://mws-eu.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "日本":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.jp";
|
|
|
|
|
break;
|
|
|
|
|
case "中国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com.cn";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
string url = "http://api.sumool.com/AmazonProxy/SendRequest";
|
|
|
|
|
string str = "EndPoint=https://mws.amazonservices.com";
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
str += "&MWSAuthToken=" + MWSAuthToken;
|
|
|
|
|
// str += "&Acknowledged=false";
|
|
|
|
|
str += "&Action=RequestReport";
|
|
|
|
|
str += "&SignatureVersion=2";
|
|
|
|
|
str += "&Version=2009-01-01";
|
|
|
|
|
str += "&ReportType=_GET_XML_RETURNS_DATA_BY_RETURN_DATE_";
|
|
|
|
|
str += "&Command=/Reports/2009-01-01";
|
|
|
|
|
str += "&MarketplaceId.Id.1=ATVPDKIKX0DER";
|
|
|
|
|
str += "&StartDate=" + sdt.ToString("yyyy-MM-dd");
|
|
|
|
|
str += "&EndDate=" + edt.ToString("yyyy-MM-dd");
|
|
|
|
|
var data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
|
|
|
|
|
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetGoodsReturnRequest", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
|
|
|
|
|
|
|
|
AMResult model2 = JsonConvert.Deserialize<AMResult>(XmlContent);
|
|
|
|
|
if (model2.HasError == true)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = model2.Message;
|
|
|
|
|
ErrorFollow.TraceWrite("GetGoodsReturnRequest", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string xml2 = model2.ResultObject.Replace("xmlns=\"http://mws.amazonaws.com/doc/2009-01-01/\"", "");
|
|
|
|
|
XElement xt2 = XElement.Parse(xml2);
|
|
|
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
|
|
|
xmlDoc.LoadXml(xml2);
|
|
|
|
|
XmlNode xnlNLFir = xmlDoc.SelectSingleNode("RequestReportResponse").SelectSingleNode("RequestReportResult").SelectSingleNode("ReportRequestInfo");//得到根节点
|
|
|
|
|
string ReportId = "";
|
|
|
|
|
if (xnlNLFir != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ReportId = xnlNLFir.SelectSingleNode("ReportRequestId").InnerText;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ReportId;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ErrorFollow.TraceWrite(ex.TargetSite.Name, ex.StackTrace, ex.Message);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<AMRepotResult> GetGoodsReturn(DateTime sdt,DateTime edt,string requestid)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string ErrorMessage = "";
|
|
|
|
|
string ServiceURL = "";
|
|
|
|
|
List<AMRepotResult> rlist = new List<AMRepotResult>();
|
|
|
|
|
#region 设置市场所在地借口地址
|
|
|
|
|
switch (country)
|
|
|
|
|
{
|
|
|
|
|
case "美国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "加拿大":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.ca";
|
|
|
|
|
break;
|
|
|
|
|
case "欧洲":
|
|
|
|
|
ServiceURL = "https://mws-eu.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "日本":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.jp";
|
|
|
|
|
break;
|
|
|
|
|
case "中国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com.cn";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
string url = "http://api.sumool.com/AmazonProxy/SendRequest";
|
|
|
|
|
string str = "EndPoint=https://mws.amazonservices.com";
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
str += "&MWSAuthToken=" + MWSAuthToken;
|
|
|
|
|
// str += "&Acknowledged=false";
|
|
|
|
|
str += "&Action=GetReportList";
|
|
|
|
|
str += "&ReportRequestIdList.Id.1="+ requestid;
|
|
|
|
|
str += "&SignatureVersion=2";
|
|
|
|
|
str += "&Version=2009-01-01";
|
|
|
|
|
str += "&ReportTypeList.Type.1=_GET_XML_RETURNS_DATA_BY_RETURN_DATE_";
|
|
|
|
|
str += "&Command=/Reports/2009-01-01";
|
|
|
|
|
str += "&MarketplaceId.Id.1=ATVPDKIKX0DER";
|
|
|
|
|
// str += "&AvailableFromDate="+sdt.ToString("yyyy-MM-dd");
|
|
|
|
|
// str += "&AvailableToDate=" + edt.ToString("yyyy-MM-dd");
|
|
|
|
|
var data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
|
|
|
|
|
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetGoodsReturn", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
|
|
|
|
|
|
|
|
AMResult model2 = JsonConvert.Deserialize<AMResult>(XmlContent);
|
|
|
|
|
if (model2.HasError == true)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = model2.Message;
|
|
|
|
|
ErrorFollow.TraceWrite("GetGoodsReturn", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string xml2 = model2.ResultObject.Replace("xmlns=\"http://mws.amazonaws.com/doc/2009-01-01/\"", "");
|
|
|
|
|
XElement xt2 = XElement.Parse(xml2);
|
|
|
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
|
|
|
xmlDoc.LoadXml(xml2);
|
|
|
|
|
XmlNode xnlNLFir = xmlDoc.SelectSingleNode("GetReportListResponse").SelectSingleNode("GetReportListResult");//得到根节点
|
|
|
|
|
if (xnlNLFir != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
XmlNodeList xnlNL = xnlNLFir.SelectNodes("ReportInfo");//得到根节点
|
|
|
|
|
if (xnlNL != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (XmlNode xnl2 in xnlNL)//遍历devset
|
|
|
|
|
{
|
|
|
|
|
AMRepotResult rmd = new AMRepotResult();
|
|
|
|
|
|
|
|
|
|
string ReportId = xnl2.SelectSingleNode("ReportId").InnerText;
|
|
|
|
|
rmd.ReportId = ReportId;
|
|
|
|
|
rlist.Add(rmd);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rlist;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ErrorFollow.TraceWrite(ex.TargetSite.Name, ex.StackTrace, ex.Message);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<AMRepotOrders> GetGoodsReturnOrders(string reportid)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string ErrorMessage = "";
|
|
|
|
|
string ServiceURL = "";
|
|
|
|
|
List<AMRepotOrders> rlist = new List<AMRepotOrders>();
|
|
|
|
|
#region 设置市场所在地借口地址
|
|
|
|
|
switch (country)
|
|
|
|
|
{
|
|
|
|
|
case "美国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "加拿大":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.ca";
|
|
|
|
|
break;
|
|
|
|
|
case "欧洲":
|
|
|
|
|
ServiceURL = "https://mws-eu.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "日本":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.jp";
|
|
|
|
|
break;
|
|
|
|
|
case "中国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com.cn";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
string url = "http://api.sumool.com/AmazonProxy/SendRequest";
|
|
|
|
|
string str = "EndPoint=https://mws.amazonservices.com";
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
str += "&MWSAuthToken=" + MWSAuthToken;
|
|
|
|
|
str += "&Action=GetReport";
|
|
|
|
|
str += "&ReportId="+ reportid;
|
|
|
|
|
str += "&SignatureVersion=2";
|
|
|
|
|
str += "&Version=2009-01-01";
|
|
|
|
|
str += "&Command=/Reports/2009-01-01";
|
|
|
|
|
str += "&MarketplaceId.Id.1=ATVPDKIKX0DER";
|
|
|
|
|
|
|
|
|
|
var data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
|
|
|
|
|
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetGoodsReturn", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
|
|
|
|
|
|
|
|
AMResult model2 = JsonConvert.Deserialize<AMResult>(XmlContent);
|
|
|
|
|
if (model2.HasError == true)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = model2.Message;
|
|
|
|
|
ErrorFollow.TraceWrite("GetGoodsReturn", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string xml2 = model2.ResultObject.Replace("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"amzn-envelope.xsd\"", "");
|
|
|
|
|
XElement xt2 = XElement.Parse(xml2);
|
|
|
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
|
|
|
xmlDoc.LoadXml(xml2);
|
|
|
|
|
XmlNodeList xnlNLFir = xmlDoc.SelectSingleNode("AmazonEnvelope").SelectSingleNode("Message").SelectNodes("return_details");//得到根节点
|
|
|
|
|
if (xnlNLFir != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (XmlNode xnl in xnlNLFir)//遍历devset
|
|
|
|
|
{
|
|
|
|
|
AMRepotOrders rmd = new AMRepotOrders();
|
|
|
|
|
string orderid = xnl.SelectSingleNode("order_id").InnerText;
|
|
|
|
|
if (orderid == "113-2488895-8691467" || orderid == "113-0306824-0995429")
|
|
|
|
|
{
|
|
|
|
|
string a = "";
|
|
|
|
|
}
|
|
|
|
|
string order_date = xnl.SelectSingleNode("order_date").InnerText;
|
|
|
|
|
string return_request_status = xnl.SelectSingleNode("return_request_status").InnerText;
|
|
|
|
|
string return_request_date = xnl.SelectSingleNode("return_request_date").InnerText;
|
|
|
|
|
rmd.order_id = orderid;
|
|
|
|
|
rmd.return_request_status = return_request_status;
|
|
|
|
|
rmd.order_date = order_date;
|
|
|
|
|
rmd.return_request_date = return_request_date;
|
|
|
|
|
|
|
|
|
|
if (xnl != null)
|
|
|
|
|
{
|
|
|
|
|
XmlNodeList xnlNL = xnl.SelectNodes("item_details");//得到根节点
|
|
|
|
|
List<AMRepotOrdersDetail> AMRepotOrdersDetail = new List<AMRepotOrdersDetail>();
|
|
|
|
|
rmd.return_details = AMRepotOrdersDetail;
|
|
|
|
|
if (xnlNL != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (XmlNode xnl2 in xnlNL)//遍历devset
|
|
|
|
|
{
|
|
|
|
|
if (xnl2.SelectSingleNode("asin") != null)
|
|
|
|
|
{
|
|
|
|
|
string asin = xnl2.SelectSingleNode("asin").InnerText;
|
|
|
|
|
string return_reason_code = xnl2.SelectSingleNode("return_reason_code").InnerText;
|
|
|
|
|
string merchant_sku = xnl2.SelectSingleNode("merchant_sku").InnerText;
|
|
|
|
|
string in_policy = xnl2.SelectSingleNode("in_policy").InnerText;
|
|
|
|
|
int return_quantity = 1;
|
|
|
|
|
if (xnl2.SelectSingleNode("return_quantity") != null && xnl2.SelectSingleNode("return_quantity").InnerText != "")
|
|
|
|
|
return_quantity = Convert.ToInt32(xnl2.SelectSingleNode("return_quantity").InnerText);
|
|
|
|
|
decimal refund_amount = 0;
|
|
|
|
|
if (xnl2.SelectSingleNode("refund_amount") != null && xnl2.SelectSingleNode("refund_amount").InnerText != "")
|
|
|
|
|
refund_amount = Convert.ToDecimal(xnl2.SelectSingleNode("refund_amount").InnerText);
|
|
|
|
|
AMRepotOrdersDetail dmd = new AMRepotOrdersDetail();
|
|
|
|
|
dmd.asin = asin;
|
|
|
|
|
dmd.return_reason_code = return_reason_code;
|
|
|
|
|
dmd.merchant_sku = merchant_sku;
|
|
|
|
|
dmd.return_quantity = return_quantity;
|
|
|
|
|
dmd.refund_amount = refund_amount;
|
|
|
|
|
dmd.in_policy = in_policy;
|
|
|
|
|
AMRepotOrdersDetail.Add(dmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<AMRepotLabelsDetail> AMRepotLabelsDetail = new List<AMRepotLabelsDetail>();
|
|
|
|
|
rmd.label_details = AMRepotLabelsDetail;
|
|
|
|
|
XmlNodeList xnlNL2 = xnl.SelectNodes("label_details");//得到根节点
|
|
|
|
|
if (xnlNL2 != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (XmlNode xnl2 in xnlNL2)//遍历devset
|
|
|
|
|
{
|
|
|
|
|
if (xnl2.SelectSingleNode("tracking_id") != null)
|
|
|
|
|
{
|
|
|
|
|
string tracking_id = xnl2.SelectSingleNode("tracking_id").InnerText;
|
|
|
|
|
string return_carrier = xnl2.SelectSingleNode("return_carrier").InnerText;
|
|
|
|
|
|
|
|
|
|
decimal label_cost = 0;
|
|
|
|
|
if (xnl2.SelectSingleNode("label_cost") != null && xnl2.SelectSingleNode("label_cost").InnerText != "")
|
|
|
|
|
label_cost = Convert.ToDecimal(xnl2.SelectSingleNode("label_cost").InnerText);
|
|
|
|
|
AMRepotLabelsDetail lmd = new AMRepotLabelsDetail();
|
|
|
|
|
lmd.tracking_id = tracking_id;
|
|
|
|
|
lmd.return_carrier = return_carrier;
|
|
|
|
|
lmd.label_cost = label_cost;
|
|
|
|
|
AMRepotLabelsDetail.Add(lmd);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string tracking_id = "";
|
|
|
|
|
string return_carrier = "";
|
|
|
|
|
|
|
|
|
|
decimal label_cost = 0;
|
|
|
|
|
if (xnl2.SelectSingleNode("label_cost") != null && xnl2.SelectSingleNode("label_cost").InnerText != "")
|
|
|
|
|
label_cost = Convert.ToDecimal(xnl2.SelectSingleNode("label_cost").InnerText);
|
|
|
|
|
AMRepotLabelsDetail lmd = new AMRepotLabelsDetail();
|
|
|
|
|
lmd.tracking_id = tracking_id;
|
|
|
|
|
lmd.return_carrier = return_carrier;
|
|
|
|
|
lmd.label_cost = label_cost;
|
|
|
|
|
AMRepotLabelsDetail.Add(lmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rlist.Add(rmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rlist;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ErrorFollow.TraceWrite(ex.TargetSite.Name, ex.StackTrace, ex.Message);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
///编码
|
|
|
|
|
public static string EncodeBase64(string code_type, string code)
|
|
|
|
|
{
|
|
|
|
|
string encode = "";
|
|
|
|
|
byte[] bytes = Encoding.GetEncoding(code_type).GetBytes(code);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
encode = Convert.ToBase64String(bytes);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
encode = code;
|
|
|
|
|
}
|
|
|
|
|
return encode;
|
|
|
|
|
}
|
|
|
|
|
public DateTime ToUTCDatetime(DateTime datetime)
|
|
|
|
|
{
|
|
|
|
|
if (country == "美国" || country == "加拿大")
|
|
|
|
|
{
|
|
|
|
|
var d = datetime.AddHours(-12).ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
return DateTime.Parse(d);
|
|
|
|
|
}
|
|
|
|
|
else if (country == "欧洲")
|
|
|
|
|
{
|
|
|
|
|
var d = datetime.AddHours(-7).ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
return DateTime.Parse(d);
|
|
|
|
|
}
|
|
|
|
|
else if (country == "日本")
|
|
|
|
|
{
|
|
|
|
|
var d = datetime.AddHours(1).ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
return DateTime.Parse(d);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var d = datetime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
return DateTime.Parse(d);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<OrderModel> GetNext(string NextToken, List<Alibaba_OrderCode> olist,out string NextToken2)
|
|
|
|
|
{
|
|
|
|
|
if (olist == null)
|
|
|
|
|
olist = new List<Alibaba_OrderCode>();
|
|
|
|
|
List<OrderModel> ListModel = new List<OrderModel>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
NextToken2 = "";
|
|
|
|
|
string ServiceURL = "";
|
|
|
|
|
|
|
|
|
|
#region 设置市场所在地借口地址
|
|
|
|
|
switch (country)
|
|
|
|
|
{
|
|
|
|
|
case "美国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "加拿大":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.ca";
|
|
|
|
|
break;
|
|
|
|
|
case "欧洲":
|
|
|
|
|
ServiceURL = "https://mws-eu.amazonservices.com";
|
|
|
|
|
break;
|
|
|
|
|
case "日本":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.jp";
|
|
|
|
|
break;
|
|
|
|
|
case "中国":
|
|
|
|
|
ServiceURL = "https://mws.amazonservices.com.cn";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
string url = "http://api.sumool.com/AmazonProxy/SendRequest";
|
|
|
|
|
string str = "EndPoint=" + ServiceURL;
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
str += "&MWSAuthToken=" + MWSAuthToken;
|
|
|
|
|
str += "&Action=ListOrdersByNextToken";
|
|
|
|
|
str += "&SignatureVersion=2";
|
|
|
|
|
str += "&Version=2013-09-01";
|
|
|
|
|
str += "&NextToken=" + System.Web.HttpUtility.UrlEncode(NextToken, System.Text.Encoding.UTF8); //NextToken;//cuuXb/5rE5V/YYuZQbKv1QafEPREmauvizt1MIhPYZY5UeE2vqL5+q+3EeDVAX1m9bYwTOaLr1BRBUDTTfkLYd8ytOVgN7d/KyNtf5fepe1HnywimSSQDWsHD6/bUUR52L5dUFExSTmS68vI7Bqws+weLxD7b1CVfTtGOfGNtrwDY5vNcs9fDyeyat9X9kfV90Pt/dS9dfNe0zIeaOVNezxWEXvdeDL7jK/e/+Wa0s1twNzrtVnOxu6eFQOZqwUbuQlY5nzacE8wE7+t4NjazyEZY027dXAVTSGshRBy6ZQghiSCZ3PIKk1DNEBSp27+Ut7nFOOx+zdaHp4fabNqjZ2tUVsJ4RQh/IBQt3FQQzLmwHDeTLwt77nugIB18KqAgbNnl5xOfnEVIjQAQxp+3J+cRqVnyn3b4SR+oXPlG2k8wbiM2qCGeUNkGZHrEmwSvkpEs3nBE8XVgbG4EqTn56vqewKupVm5Cz/L15hZDT5OeKmHpMzOQw==";
|
|
|
|
|
str += "&Command=/Orders/2013-09-01";
|
|
|
|
|
str += "&MarketplaceId.Id.1="+MarketplaceId;
|
|
|
|
|
// str += "&MaxResultsPerPage=2";
|
|
|
|
|
var data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
string ErrorMessage = "";
|
|
|
|
|
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetNext", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
|
|
|
|
|
|
|
|
AMResult model2 = JsonConvert.Deserialize<AMResult>(XmlContent);
|
|
|
|
|
if (model2.HasError == true)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = model2.Message;
|
|
|
|
|
ErrorFollow.TraceWrite("GetNext", "", ErrorMessage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
string xml = model2.ResultObject.Replace("xmlns=\"https://mws.amazonservices.com/Orders/2013-09-01\"", "");
|
|
|
|
|
XElement xt = XElement.Parse(xml);
|
|
|
|
|
XElement xel = xt.Element("ListOrdersByNextTokenResult").Element("Orders"); // <ListOrdersResult>\n <Orders>\n
|
|
|
|
|
|
|
|
|
|
string nexttoken = "";
|
|
|
|
|
if (xt.Element("ListOrdersByNextTokenResult") != null && xt.Element("ListOrdersByNextTokenResult").Element("NextToken") != null && xt.Element("ListOrdersByNextTokenResult").Element("NextToken").Value != "")
|
|
|
|
|
nexttoken = xt.Element("ListOrdersByNextTokenResult").Element("NextToken").Value;
|
|
|
|
|
// GetNext(nexttoken);
|
|
|
|
|
|
|
|
|
|
foreach (XElement item in xel.Elements("Order"))
|
|
|
|
|
{
|
|
|
|
|
System.Threading.Thread.Sleep(1000);
|
|
|
|
|
if (item.Element("OrderStatus")!=null&&item.Element("OrderStatus").Value == "Canceled")
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (item.Element("OrderTotal") == null || item.Element("OrderTotal").Element("Amount") == null || item.Element("OrderTotal").Element("Amount").Value == "")
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
OrderModel model = new OrderModel();
|
|
|
|
|
model.OrderCode = item.Element("AmazonOrderId").Value;//订单编号
|
|
|
|
|
if (model.OrderCode == "113-1276800-3025014")
|
|
|
|
|
{
|
|
|
|
|
string a = "";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
model.PlatOrderCode = item.Element("AmazonOrderId").Value;//OrderLineItemID
|
|
|
|
|
model.PlatOrderCode = item.Element("AmazonOrderId").Value;//OrderLineItemID
|
|
|
|
|
if (model.PlatOrderCode == null || model.PlatOrderCode == "")
|
|
|
|
|
continue;
|
|
|
|
|
if (olist != null)
|
|
|
|
|
{
|
|
|
|
|
var amd = olist.Find(n => n.OrderCode == model.PlatOrderCode);
|
|
|
|
|
if (amd != null)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model.TotalPrice = Convert.ToDecimal(item.Element("OrderTotal").Element("Amount").Value);
|
|
|
|
|
model.MoneyCode = "USD";//币种
|
|
|
|
|
|
|
|
|
|
if (item.Element("PurchaseDate") != null)
|
|
|
|
|
model.OrderDate = Convert.ToDateTime(item.Element("PurchaseDate").Value.Substring(0, 18).Replace("T", " ")).AddHours(8);
|
|
|
|
|
if (item.Element("FulfillmentChannel") != null)
|
|
|
|
|
model.BuyerID = item.Element("FulfillmentChannel").Value;
|
|
|
|
|
else
|
|
|
|
|
model.BuyerID = "MFN";
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("Name") != null)
|
|
|
|
|
model.BuyerName = item.Element("ShippingAddress").Element("Name").Value;
|
|
|
|
|
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("CountryCode") != null && item.Element("ShippingAddress").Element("CountryCode").Value != "")
|
|
|
|
|
model.BuyerCountry = item.Element("ShippingAddress").Element("CountryCode").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressLine1") != null && item.Element("ShippingAddress").Element("AddressLine1").Value != "")
|
|
|
|
|
model.BuyerAddr = item.Element("ShippingAddress").Element("AddressLine1").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressLine2") != null && item.Element("ShippingAddress").Element("AddressLine2").Value != "")
|
|
|
|
|
model.BuyerAddr += " " + item.Element("ShippingAddress").Element("AddressLine2").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressLine3") != null && item.Element("ShippingAddress").Element("AddressLine3").Value != "")
|
|
|
|
|
model.BuyerAddr += " " + item.Element("ShippingAddress").Element("AddressLine3").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("County") != null && item.Element("ShippingAddress").Element("County").Value != "")
|
|
|
|
|
model.BuyerAddr += " " + item.Element("ShippingAddress").Element("County").Value;
|
|
|
|
|
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("Phone") != null && item.Element("ShippingAddress").Element("Phone").Value != "")
|
|
|
|
|
model.BuyerPhone = item.Element("ShippingAddress").Element("Phone").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("StateOrRegion") != null)
|
|
|
|
|
model.BuyerProvince = item.Element("ShippingAddress").Element("StateOrRegion").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("City") != null)
|
|
|
|
|
model.BuyerCity = item.Element("ShippingAddress").Element("City").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("District") != null && item.Element("ShippingAddress").Element("District").Value != "")
|
|
|
|
|
model.BuyerArea = item.Element("ShippingAddress").Element("District").Value;
|
|
|
|
|
model.BuyerMobile = "";
|
|
|
|
|
if (item.Element("BuyerEmail") != null)
|
|
|
|
|
model.BuyerMail = item.Element("BuyerEmail").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("AddressType") != null)
|
|
|
|
|
model.BuyerFax = item.Element("ShippingAddress").Element("AddressType").Value;
|
|
|
|
|
if (item.Element("ShippingAddress") != null && item.Element("ShippingAddress").Element("PostalCode") != null)
|
|
|
|
|
model.BuyerZip = item.Element("ShippingAddress").Element("PostalCode").Value;
|
|
|
|
|
|
|
|
|
|
model.OrderRemark = "";
|
|
|
|
|
model.LeaveWord = "";
|
|
|
|
|
|
|
|
|
|
if (item.Element("LastUpdateDate") != null)
|
|
|
|
|
model.PayDate = Convert.ToDateTime(item.Element("LastUpdateDate").Value.Substring(0, 18).Replace("T", " ")).AddHours(8);
|
|
|
|
|
|
|
|
|
|
if (item.Element("LatestDeliveryDate") != null)
|
|
|
|
|
model.OutOrderDate = Convert.ToDateTime(item.Element("LatestDeliveryDate").Value.Substring(0, 18).Replace("T", " ")).AddHours(8);
|
|
|
|
|
if (model.OrderDate != null && model.OrderDate.Value <= Convert.ToDateTime("1753-01-01"))
|
|
|
|
|
{
|
|
|
|
|
model.OrderDate = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
if (model.PayDate != null && model.PayDate.Value <= Convert.ToDateTime("1753-01-01"))
|
|
|
|
|
{
|
|
|
|
|
model.PayDate = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
if (model.OutOrderDate != null && model.OutOrderDate.Value <= Convert.ToDateTime("1753-01-01"))
|
|
|
|
|
{
|
|
|
|
|
model.OutOrderDate = DateTime.Now.AddDays(7);
|
|
|
|
|
}
|
|
|
|
|
model.PostInfo = item.Element("ShipServiceLevel").Value;
|
|
|
|
|
model.ListModel = new List<OrderDetailModel>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
str = "EndPoint=" + ServiceURL;
|
|
|
|
|
str += "&SumoolToKen=" + SumoolToKen;
|
|
|
|
|
str += "&SellerId=" + SellerId;
|
|
|
|
|
str += "&MWSAuthToken=" + MWSAuthToken;
|
|
|
|
|
str += "&Action=ListOrderItems";
|
|
|
|
|
str += "&AmazonOrderId=" + model.PlatOrderCode;
|
|
|
|
|
str += "&SignatureVersion=2";
|
|
|
|
|
str += "&Version=2013-09-01";
|
|
|
|
|
str += "&Command=/Orders/2013-09-01";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = Encoding.UTF8.GetBytes(str);
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
string XmlContent2 = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
|
|
|
|
|
if (ErrorMessage != "")
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetNext", "", ErrorMessage);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AMResult model3 = JsonConvert.Deserialize<AMResult>(XmlContent2);
|
|
|
|
|
if (model3.HasError == true)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = model3.Message;
|
|
|
|
|
ErrorFollow.TraceWrite("GetNext", "", ErrorMessage);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
string xml2 = model3.ResultObject.Replace("xmlns=\"https://mws.amazonservices.com/Orders/2013-09-01\"", "");
|
|
|
|
|
XElement xt2 = XElement.Parse(xml2);
|
|
|
|
|
XElement xel2 = xt2.Element("ListOrderItemsResult").Element("OrderItems");
|
|
|
|
|
model.escrowFee = 0;
|
|
|
|
|
foreach (XElement item2 in xel2.Elements("OrderItem"))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
OrderDetailModel gmodel = new OrderDetailModel();
|
|
|
|
|
gmodel.productImgUrl = item2.Element("ASIN").Value;//订单编号
|
|
|
|
|
if (item2.Element("ItemTax") != null && item2.Element("ItemTax").Element("Amount") != null)
|
|
|
|
|
model.escrowFee += Convert.ToDecimal(item2.Element("ItemTax").Element("Amount").Value);
|
|
|
|
|
|
|
|
|
|
if (item2.Element("ShippingTax") != null && item2.Element("ShippingTax").Element("Amount") != null)
|
|
|
|
|
model.escrowFee += Convert.ToDecimal(item2.Element("ShippingTax").Element("Amount").Value);
|
|
|
|
|
|
|
|
|
|
gmodel.GoodsNum = Convert.ToInt32(item2.Element("QuantityOrdered").Value);
|
|
|
|
|
if (item2.Element("ItemPrice") != null && item2.Element("ItemPrice").Element("Amount") != null)
|
|
|
|
|
{
|
|
|
|
|
gmodel.GoodsPrice = Convert.ToDecimal(item2.Element("ItemPrice").Element("Amount").Value);
|
|
|
|
|
gmodel.MoneyCode = item2.Element("ItemPrice").Element("CurrencyCode").Value;
|
|
|
|
|
}
|
|
|
|
|
gmodel.GoodsName = item2.Element("Title").Value;
|
|
|
|
|
gmodel.GoodsSKU = item2.Element("SellerSKU").Value;
|
|
|
|
|
gmodel.PostInfo = model.PostInfo;
|
|
|
|
|
gmodel.OrderItemId = item2.Element("OrderItemId").Value;
|
|
|
|
|
model.ListModel.Add(gmodel);
|
|
|
|
|
}
|
|
|
|
|
// model.TotalPrice = model.TotalPrice - model.escrowFee;
|
|
|
|
|
ListModel.Add(model);
|
|
|
|
|
}
|
|
|
|
|
if (nexttoken != null && nexttoken != "")
|
|
|
|
|
{
|
|
|
|
|
NextToken2 = nexttoken;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return ListModel;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("GetNext", ex.StackTrace, ex.Message);
|
|
|
|
|
NextToken2 = "";
|
|
|
|
|
return ListModel;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class AMRepotResult
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string ReportId { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public class AMRepotOrders
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string order_id { get; set; }
|
|
|
|
|
public string order_date { get; set; }
|
|
|
|
|
public string return_request_date { get; set; }
|
|
|
|
|
public string return_request_status { get; set; }
|
|
|
|
|
public List<AMRepotOrdersDetail> return_details { get; set; }
|
|
|
|
|
public List<AMRepotLabelsDetail> label_details { get; set; }
|
|
|
|
|
}
|
|
|
|
|
public class AMRepotOrdersDetail
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string item_name { get; set; }
|
|
|
|
|
public string asin { get; set; }
|
|
|
|
|
public string return_reason_code { get; set; }
|
|
|
|
|
public string merchant_sku { get; set; }
|
|
|
|
|
public Int32? return_quantity { get; set; }
|
|
|
|
|
public string resolution { get; set; }
|
|
|
|
|
public decimal? refund_amount { get; set; }
|
|
|
|
|
public string in_policy { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AMRepotLabelsDetail
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string tracking_id { get; set; }
|
|
|
|
|
public string return_carrier { get; set; }
|
|
|
|
|
public decimal? label_cost { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public class AMResult
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public Boolean? HasError { get; set; }
|
|
|
|
|
public string Message { get; set; }
|
|
|
|
|
|
|
|
|
|
public string ResultObject { get; set; }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AMOrder
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public string OrderStatus { get; set; }
|
|
|
|
|
public string AmazonOrderId { get; set; }
|
|
|
|
|
|
|
|
|
|
public string PurchaseDate { get; set; }
|
|
|
|
|
|
|
|
|
|
public AMAddr ShippingAddress { get; set; }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AMAddr
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public string AddressLine1 { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class AMGoodsPM
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public Int32? ShopId { get; set; }
|
|
|
|
|
public Int32? GoodsId { get; set; }
|
|
|
|
|
public string ASIN { get; set; }
|
|
|
|
|
public Int32? id { get; set; }
|
|
|
|
|
public int PM1 { get; set; }
|
|
|
|
|
public int PM2 { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|