亚马逊MWS API返回SignatureDoesNotMatch
我需要调用Amazon MWS操作'RequestReport'并将ReportType指定为'_GET_FLAT_FILE_OPEN_LISTINGS_DATA_'。 我已成功连接到获得FulfillmentInventory / ListInventorySupply,所以我知道cURL和亚马逊设置是正确的,但每次我提交我得到'我们计算的请求签名与您提供的签名不匹配。 检查您的AWS秘密访问密钥和签名方法。 有关详细信息,请参阅服务文档。' 从服务器返回。 我已经在第23和第14行尝试了sort和ksort - 在调用FulfillmentInventory / ListInventorySupply时,我不得不使用两个ksorts来设置它,以便保持API的正确顺序的SKU列表
正如我所说,这是密码,秘密,商人和钥匙是正确的:
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-dTH:i:s. 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,但该网址将其显示为商家 - 我已经尝试过,没有任何快乐
不要向你抛出一个曲线球,但是我使用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
文件(基本上是MarketplaceWebServiceSamplesRequestReportSample.php
文件中后半段代码中的重要功能:
function invokeRequestReport(MarketplaceWebService_Interface $service, $request)
{
try {
$response = $service->requestReport($request);
echo ("Service Responsen");
echo ("=============================================================================n");
echo(" RequestReportResponsen");
if ($response->isSetRequestReportResult()) {
echo(" RequestReportResultn");
$requestReportResult = $response->getRequestReportResult();
if ($requestReportResult->isSetReportRequestInfo()) {
$reportRequestInfo = $requestReportResult->getReportRequestInfo();
echo(" ReportRequestInfon");
if ($reportRequestInfo->isSetReportRequestId())
{
echo(" ReportRequestIdn");
echo(" " . $reportRequestInfo->getReportRequestId() . "n");
}
$report_request_id = $reportRequestInfo->getReportRequestId();
$report_type = '';
if ($reportRequestInfo->isSetReportType())
{
echo(" ReportTypen");
echo(" " . $reportRequestInfo->getReportType() . "n");
$report_type = $reportRequestInfo->getReportType();
}
if ($reportRequestInfo->isSetStartDate())
{
echo(" StartDaten");
echo(" " . $reportRequestInfo->getStartDate()->format(DATE_FORMAT) . "n");
}
if ($reportRequestInfo->isSetEndDate())
{
echo(" EndDaten");
echo(" " . $reportRequestInfo->getEndDate()->format(DATE_FORMAT) . "n");
}
if ($reportRequestInfo->isSetSubmittedDate())
{
echo(" SubmittedDaten");
echo(" " . $reportRequestInfo->getSubmittedDate()->format(DATE_FORMAT) . "n");
}
if ($reportRequestInfo->isSetReportProcessingStatus())
{
echo(" ReportProcessingStatusn");
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(" ResponseMetadatan");
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
echo(" RequestIdn");
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-dTH:i:sZ');
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...
编辑
此代码将创建报告请求,但实际上并未创建报告。 您必须继续使用相同的代码对亚马逊进行调查,直到您收到“完整”或类似的内容(不记得报告创建时亚马逊发回的确切字词)。 那么你需要实际检索报告。
链接地址: http://www.djcxy.com/p/39013.html