我找到了java sdk 但我找不到使用的例子。
我需要调用ResolveCustomer(为产品和用户生成令牌)和GetEntitlements(给出产品和用户的权限列表)。
有没有人使用过这项服务?
答案 0 :(得分:1)
以下是从aws marketplace获取有关客户端的信息的完整示例。 你应该使用这个图书馆:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-marketplacemeteringservice</artifactId>
<version>1.11.192</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-marketplaceentitlement</artifactId>
<version>1.11.194</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
Java代码:
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.marketplaceentitlement.AWSMarketplaceEntitlementClient;
import com.amazonaws.services.marketplaceentitlement.AWSMarketplaceEntitlementClientBuilder;
import com.amazonaws.services.marketplaceentitlement.model.GetEntitlementsRequest;
import com.amazonaws.services.marketplaceentitlement.model.GetEntitlementsResult;
import com.amazonaws.services.marketplacemetering.*;
import com.amazonaws.services.marketplacemetering.model.*;
import org.junit.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class R
{
@Test
public void test() throws Exception
{
AWSCredentialsProvider provider = new AWSCredentialsProvider()
{
public AWSCredentials getCredentials()
{
return new AWSCredentials()
{
public String getAWSAccessKeyId()
{
return "<YOUR ACCESS KEY>";
}
public String getAWSSecretKey()
{
return "YOUR SECRET KEY";
}
};
}
public void refresh()
{
}
};
AWSMarketplaceMeteringClientBuilder b = AWSMarketplaceMeteringClient.builder();
b.setRegion("us-east-1"); // YOUR AWS REGION
b.setCredentials(provider);
AWSMarketplaceMetering c = b.build();
ResolveCustomerRequest r = new ResolveCustomerRequest();
r.setRegistrationToken(<YOUR "x-amzn-marketplace-token">); // it comes to your application in the url parameter when the user clicks the buy button in the aws market
final ResolveCustomerResult response = c.resolveCustomer(r);
AWSMarketplaceEntitlementClientBuilder entitlementClientBuilder = AWSMarketplaceEntitlementClient.builder();
entitlementClientBuilder.setRegion("us-east-1");
entitlementClientBuilder.setCredentials(provider);
GetEntitlementsRequest getEntitlementsRequest = new GetEntitlementsRequest();
getEntitlementsRequest.setProductCode(response.getProductCode());
getEntitlementsRequest.setFilter(new HashMap<String, List<String>>()
{{
put("CUSTOMER_IDENTIFIER", new ArrayList<String>()
{{
add(response.getCustomerIdentifier());
}});
}});
GetEntitlementsResult entitlementsResult = entitlementClientBuilder.build().getEntitlements(getEntitlementsRequest);
entitlementsResult = null;
}
}