· 9 years ago · Jan 14, 2017, 08:36 PM
1class UniqueCode extends Command
2{
3 /**
4 * The name and signature of the console command.
5 *
6 * @var string
7 */
8 protected $signature = 'code:unique';
9
10 /**
11 * The console command description.
12 *
13 * @var string
14 */
15 protected $description = 'Retrieve Information Based On Unique Code Description';
16
17 /**
18 * Create a new command instance.
19 *
20 * @return void
21 */
22 public function __construct()
23 {
24 parent::__construct();
25 }
26
27 /**
28 * Execute the console command.
29 *
30 * @return mixed
31 */
32 public function handle()
33 {
34 $client = new GuzzleHttpClient();
35
36 $access_key = '$accesskey';
37 $secret_key = '$secretkey';
38 $associate_tag = '$associate-tag';
39
40 $timestamp = date('c');
41 $uniquecodes = array("B01B0UET6O", "B01AMY8K4Q","B00JJZ7WUI", "B00JJZ7VE0","B00JJZ7URS", "B00JJZ7TME","B00JJZ7S2U", "B01FFQJ4MS","B00VB1TU44");
42 foreach ($uniquecodes as $codes) {
43 $query = [
44 'Service' => 'AWSECommerceService',
45 'Operation' => 'ItemLookup',
46 'ResponseGroup' => 'Large',
47 'IdType' => 'ASIN',
48 'ItemId' => $codes,
49 'Condition' => "New",
50 'AssociateTag' => $associate_tag,
51 'AWSAccessKeyId' => $access_key,
52 'Timestamp' => $timestamp
53 ];
54 }
55 ksort($query);
56
57 $sign = http_build_query($query);
58
59 $request_method = 'GET';
60 $base_url = 'webservices.amazon.com';
61 $endpoint = '/onca/xml';
62 $string_to_sign = "{$request_method}n{$base_url}n{$endpoint}n{$sign}";
63 $signature = base64_encode(
64 hash_hmac("sha256", $string_to_sign, $secret_key, true)
65 );
66
67 $query['Signature'] = $signature;
68
69 try {
70 $response = $client->request(
71 'GET', 'http://webservices.amazon.com/onca/xml',
72 ['query' => $query]
73 );
74
75 $contents = new SimpleXMLElement($response->getBody()->getContents());
76 echo "<pre>";
77 print_r($contents);
78 echo "</pre>";
79 } catch(Exception $e) {
80 echo "something went wrong: <br>";
81 echo $e->getMessage();
82 }
83}}
84
85public function handle()
86{
87 $client = new GuzzleHttpClient();
88
89 $access_key = '$accesskey';
90 $secret_key = '$secretkey';
91 $associate_tag = '$associate-tag';
92
93 $timestamp = date('c');
94 $uniquecodes = ["B01B0UET6O", "B01AMY8K4Q", "B00JJZ7WUI", "B00JJZ7VE0", "B00JJZ7URS", "B00JJZ7TME", "B00JJZ7S2U", "B01FFQJ4MS", "B00VB1TU44"];
95 foreach ($uniquecodes as $codes) {
96 $query = [
97 'Service' => 'AWSECommerceService',
98 'Operation' => 'ItemLookup',
99 'ResponseGroup' => 'Large',
100 'IdType' => 'ASIN',
101 'ItemId' => $codes,
102 'Condition' => "New",
103 'AssociateTag' => $associate_tag,
104 'AWSAccessKeyId' => $access_key,
105 'Timestamp' => $timestamp,
106 ];
107
108 ksort($query);
109
110 $sign = http_build_query($query);
111
112 $request_method = 'GET';
113 $base_url = 'webservices.amazon.com';
114 $endpoint = '/onca/xml';
115 $string_to_sign = "{$request_method}n{$base_url}n{$endpoint}n{$sign}";
116 $signature = base64_encode(
117 hash_hmac("sha256", $string_to_sign, $secret_key, true)
118 );
119
120 $query['Signature'] = $signature;
121
122 try {
123 $response = $client->request(
124 'GET', 'http://webservices.amazon.com/onca/xml',
125 ['query' => $query]
126 );
127
128 $contents = new SimpleXMLElement($response->getBody()->getContents());
129 echo "<pre>";
130 print_r($contents);
131 echo "</pre>";
132 } catch (Exception $e) {
133 echo "something went wrong: <br>";
134 echo $e->getMessage();
135 }
136 }
137}