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文件发送测试申请
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());
申请后果:
到此官网文档的六个接口都以测试结束!