1.获取Amazon官方SDK
2.获得的效果如下
@Test
public void test01(){
//1.连接到spApi
//1.1配置自己的AWS凭证
AWSAuthenticationCredentials awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
.accessKeyId("you accessKeyId")
.secretKey("you secretKey")
.region("us-east-1")
.build();
//1.2配置您的AWS凭证提供商
AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSAuthenticationCredentialsProvider.builder()
.roleArn("you roleArn")//IAM角色
.roleSessionName("you roleSessionName")
.build();
//1.3配置LWA凭证
LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
.clientId("you clientId")
.clientSecret("you clientSecret")
.refreshToken("you refreshToken")
.endpoint("https://api.amazon.com/auth/o2/token")//LWA验证服务器URI
.build();
OrdersV0Api ordersV0Api = new OrdersV0Api.Builder().awsAuthenticationCredentials(awsAuthenticationCredentials)
.awsAuthenticationCredentialsProvider(awsAuthenticationCredentialsProvider)
.lwaAuthorizationCredentials(lwaAuthorizationCredentials)
//本次试验为测试环境
.endpoint("https://sandbox.sellingpartnerapi-na.amazon.com")
.build();
3.参考OrdersV0.json文件发送测试请求
请选中带有x-amazon-spds-sandbox-behaviors的内容为测试请求要求。
4.实操
4.1 getOrders
请求要求:
请求代码:
List<String> marketplaceIds = Arrays.asList("ATVPDKIKX0DER");
GetOrdersResponse orders = null;
try {
orders = ordersV0Api.getOrders(marketplaceIds, "TEST_CASE_200", null, null, null, null, null, null, null, null, null, null, null, null);
} catch (ApiException e) {
e.printStackTrace();
System.out.println("orders.getErrors().toString() = " + orders.getErrors().toString());
}
System.out.println("orders.getPayload().getOrders() = " + orders.getPayload().getOrders());
请求结果:
4.2 getOrder
请求要求:
请求代码:
GetOrderResponse order = null;
try {
order = ordersV0Api.getOrder("TEST_CASE_200");
} catch (ApiException e) {
e.printStackTrace();
}
System.out.println("order.getPayload() = " + order.getPayload());
请求结果:
4.3 getOrderBuyerInfo
请求要求:
请求代码:
GetOrderBuyerInfoResponse order = null;
try {
order = ordersV0Api.getOrderBuyerInfo("TEST_CASE_200");
} catch (ApiException e) {
e.printStackTrace();
}
System.out.println("order.getPayload() = " + order.getPayload());
请求结果:
4.4 getOrderAddress
请求要求:
请求代码:
GetOrderAddressResponse order = null;
try {
order = ordersV0Api.getOrderAddress("TEST_CASE_200");
} catch (ApiException e) {
e.printStackTrace();
}
System.out.println("order.getPayload() = " + order.getPayload());
请求结果:
4.5 getOrderItems
请求要求:
请求代码:
GetOrderItemsResponse order = null;
try {
order = ordersV0Api.getOrderItems("TEST_CASE_200",null);
} catch (ApiException e) {
e.printStackTrace();
}
System.out.println("order.getPayload() = " + order.getPayload());
请求结果:
4.6 getOrderItemsBuyerInfo
请求要求:
请求代码:
GetOrderItemsBuyerInfoResponse order = null;
try {
order = ordersV0Api.getOrderItemsBuyerInfo("TEST_CASE_200",null);
} catch (ApiException e) {
e.printStackTrace();
}
System.out.println("order.getPayload() = " + order.getPayload());
请求结果:
到此官方文档的六个接口都以测试完毕!