0

文档链接:https ://github.com/amzn/ sell-partner-api-docs/blob/main/guides/en-US/use-case-guides/feeds-api-use-case-guide/feeds-api-用例指南_2021-06-30.md#step-3-upload-the-feed-data

大家好,我知道亚马逊在 2021-06-30 版本的创建提要中不需要数据加密。我正在研究 feed api 并试图将产品发送到亚马逊。有没有人有 C# 中的 feed api 解决方案?

这是我的上传文件功能

public async Task UploadFile(byte[] bytes, string url)
    {
        var contentType = "text/xml; charset=UTF-8;"; // this should be the same as what was used in Step #1 (in the CreateFeedDocument API request)

        RestClient restClient = new RestClient(url);
        IRestRequest restRequest = new RestRequest(Method.POST);

        restRequest.AddParameter(contentType, bytes, ParameterType.RequestBody);

        var response = await restClient.ExecuteAsync(restRequest);

        if (!response.IsSuccessful)
        {
            // your error logic
        }

        // success. Move to Step #3
    }

[我每次都收到此错误,我已成功签署以获取订单和 createfeeddocument,但我收到签署错误。][2]

'Signature doesnt match' !

<?xml version="1.0" encoding="UTF-8"?>
SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.AKIAX2ZVOZFBD2CTMM2RAWS4-HMAC-SHA256 20210811T092947Z 20210811/eu-west-1/s3/aws4_request e0a3e8fdad01a4e256375c3a70426099e0a0f1dd1098e1f2184551858abb04bd460a2d16ab8d54f4ae1e96b23840540bb668e58b407fd3b7a83ca8f932eb24f741 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 32 31 30 38 31 31 54 30 39 32 39 34 37 5a 0a 32 30 32 31 30 38 31 31 2f 65 75 2d 77 65 73 74 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 65 30 61 33 65 38 66 64 61 64 30 31 61 34 65 32 35 36 33 37 35 63 33 61 37 30 34 32 36 30 39 39 65 30 61 30 66 31 64 64 31 30 39 38 65 31 66 32 31 38 34 35 35 31 38 35 38 61 62 62 30 34 62 64PUT //NinetyDays/amzn1.tortuga.3.bd6c391e-4b21-4f3a-91ce-515b52290d26.T3K0FV1JLTYHKL X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAX2ZVOZFBD2CTMM2R%2F20210811%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20210811T092947Z&X-Amz-Expires=300&X-Amz-SignedHeaders=content-type%3Bhost content-type:text/plain host:tortuga-prod-eu.s3-eu-west-1.amazonaws.com

content-type;host UNSIGNED-PAYLOAD50 55 54 0a 2f 2f 4e 69 6e 65 74 79 44 61 79 73 2f 61 6d 7a 6e 31 2e 74 6f 72 74 75 67 61 2e 33 2e 62 64 36 63 33 39 31 65 2d 34 62 32 31 2d 34 66 33 61 2d 39 31 63 65 2d 35 31 35 62 35 32 32 39 30 64 32 36 2e 54 33 4b 30 46 56 31 4a 4c 54 59 48 4b 4c 0a 58 2d 41 6d 7a 2d 41 6c 67 6f 72 69 74 68 6d 3d 41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 26 58 2d 41 6d 7a 2d 43 72 65 64 65 6e 74 69 61 6c 3d 41 4b 49 41 58 32 5a 56 4f 5a 46 42 44 32 43 54 4d 4d 32 52 25 32 46 32 30 32 31 30 38 31 31 25 32 46 65 75 2d 77 65 73 74 2d 31 25 32 46 73 33 25 32 46 61 77 73 34 5f 72 65 71 75 65 73 74 26 58 2d 41 6d 7a 2d 44 61 74 65 3d 32 30 32 31 30 38 31 31 54 30 39 32 39 34 37 5a 26 58 2d 41 6d 7a 2d 45 78 70 69 72 65 73 3d 33 30 30 26 58 2d 41 6d 7a 2d 53 69 67 6e 65 64 48 65 61 64 65 72 73 3d 63 6f 6e 74 65 6e 74 2d 74 79 70 65 25 33 42 68 6f 73 74 0a 63 6f 6e 74 65 6e 74 2d 74 79 70 65 3a 74 65 78 74 2f 70 6c 61 69 6e 0a 68 6f 73 74 3a 74 6f 72 74 75 67 61 2d 70 72 6f 64 2d 65 75 2e 73 33 2d 65 75 2d 77 65 73 74 2d 31 2e 61 6d 61 7a 6f 6e 61 77 73 2e 63 6f 6d 0a 0a 63 6f 6e 74 65 6e 74 2d 74 79 70 65 3b 68 6f 73 74 0a 55 4e 53 49 47 4e 45 44 2d 50 41 59 4c 4f 41 447H09K126X3778XS3meKxAQ/wrXgZswVZUrw8Zat1PMACU8dQwhVnPP8KUV5Yi5P3G4Y/tDZGjGaOe3rrBtXg1y8A5Ag=

我的项目 MVC.netcore3

请帮我

4

1 回答 1

1

大家好,经过与亚马逊的几次会议后,我找到了解决方案。在第 1 步中:创建提要文档,提供输入提要文档 ID 和 url。网址涵盖了所有需要作为查询字符串。因此,您可以使用 put 方法上传数据。您可以在下面看到邮递员请求和 c# 代码。

在此处输入图像描述

public CreateFeedDocumentResponse CreateFeedDocument(LWAAuthorizationCredentials lwaAuthCreds, AWSAuthenticationCredentials awsAuthCreds, AssumeRoleRequest assumeRoleRequest, string marketPlaceId)
    {

        using (var STSClient = new AmazonSecurityTokenServiceClient(awsAuthCreds.AccessKeyId, awsAuthCreds.SecretKey, RegionEndpoint.USEast1))
        {
            var req = new AssumeRoleRequest()
            {
                RoleArn = assumeRoleRequest.RoleArn,
                DurationSeconds = 950, //put anything you want here
                RoleSessionName = Guid.NewGuid().ToString()
            };

            AssumeRoleResponse assumeRoleResponse = STSClient.AssumeRoleAsync(req, new CancellationToken()).Result;

            RestClient restClient = new RestClient("https://sellingpartnerapi-eu.amazon.com");

            IRestRequest restRequest = new RestRequest("/feeds/2021-06-30/documents", Method.POST, DataFormat.Json); // 2021/06/30

            restRequest = new LWAAuthorizationSigner(lwaAuthCreds).Sign(restRequest);

            var awsAuthCred = new AWSAuthenticationCredentials
            {
                AccessKeyId = assumeRoleResponse.Credentials.AccessKeyId,
                SecretKey = assumeRoleResponse.Credentials.SecretAccessKey,
                Region = awsAuthCreds.Region,
            };
            restRequest.AddParameter("application/json", "{ \"contentType\": \"text/xml; charset=UTF-8\"}", ParameterType.RequestBody);

            restRequest.AddHeader("x-amz-security-token", assumeRoleResponse.Credentials.SessionToken);
            restRequest = new AWSSigV4Signer(awsAuthCred)
                .Sign(restRequest, restClient.BaseUrl.Host);
            var resp = restClient.Execute(restRequest);

            return JsonConvert.DeserializeObject<CreateFeedDocumentResponse>(resp.Content);
        }
    }

    public static async Task UploadFile(Uri url,string data)
    {
     
        RestClient restClient = new RestClient(url);
        IRestRequest restRequest = new RestRequest(Method.PUT);
        restRequest.AddHeader("Content-Type", "text/xml; charset=UTF-8");
        restRequest.AddXmlBody(data);
        var response = await restClient.ExecuteAsync(restRequest);

        if (response.StatusCode!= System.Net.HttpStatusCode.OK)
        {
            // your error logic
        }

        // success. Move to Step #3
    }
于 2021-09-02T07:57:21.257 回答