我正在尝试使用亚马逊 MWS GetMatchingProductForId API,但我一直在尝试获取多个 isbn 的信息。格式需要采用以下形式:IdList.Id.1=isbn[x],其中 isbn[x] 是我的数组。我需要能够将它们列在 20 个列表中(即 IdList.Id.1=, IdList.Id.2= ...IdList.Id.20= )。我以为我可以像这样使用 implode($isbn) :
$count=0;
function ProductId_xml($searchTerm) {
$params = array(
'AWSAccessKeyId' => AWS_ACCESS_KEY_ID,
'Action' => "GetMatchingProductForId",
'SellerId' => MERCHANT_ID,
'SignatureMethod' => "HmacSHA256",
'SignatureVersion' => "2",
'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
'Version'=> "2011-10-01",
'MarketplaceId' => MARKETPLACE_ID,
'IdType' => "ISBN",
);
$id=array(explode(',',$searchTerm));
foreach ($id as $newId)
{
$count .= $count +1;
$params += array('IdList.Id.'.$count => $newId);
} //end of foreach
// Sort the URL parameters
$url_parts = array();
foreach(array_keys($params) as $key)
$url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));
sort($url_parts);
// Construct the string to sign
$url_string = implode("&", $url_parts);
$string_to_sign = "GET\nmws.amazonservices.com\n/Products/2011-10-01\n" . $url_string;
// Sign the request
$signature = hash_hmac("sha256", $string_to_sign, AWS_SECRET_ACCESS_KEY, TRUE);
// Base64 encode the signature and make it URL safe
$signature = urlencode(base64_encode($signature));
$url = "https://mws.amazonservices.com/Products/2011-10-01" . '?' . $url_string . "&Signature=" . $signature;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);
$parsed_xml = simplexml_load_string($response);
return ($parsed_xml);
}
}
?>
$searchterm 是我的 isbn 数字数组,但这仅将它们列为 isbn 字符串。我知道如果我一次只使用一个 isbn 就可以了,但我需要以 20 个为一组运行它们以加快我的进程。我不知道从这里去哪里。任何帮助将不胜感激。编辑:我已经更新了函数,以便它将 20 个 isbn 的批次包含在 $params 中,但我不确定我添加它的方式是否正确。