我需要将亚马逊 MWS 操作称为"请求报告",并将报告类型指定为"_GET_FLAT_FILE_OPEN_LISTINGS_DATA_"。 我已经成功连接以获取FulfillmentInventory/ListInventorySupply,所以我知道cURL和Amazon设置是正确的,但是每次提交时,我都会收到"我们计算的请求签名与您提供的签名不匹配。检查您的 AWS 秘密访问密钥和签名方法。有关详细信息,请参阅服务文档。我已经在第 23 行和第 14 行尝试了排序和 ksort - 在调用 FulfillmentInventory/ListInventorySupply 时,我必须使用两个 kSort 对其进行设置,以便将 SKU 列表保持在 API 的正确顺序
这是我说的代码,秘密、商家和 keyid 是正确的:
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 时,它"看起来"正确,所以我一定错过了一些东西,我希望这对那里的人来说是显而易见的,因为我很困惑。
顺便说一句,暂存器将其列为卖方ID,但网址将其显示为商家 - 我已经尝试了两者,但没有乐趣
不是向你扔曲线球,但我在使用RequestReport
方面取得的唯一成功是通过使用亚马逊创建的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...
编辑
此代码将创建报表请求,但实际上不会创建报表。您必须继续使用相同的代码轮询亚马逊,直到您收到"完成"或类似内容(不记得创建报告时亚马逊发回的确切单词)。然后,您需要实际检索报告。