-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
81 lines (72 loc) · 2.46 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
require_once "config.php";
require_once "paapi5.php";
$itemId = $_GET['item'];
$serviceName="ProductAdvertisingAPI";
$region="us-west-2";
$accessKey=AMZN_ACCESS_KEY;
$secretKey=AMZN_SECRET_KEY;
$payload="{"
." \"ItemIds\": ["
." \"${itemId}\""
." ],"
." \"Resources\": ["
." \"BrowseNodeInfo.BrowseNodes\","
." \"Images.Primary.Small\","
." \"Images.Primary.Medium\","
." \"Images.Primary.Large\","
." \"ItemInfo.Title\","
." \"Offers.Listings.DeliveryInfo.IsPrimeEligible\","
." \"Offers.Listings.Price\""
." ],"
." \"PartnerTag\": \"" . "ochitegome-22" . "\","
." \"PartnerType\": \"Associates\","
." \"Marketplace\": \"www.amazon.co.jp\""
."}";
$host="webservices.amazon.co.jp";
$uriPath="/paapi5/getitems";
$awsv4 = new AwsV4 ($accessKey, $secretKey);
$awsv4->setRegionName($region);
$awsv4->setServiceName($serviceName);
$awsv4->setPath ($uriPath);
$awsv4->setPayload ($payload);
$awsv4->setRequestMethod ("POST");
$awsv4->addHeader ('content-encoding', 'amz-1.0');
$awsv4->addHeader ('content-type', 'application/json; charset=utf-8');
$awsv4->addHeader ('host', $host);
$awsv4->addHeader ('x-amz-target', 'com.amazon.paapi5.v1.ProductAdvertisingAPIv1.GetItems');
$headers = $awsv4->getHeaders ();
$headerString = "";
foreach ( $headers as $key => $value ) {
$headerString .= $key . ': ' . $value . "\r\n";
}
$params = array (
'http' => array (
'header' => $headerString,
'method' => 'POST',
'content' => $payload
)
);
$stream = stream_context_create ( $params );
sleep(3);
$fp = @fopen ( 'https://'.$host.$uriPath, 'rb', false, $stream );
if (! $fp) {
throw new Exception ( "Exception Occured" );
}
$response = @stream_get_contents ( $fp );
if ($response === false) {
throw new Exception ( "Exception Occured" );
}
$item = json_decode($response)->ItemsResult->Items[0];
header("Content-Type: application/json; charset=utf-8");
echo json_encode([
"title" => $item->ItemInfo->Title->DisplayValue,
"item_url" => $item->DetailPageURL,
"images" => [
"large" => $item->Images->Primary->Large->URL,
"medium" => $item->Images->Primary->Medium->URL,
"small" => $item->Images->Primary->Small->URL,
],
"price" => $item->Offers->Listings[0]->Price->DisplayAmount,
"is_prime" => !!$item->Offers->Listings[0]->DeliveryInfo->IsPrimeEligible,
]);