-
Notifications
You must be signed in to change notification settings - Fork 0
/
apicall.php
114 lines (91 loc) · 3.6 KB
/
apicall.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
include_once("print.php");
include_once("amazonadd.php");
echo "<br/><a href='search.php'>Go Back</a>";
echo "<br/><a href='displayDB.php'>Display database</a>";
//Amazon
if(isset($_POST['Search'])) {
$name = $_POST['keywords'];
// Your AWS Access Key ID, as taken from the AWS Your Account page
$aws_access_key_id = " /*copy paste your access key id*/ ";
// Your AWS Secret Key corresponding to the above ID, as taken from the AWS Your Account page
$aws_secret_key = " /*copy paste your secret key */ ";
// The region you are interested in
$endpoint = "webservices.amazon.in";
$uri = "/onca/xml";
$params = array(
"Service" => "AWSECommerceService",
"Operation" => "ItemSearch",
"AWSAccessKeyId" => "AKIAIAQRDD3EJNDPPSNQ",
"AssociateTag" => "/* your associate tag*/",
"SearchIndex" => "Books",
"ResponseGroup" => "ItemAttributes, Offers, Images",
"Keywords" => $name,
"Availability" => "Available"
);
// Set current timestamp if not set
if (!isset($params["Timestamp"])) {
$params["Timestamp"] = gmdate('Y-m-d\TH:i:s\Z');
}
// Sort the parameters by key
ksort($params);
$pairs = array();
foreach ($params as $key => $value) {
array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
}
// Generate the canonical query
$canonical_query_string = join("&", $pairs);
// Generate the string to be signed
$string_to_sign = "GET\n".$endpoint."\n".$uri."\n".$canonical_query_string;
// Generate the signature required by the Product Advertising API
$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $aws_secret_key, true));
// Generate the signed URL
$request_url = 'http://'.$endpoint.$uri.'?'.$canonical_query_string.'&Signature='.rawurlencode($signature);
//echo "Signed URL: \"".$request_url."\"";
//Catch the response in the $response object
$response = file_get_contents($request_url);
$parsed_xml = simplexml_load_string($response);
//printSearchResults($parsed_xml, $SearchIndex);
//Verify a successful request
if(isset($parsed_xml->OperationRequest->Errors->Error)){
foreach($parsed_xml->OperationRequest->Errors->Error as $error){
echo "Error code: " . $error->Code . "\r\n";
echo $error->Message . "\r\n";
echo "\r\n";
}}
printSearchResults($parsed_xml);
amazonAddToDB($parsed_xml, $mysqli);
}
?>
<?php
//FlipKart
include_once("flpkprint.php");
include_once("flipkartadd.php");
if(isset($_POST['Search'])) {
$query = urlencode($_POST['keywords']);
$url= "https://affiliate-api.flipkart.net/affiliate/1.0/search.json?query=" . $query . "&resultCount=10";
//Make sure cURL is available
if (function_exists('curl_init') && function_exists('curl_setopt')){
//The headers are required for authentication
$headers = array(
'Cache-Control: no-cache',
'Fk-Affiliate-Id: /*your flipkart affiliate id */',
'Fk-Affiliate-Token: /*your affiliate token*/'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($ch, CURLOPT_USERAGENT, 'sai/0.1');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
$array=json_decode($result, true);
printFlipkartResults($array);
//$json = json_encode(json_decode($result), JSON_PRETTY_PRINT);
//echo $json;
flipkartAddToDB($array, $mysqli);
}
mysqli_close($mysqli);}
?>