· 7 years ago · Jan 23, 2019, 01:30 PM
1<?php
2
3// Your Access Key ID, as taken from the Your Account page
4$access_key_id = "AKIAJZWJRMYA4CYSBA2A";
5
6// Your Secret Key corresponding to the above ID, as taken from the Your Account page
7$secret_key = "77kxEjNVnFFwV39eUennRYhmmUhEHrkC+DVgoaX3";
8
9// The region you are interested in
10$endpoint = "webservices.amazon.de";
11
12$uri = "/onca/xml";
13
14$params = array(
15 "Service" => "AWSECommerceService",
16 "Operation" => "CartCreate",
17 "AWSAccessKeyId" => "AKIAJZWJRMYA4CYSBA2A",
18 "AssociateTag" => "httpwwwxlco00-21",
19 "Item-1-ASIN" => "B0178MT96I",
20 "Item-1-Quantity" => "1",
21 "ResponseGroup" => "Cart",
22 "Item-2-ASIN" => "B0713XLVV2",
23 "Item-2-Quantity" => "1"
24);
25
26// Set current timestamp if not set
27if (!isset($params["Timestamp"])) {
28 $params["Timestamp"] = gmdate('Y-m-d\TH:i:s\Z');
29}
30
31// Sort the parameters by key
32ksort($params);
33
34$pairs = array();
35
36foreach ($params as $key => $value) {
37 array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
38}
39
40// Generate the canonical query
41$canonical_query_string = join("&", $pairs);
42
43// Generate the string to be signed
44$string_to_sign = "GET\n".$endpoint."\n".$uri."\n".$canonical_query_string;
45
46// Generate the signature required by the Product Advertising API
47$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $secret_key, true));
48
49// Generate the signed URL
50$request_url = 'https://'.$endpoint.$uri.'?'.$canonical_query_string.'&Signature='.rawurlencode($signature);
51
52echo "Signed URL: \"".$request_url."\"";
53
54?>