(View Original Web?)

HOBBY > SOURCE CODE

Tutorial PHP Amazon API timestamp signature request auto generate XML method


(Page 1 of 1)
AMAZON API, AWS, ECS, WEBSERVICES Tutorial
How to auto generate request signature?
How to auto generate timestamp?
This sample to add cart with timestamp and signature request

Code:
<?php

//////////////////////DEFINE////////////////
/////////////MODIF THIS////////////////////
$country 'com';
$api_key '';
$secret_api_key '';
$associate_tag '';
$id_produk_amazon ''// ASIN ID
///////////////////////////////////////////////

$method "GET";
$host 'webservices.amazon.'.$country;
$uri "/onca/xml";
$timestampauto gmdate("Y-m-d\TH:i:s\Z");

$koleksiparam = array
(
"Service"=>"AWSECommerceService"
"AWSAccessKeyId"=>$api_key,
"AssociateTag"=>$associate_tag
"Timestamp"=>$timestampauto ,
"Operation"=>"CartCreate",
"Item.1.ASIN"=>$id_produk_amazon,
"Item.1.Quantity"=>"1",
"Version"=>"2009-01-01"
);
ksort($koleksiparam);
$canonicalized_query = array();
foreach (
$koleksiparam as $param=>$value)
{
$param str_replace("%7E""~"rawurlencode($param));
$value str_replace("%7E""~"rawurlencode($value));
$canonicalized_query[] = $param."=".$value;
}
$canonicalized_query implode("&"$canonicalized_query);
$string_to_sign $method."
"
.$host."
"
.$uri."
"
.$canonicalized_query;
$signature base64_encode(hash_hmac("sha256"$string_to_sign$secret_api_keyTrue));
$signature str_replace("%7E""~"rawurlencode($signature));
echo @
file_get_contents('http://webservices.amazon.'.$country.'/onca/xml?'.$canonicalized_query.'&Signature='.$signature.''); ?>

 
(Page 1 of 1)

Navigation

Back Sub-Forum