繁体   English   中英

Amazon MWS API返回SignatureDoesNotMatch

[英]Amazon MWS API returning SignatureDoesNotMatch

我需要调用亚马逊MWS操作“ RequestReport”,并将ReportType指定为“ _GET_FLAT_FILE_OPEN_LISTINGS_DATA_”。 我已经成功连接以获得FulfillmentInventory / ListInventorySupply,所以我知道cURL和Amazon设置正确,但是每次提交时我都会收到“我们计算出的请求签名与您提供的签名不匹配。 检查您的AWS Secret Access密钥和签名方法。 有关详细信息,请查阅服务文档。 从服务器返回。 我在第23行和第14行中都尝试了sort和ksort-在对FulfillmentInventory / ListInventorySupply的调用中,我必须将其设置为两个ksort,以使SKU列表保持API的正确顺序

这是代码,正如我所说的,秘密,商人和密钥ID是正确的:

header('Content-type: application/xml');
$secret = 'secretcodehere';

$param = array();
$param['AWSAccessKeyId']   = 'accessidhere'; 
$param['Action']           = 'RequestReport'; 
$param['Merchant']         = 'merchantidhere';
$param['SignatureVersion'] = '2'; 
$param['Timestamp']        = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());

$param['Version']          = '2009-01-01'; 
$param['SignatureMethod']  = 'HmacSHA256';  
$param['ReportType']  = '_GET_FLAT_FILE_OPEN_LISTINGS_DATA_';  
ksort($param);
$url = array();
foreach ($param as $key => $val) {

    $key = str_replace("%7E", "~", rawurlencode($key));
    $val = str_replace("%7E", "~", rawurlencode($val));
    $url[] = "{$key}={$val}";
}

sort($url);

$arr   = implode('&', $url);

$sign  = 'POST' . "\n";
$sign .= 'mws.amazonservices.com';
$sign .= '/doc/2009-01-01' . "\n";
$sign .= $arr;

$signature = hash_hmac("sha256", $sign, $secret, true);
$signature = urlencode(base64_encode($signature));

$link  = "https://mws.amazonservices.com/doc/2009-01-01/?";
$link .= $arr . "&Signature=" . $signature;
/*

echo($link);//for debugging 

exit(); */

$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
print_r($response);

我已经在MWS暂存器中尝试过它,并且信息是正确的并生成200响应,并且当我对照暂存器生成的URL检查URL时,它“看起来”正确,因此我必须丢失一些内容,我希望它显而易见有人在那里,因为我感到困惑。

btw-scratchpad将其列为SellerId,但url将其显示为Merchant-我已经尝试了两次,都没有高兴

不用给您一个曲线球,但是我使用RequestReport的唯一成功就是使用了Amazon创建的PHP库。 如果您还没有的话,这里是链接

这是我刚刚确认的可用于请求报告的代码:

<?php

define('AWS_ACCESS_KEY_ID', $am_aws_access_key);
define('AWS_SECRET_ACCESS_KEY', $am_secret_key);
define('MERCHANT_ID', $am_merchant_id);
define('MARKETPLACE_ID', $am_marketplace_id);

include_once ('/link/to/Amazon/library/MarketplaceWebService/Samples/.config.inc.php');

include_once ('functions.php');

$serviceUrl = "https://mws.amazonservices.com";
$config = array (
    'ServiceURL' => $serviceUrl,
    'ProxyHost' => null,
    'ProxyPort' => -1,
    'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebService_Client(
    AWS_ACCESS_KEY_ID,
    AWS_SECRET_ACCESS_KEY,
    $config,
    APPLICATION_NAME,
    APPLICATION_VERSION);

echo '<br />';
$parameters = array (
    'Marketplace' => MARKETPLACE_ID,
    'Merchant' => MERCHANT_ID,
    'ReportType' => '_GET_FLAT_FILE_OPEN_LISTINGS_DATA_',
);

echo '<br /><br/>Request Report Request:<br><br>';
$request = new MarketplaceWebService_Model_RequestReportRequest($parameters);
print_r($request);
invokeRequestReport($service, $request);
echo '<br /><br/>';

functions.php文件(基本上是MarketplaceWebService\\Samples\\RequestReportSample.php文件中代码后半部分的重要功能:

function invokeRequestReport(MarketplaceWebService_Interface $service, $request)
{
    try {
        $response = $service->requestReport($request);
        echo ("Service Response\n");
        echo ("=============================================================================\n");
        echo("        RequestReportResponse\n");
        if ($response->isSetRequestReportResult()) {
            echo("            RequestReportResult\n");
            $requestReportResult = $response->getRequestReportResult();
            if ($requestReportResult->isSetReportRequestInfo()) {
                $reportRequestInfo = $requestReportResult->getReportRequestInfo();
                echo("                ReportRequestInfo\n");
                if ($reportRequestInfo->isSetReportRequestId())
                {
                    echo("                    ReportRequestId\n");
                    echo("                        " . $reportRequestInfo->getReportRequestId() . "\n");
                }
                $report_request_id = $reportRequestInfo->getReportRequestId();
                $report_type = '';
                if ($reportRequestInfo->isSetReportType())
                {
                    echo("                    ReportType\n");
                    echo("                        " . $reportRequestInfo->getReportType() . "\n");
                    $report_type = $reportRequestInfo->getReportType();
                }
                if ($reportRequestInfo->isSetStartDate())
                {
                    echo("                    StartDate\n");
                    echo("                        " . $reportRequestInfo->getStartDate()->format(DATE_FORMAT) . "\n");
                }
                if ($reportRequestInfo->isSetEndDate())
                {
                    echo("                    EndDate\n");
                    echo("                        " . $reportRequestInfo->getEndDate()->format(DATE_FORMAT) . "\n");
                }
                if ($reportRequestInfo->isSetSubmittedDate())
                {
                    echo("                    SubmittedDate\n");
                    echo("                        " . $reportRequestInfo->getSubmittedDate()->format(DATE_FORMAT) . "\n");
                }
                if ($reportRequestInfo->isSetReportProcessingStatus())
                {
                    echo("                    ReportProcessingStatus\n");
                    echo("                        " . $reportRequestInfo->getReportProcessingStatus() . "\n");
                }
                if($report_type == '_GET_FLAT_FILE_OPEN_LISTINGS_DATA_') {
                    if(!empty($report_request_id)) {
                        $parameters = array (
                            'Marketplace' => MARKETPLACE_ID,
                            'Merchant' => MERCHANT_ID,
                            'Report' => @fopen('php://memory', 'rw+'),
                            'ReportRequestIdList' => $report_request_id,
                        );
                        $report = new MarketplaceWebService_Model_GetReportRequestListRequest($parameters);
                        print_r($report);
                    }
                }
            }
        }
        if ($response->isSetResponseMetadata()) {
            echo("            ResponseMetadata\n");
            $responseMetadata = $response->getResponseMetadata();
            if ($responseMetadata->isSetRequestId())
            {
                echo("                RequestId\n");
                echo("                    " . $responseMetadata->getRequestId() . "\n");
            }
        }
    } catch (MarketplaceWebService_Exception $ex) {
        echo("Caught Exception: " . $ex->getMessage() . "\n");
        echo("Response Status Code: " . $ex->getStatusCode() . "\n");
        echo("Error Code: " . $ex->getErrorCode() . "\n");
        echo("Error Type: " . $ex->getErrorType() . "\n");
        echo("Request ID: " . $ex->getRequestId() . "\n");
        echo("XML: " . $ex->getXML() . "\n");
    }
}

编辑

这是.config.inc.php文件的重要部分:

<?php

define ('DATE_FORMAT', 'Y-m-d\TH:i:s\Z');
date_default_timezone_set('America/Denver');

$app_name = "Just make up a name like 'Awesome Sync'";
$app_version = "1.0";
define('APPLICATION_NAME', $app_name);
define('APPLICATION_VERSION', $app_version);

set_include_path('/link/to/Amazon/library/');
...rest of code...

编辑

这段代码将创建报告请求,但是实际上并没有创建报告。 您必须继续使用相同的代码轮询Amazon,直到收到“ Complete”或类似的内容(创建报告后,Amazon不会回信确切的单词)。 然后,您需要实际检索报告。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM