<p>亚马逊接口测试地址:</p>
<p><a href="https://mws.amazonservices.com/scratchpad/index.html">https://mws.amazonservices.com/scratchpad/index.html</a></p>
<p>开始 test </p>
<p><strong>AmazonApplicationTests</strong></p>
<pre class="blockcode"><code class="language-java">package com.example.amazon.amazon;
import com.example.amazon.amazon.untils.AmazonConstant;
import com.example.amazon.amazon.untils.AmazonUntil;
import com.example.amazon.amazon.untils.GetReportListUntil;
import com.example.amazon.amazon.untils.GetReportList;
import net.sf.json.JSONArray;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.math.BigDecimal;
import java.util.HashMap;
@SpringBootApplication
@RunWith(SpringRunner.class)
@SpringBootTest
public class AmazonApplicationTests implements AmazonConstant {
/**
*
*AmazonUntil
*Reports
*/
@Test
public void Reports() {
//***亚马逊提供密钥***
String secretKey = "r1LaemH2Jx2x******************k2";
HashMap<String, String> parameters = new HashMap<>();
//***亚马逊提供访问id***
parameters.put("AWSAccessKeyId", AmazonUntil.urlEncode("AK*******KA"));
//***商家提供授权token***
parameters.put("MWSAuthToken", AmazonUntil.urlEncode("amzn.mws.96**********b6"));
//***商家提供卖家id***
parameters.put("SellerId", AmazonUntil.urlEncode("A1T**************IJGDS"));
//***Request URL: http://docs.developer.amazonservices.com/zh_CN/dev_guide/DG_Endpoints.html***
parameters.put("ReportType", "_GET_FBA_FULFILLMENT_CURRENT_INVENTORY_DATA_");
parameters.put("MarketplaceId.Id.1", "ATVPDKIKX0DER");
try {
String orders = AmazonUntil.doPost( parameters, secretKey);
GetReportList(orders);
} catch (Exception e) {
;
}
//todo 解析orders数组就是每一条订单的数据
}
/**
*
*GetReportListUntil
*GetReportRequestList
*/
public void GetReportList(String ReportRequestId) {
//***亚马逊提供密钥***
String secretKey = "r1LaemH2Jx2xGStbTqadn1mVJwzYFLyBMKZQLKk2";
HashMap<String, String> parameters = new HashMap<>();
//***亚马逊提供访问id***
parameters.put("AWSAccessKeyId", AmazonUntil.urlEncode("AKIAJEBONJNSXN5L5WKA"));
//***商家提供授权token***
parameters.put("MWSAuthToken", AmazonUntil.urlEncode("amzn.mws.96b29db4-0820-7d35-139c-ad9f3ea196b6"));
//***商家提供卖家id***
parameters.put("SellerId", AmazonUntil.urlEncode("A1TUEZAEMIJGDS"));
//***Request URL: http://docs.developer.amazonservices.com/zh_CN/dev_guide/DG_Endpoints.html***
//n为毫秒数
try { Thread.sleep ( 10000 ) ;
} catch (InterruptedException ie){}
parameters.put("ReportRequestIdList.Id.1", ReportRequestId);
String orders = "";
try {
orders = GetReportListUntil.doPost( parameters, secretKey);
System.out.println("?????"+orders);
GetReport(orders);
} catch (Exception e) {
;
}
//todo 解析orders数组就是每一条订单的数据
}
/**
*
*GetReportListUntil
*GetReportList
* public void GetReport(String GetReport) {
*/
// @Test
public void GetReport(String GetReport) {
//***亚马逊提供密钥***
String secretKey = "r1LaemH2Jx2xGStbTqadn1mVJwzYFLyBMKZQLKk2";
HashMap<String, String> parameters = new HashMap<>();
//***亚马逊提供访问id***
parameters.put("AWSAccessKeyId", AmazonUntil.urlEncode("AKIAJEBONJNSXN5L5WKA"));
//***商家提供授权token***
parameters.put("MWSAuthToken", AmazonUntil.urlEncode("amzn.mws.96b29db4-0820-7d35-139c-ad9f3ea196b6"));
//***商家提供卖家id***
parameters.put("SellerId", AmazonUntil.urlEncode("A1TUEZAEMIJGDS"));
//***Request URL: http://docs.developer.amazonservices.com/zh_CN/dev_guide/DG_Endpoints.html***
parameters.put("ReportId", GetReport);
String orders = "";
try {
orders = GetReportList.doPost( parameters, secretKey);
} catch (Exception e) {
;
}
//todo 解析orders数组就是每一条订单的数据
}
}</code></pre>
<p>2、RequestReport 接口调用</p>
<pre class="blockcode"><code class="language-java">package com.example.amazon.amazon.untils;
import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.xml.XMLSerializer;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
impor |
|