2

Java sdk は見つかりましたが、使用例が見つかりません。

ResolveCustomer (製品とユーザーのトークンを生成) と GetEntitlements (製品とユーザーの権利のリストを提供) を呼び出す必要があります。

このサービスを利用した人はいますか?

4

1 に答える 1

3

aws マーケットプレイスからクライアントに関する情報を取得する完全な例を次に示します。このライブラリを使用する必要があります。

 <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;
    }
}

また、AWS アカウントにポリシーを追加する必要があります。 ここに画像の説明を入力

于 2017-09-15T05:46:47.947 に答える