/*
* 基本情報
*/
const SERVICE = "AWSECommerceService";
const ACCESS_KEY = "自身のアクセスキーを入力";
const ASSOCIATE_TAG = "自身のアソシエイトIDを入力";
const SECRET_KEY = "自身の秘密キーを入力";
$operation = "ItemSearch";
$searchIndex = "Apparel";
$keywords = "Shirt";
$timestamp = gmdate('Y-m-d\TH:i:s\Z');
$params = array(
"Service" => SERVICE,
"AWSAccessKeyId" => ACCESS_KEY,
"AssociateTag" => ASSOCIATE_TAG,
"Operation" => $operation,
"SearchIndex" => $searchIndex,
"Keywords" => $keywords,
"Timestamp" => $timestamp
);
//キーのソートを実行する。
//ソートをしないと思わぬエラーが発生するので要注意。
ksort($params);
//パラメータの整形
$pairs = array();
foreach ($params as $key => $value) {
array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
}
$canonicalQS = join("&", $pairs);
/*
* 署名情報
*/
const REQUEST_METHOD = "GET";
const ENDPOINT = "webservices.amazon.co.jp";
const REQUEST_URI = "/onca/xml";
const ALGORITHM = "sha256";
$toSign =
REQUEST_METHOD . "\n"
. ENDPOINT . "\n"
. REQUEST_URI . "\n"
. $canonicalQS;
//RFC2104準拠のHMAC-SHA256ハッシュアルゴリズムで計算する
$signature = rawurlencode(base64_encode(hash_hmac(ALGORITHM, $toSign, SECRET_KEY, true)));
//リクエストURL完成
$url = "http://" . ENDPOINT . REQUEST_URI . "?" . $canonicalQS . "&Signature=" . $signature;
echo "url: " . $url;
|