Amzon MWS API开发之订单接口
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Amzon MWS API开发之订单接口相关的知识,希望对你有一定的参考价值。
Amazon订单接口是Amazon MWS 开发接口中的一大块,我们可以通过接口调用来获得订单数据。
在调用接口之前,首先我们要获得相关店铺商家的店铺密钥等信息。如下:
在此我将所有信息定义在一个类中,采用序列化的方式,方便存取值。
/// <summary> /// 账户信息 /// </summary> [Serializable] public class AccountConfig : BaseConfig<AccountConfig> { /// <summary> /// 应用程序名称 /// </summary> public string AppName { get; set; } /// <summary> /// 应用程序版本 /// </summary> public string AppVersion { get; set; } /// <summary> /// 账户KeyId /// </summary> public string AccessKeyId { get; set; } /// <summary> /// 密钥Id /// </summary> public string SecretAccessKey { get; set; } /// <summary> /// 商城Id /// </summary> public string MerchantId { get; set; } /// <summary> /// 商城唯一标识Id /// </summary> public string MarketplaceId { get; set; } /// <summary> /// 服务端URL /// </summary> public string ServiceUrl { get; set; } }
然后我们回到文档中,我们会发现,请求参数中,有两个参数是必填的:CreatedAfter、MarketplaceId。调用接口的方法很简单,无非是构造完整的对象,其实主要还是保持必填参数的完整性,这次我们拿ListOrder 接口来举例:
/// <summary> /// 获得账户信息 /// </summary> protected AccountConfig Account { get { return AccountConfig.Instance; } } private MarketplaceWebServiceOrdersConfig GetConfig() { var config = new MarketplaceWebServiceOrdersConfig(); config.ServiceURL = Account.ServiceUrl; return config; } private MarketplaceWebServiceOrdersClient GetClient() { var config = this.GetConfig(); var client = new MarketplaceWebServiceOrdersClient(Account.AppName, Account.AppVersion, Account.AccessKeyId, Account.SecretAccessKey, config); return client; } #region 获得订单列表(OrderList) private List<Order> GetNextOrderList(ref string nextToken) { var client = this.GetClient(); var request = new ListOrdersByNextTokenRequest(); request.SellerId = Account.MerchantId; request.NextToken = nextToken; var response = client.ListOrdersByNextToken(request); var result = response.ListOrdersByNextTokenResult; nextToken = result.NextToken; List<Order> orderList = result.Orders.Order; return orderList; } /// <summary> /// 获得订单列表(指定Request模式) /// </summary> /// <param name="request">ListOrdersRequest</param> /// <returns></returns> public List<Order> GetOrderList(DateTime createdAfter, DateTime createdBefore) { var request = new ListOrdersRequest(); request.CreatedAfter = AmazonHelper.ConvertToISO8601(createdAfter); request.CreatedBefore = AmazonHelper.ConvertToISO8601(createdBefore); request.MarketplaceId = new MarketplaceIdList(); request.MarketplaceId.Id = new List<string> { Account.MarketplaceId }; request.SellerId = Account.MerchantId; var client = GetClient(); var response = client.ListOrders(request); var result = response.ListOrdersResult; var orderList = result.Orders.Order; string nextToken = result.NextToken; while (!string.IsNullOrEmpty(nextToken)) { List<Order> tempList = GetNextOrderList(ref nextToken); orderList = orderList.Concat(tempList).ToList(); } return orderList; } #endregion
切记,在调用中不要忽视了在请求参数中给 SellerId 赋值。
以上是关于Amzon MWS API开发之订单接口的主要内容,如果未能解决你的问题,请参考以下文章