· 8 years ago · Feb 05, 2018, 11:34 AM
1<?php
2error_reporting(E_ERROR);
3// Your Access Key ID, as taken from the Your Account page
4$access_key_id = "AKIAIZHMZ2NMSPSKTA4A";
5
6// Your Secret Key corresponding to the above ID, as taken from the Your Account page
7$secret_key = "Fy/tp8FiurbEyFwZF0/NovQ9dCtyV2/9PF7yn1qv";
8
9// The region you are interested in
10$endpoint = "webservices.amazon.co.uk";
11
12$uri = "/onca/xml";
13
14$lines = file('plik.txt');
15$fp = fopen("amazon.txt", "r+");
16
17foreach ($lines as $line_num => $line)
18{
19 $pattern = '/\s*/m';
20 $replace = '';
21 $liniaBezZnakowBialych = preg_replace( $pattern, $replace,$line );
22
23 $params = array(
24 "Service" => "AWSECommerceService",
25 "Operation" => "ItemSearch",
26 "AWSAccessKeyId" => "AKIAIZHMZ2NMSPSKTA4A",
27 "AssociateTag" => "amazonwyszuki-21",
28 "SearchIndex" => "All",
29 "Keywords" => $line, //4011334221098", //3250614126765
30 "ResponseGroup" => "Images,ItemAttributes,ItemIds,OfferFull,OfferListings,Offers,VariationSummary"
31 );
32
33 // Set current timestamp if not set
34 if (!isset($params["Timestamp"])) {
35 $params["Timestamp"] = gmdate('Y-m-d\TH:i:s\Z');
36 }
37
38 // Sort the parameters by key
39 ksort($params);
40
41 $pairs = array();
42
43 foreach ($params as $key => $value)
44 {
45 array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
46 }
47
48 // Generate the canonical query
49 $canonical_query_string = join("&", $pairs);
50
51 // Generate the string to be signed
52 $string_to_sign = "GET\n".$endpoint."\n".$uri."\n".$canonical_query_string;
53
54 // Generate the signature required by the Product Advertising API
55 $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $secret_key, true));
56
57 // Generate the signed URL
58 $request_url = 'http://'.$endpoint.$uri.'?'.$canonical_query_string.'&Signature='.rawurlencode($signature);
59
60 //echo $request_url. "<br />";
61
62 $dom = new DOMDocument;
63 $dom->preserveWhiteSpace = FALSE;
64 //sleep(2);
65
66 $dom->load($request_url);
67 $eans = $dom->getElementsByTagName('EAN');
68 $ceny = $dom->getElementsByTagName('Amount');
69 $najmniejszaCena = 9999;
70
71 foreach ($ceny as $cena)
72 {
73 $cena->nodeValue;
74 if ($cena->nodeValue < $najmniejszaCena)
75 {
76 $najmniejszaCena = $cena->nodeValue;
77 }
78 }
79
80 if($eans->length==0)
81 {
82 echo $liniaBezZnakowBialych;
83 echo "<br/>";
84 }
85 $kolejny = 0;
86
87 foreach ($eans as $ean)
88 {
89 //echo $ean->nodeValue. "----------------"
90 if ($liniaBezZnakowBialych == $ean->nodeValue && $liniaBezZnakowBialych != $kolejny)
91 {
92 $najmniejszaCena = $najmniejszaCena/100;
93 $najmniejszaCena = $najmniejszaCena."\r\n";
94 $noweDane = $liniaBezZnakowBialych;
95 fputs($fp, $noweDane."->".$najmniejszaCena);
96
97 echo $liniaBezZnakowBialych."->";
98 echo $najmniejszaCena."<br />";
99 $kolejny = $liniaBezZnakowBialych;
100 }
101 }
102}
103
104fclose($fp);
105?>