-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskytest1.php
235 lines (204 loc) · 5.66 KB
/
skytest1.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
session_start();
$apikey='Mu487549814095508692970935581566';
//$apikey='prtl6749387986743898559646983194';
$originplace =$_REQUEST['info'];
/*$split=explode(',',$info);
$country=$split[0];
$currency=$split[1];
$locale=urlencode($split[2]);
$originplace=$split[3];
$destinationplace=$split[4];
$outbounddate=$split[5];
$inbounddate=$split[6];
$cabinclass=$split[7];
$adults=$split[8];
$origincity=$split[9];
$destinationcity=$split[10];
*/
$arr_names =array();
$ct='';
$session_key='';
//get current date from server
//set time zone
date_default_timezone_set('ASIA/CALCUTTA');
// Then call the date functions
$outbounddate = date('Y-m-d');
$params = http_build_query(array
(
"currency" => 'INR',
"country" => 'IN',
"locale" => 'en-IN',
"originPlace" => 'GOI-sky',
"destinationPlace" => $originplace,
"outbounddate" => $outbounddate,
"cabinclass" => 'Economy',
"adults" => 1
));
/*
$params = http_build_query(array
(
"currency" => 'GBP',
"country" => 'GB',
"locale" =>'en-GB',
"originPlace" => 'DEL-sky',
"destinationPlace" => 'GOA-sky',
"outbounddate" => '2014-12-25',
"inbounddate" => '2014-12-30',
"cabinclass" => 'Economy',
"adults" => 1
));
*/
//variables
$searcheddate=' ';
$cheapestprice=' ';
$origin=' ';
$destination=' ';
$arr_names=array();
/*DB connection
$sql = "SELECT * FROM skyscanner where city1='$origincity' AND airportcode1='$originplace' AND city2='$destinationcity' AND airportcode2='$destinationplace' AND outbounddate='$outbounddate' AND inbounddate='$inbounddate'";
$retval = mysqli_query($con,$sql);
if(!$retval)
{
die('Could not enter data: ' . mysqli_error());
}
while($row = mysqli_fetch_array($retval))
{
$searcheddate=$row['searchdate'];
$cheapestprice=$row['cheapestprice'];
$origin=$row['city1'];
$destination=$row['city2'];
}
*/
//step1
$cSession = curl_init();
//step2
curl_setopt($cSession,CURLOPT_URL,"http://partners.api.skyscanner.net/apiservices/pricing/v1.0?apikey=".$apikey);
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession, CURLOPT_POST, true);
curl_setopt($cSession,CURLOPT_HEADER, true);
curl_setopt($cSession, CURLOPT_VERBOSE, 1);
curl_setopt($cSession, CURLOPT_POSTFIELDS, $params);
curl_setopt($cSession,CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
//step3
$result = curl_exec($cSession);
if(!$result)
{
die('Error: "' . curl_error($cSession) . '" - Code: ' . curl_errno($cSession));
}
else
{
//echo $result;
$st=explode('/',$result);
//echo '<pre>';
//echo $st[9];
$sessionkey= substr($st[9],0,74);
//echo $sessionkey;
//echo 'hello';
$_SESSION['apikey']=$apikey;
$_SESSION['sessionkey']=$sessionkey;
$session_key=$_SESSION['sessionkey'];
//array_push($arr_names,$session_key);
//$sending_json = json_encode($arr_names);
//echo $sending_json;
}
$header_size = curl_getinfo($cSession, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
//echo $body = substr($response, $header_size);
if (empty($result))
{
// some kind of an error happened
die(curl_error($cSession));
}
else
{
$info = curl_getinfo($cSession);
//curl_close($cSession); // close cURL handler
if (empty($info['http_code']))
{
die("No HTTP code was returned");
}
else
{
// load the HTTP codes
$http_codes = parse_ini_file("info.ini");
// echo results
//echo "The server responded: <br />";
//echo $info['http_code'] . " " . $http_codes[$info['http_code']];
}
}
//code to get prices
$pricedata=' ';
//step1
$ch = curl_init();
//step2
curl_setopt($ch,CURLOPT_URL,"http://partners.api.skyscanner.net/apiservices/pricing/v1.0/".$session_key."?apiKey=".$apikey);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch,CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
//step3
$result = curl_exec($ch);
if(!$result)
{
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
else
{
$myarray=array();
$myarray1=array();
//echo $result;
$st=explode('GMT',$result);
$myarray=json_decode($st[1],true);
//echo '<PRE>';
// print_r($myarray);
// foreach($myarray as $k => $v)
// {
// echo "<br>";
// }
//echo '<pre>';
//print_r($myarray['Itineraries']);
//print_r($myarray);
//$myarray1=$myarray['Itineraries'];
// echo '<pre>';
// print_r($myarray1);
//echo 'here'.$myarray1['PricingOptions'];
//Itineraries
foreach ($myarray['Itineraries'][0]['PricingOptions'] as $Option)
{
$pricedata= $Option['Price'];
array_push($arr_names,$pricedata);
// echo "<b> Agents </b> " .implode(',', $Option['Agents']), " <br> <b>price </b>",$Option['Price'] ,"<br />";
}
$sending_json = json_encode($arr_names);
echo $sending_json;
}
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
//echo $body = substr($response, $header_size);
if (empty($result))
{
// some kind of error happened
die(curl_error($ch));
}
else
{
$info = curl_getinfo($ch);
if (empty($info['http_code']))
{
die("No HTTP code was returned");
}
else
{
// load the HTTP codes
$http_codes = parse_ini_file("info.ini");
// echo results
//echo "The server responded: <br />";
//echo $info['http_code'] . " " . $http_codes[$info['http_code']];
}
}
curl_close($cSession);
curl_close($ch);
?>