-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSabreConnect.php
116 lines (81 loc) · 3.11 KB
/
SabreConnect.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
<?php
/*
// get access token
//$client_id= base64_encode("V1:user:group:AA");
//$client_id= base64_encode('V1:vfi6yjwxo1nderkk:DEVCENTER:EXT');
$client_id= 'VjE6dmZpNnlqd3hvMW5kZXJrazpERVZDRU5URVI6RVhU';
$client_secret = 'aTRMdEx5TDI=';
//$client_secret = base64_encode('i4LtLyL2=');
//$client_secret = 'aTRMdEx5TDI=';
$token = base64_encode($client_id.":".$client_secret);
$data='grant_type=client_credentials';
*/
if( !class_alias('SabreClass') )
{
class SabreClass()
{
private $_link;
private $_result = array();
private $_ch = nulll
private $_clientID;
private $_secret;
private $taken;
private $data;
public function _construct( $secret, $clientID )
{
$_clientID = ( $clientID != '' ) ? $clientID : '' ;
$_clientID = ( $secret != '' ) ? $secret : '' ;
$token = base64_encode($client_id.":".$client_secret);
$data='grant_type=client_credentials';
}
public function _doConnect( $endpoint=null )
{
$headers = array(
'Authorization: Basic '.$token,
'Accept: */*',
'Content-Type: application/x-www-form-urlencoded'
);
$ch = curl_init();
// curl_setopt($ch,CURLOPT_URL,"https://api.sabre.com/v2/auth/token");
curl_setopt($ch,CURLOPT_URL,"https://api.test.sabre.com/v2/auth/token");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
$resf = json_decode($res);
//echo "Token " . $resf->access_token;
//exit;
$access_token = $resf->access_token; // token provided from sabre
$expires_in_seconds = $resf->expires_in;
$token_type = $resf->token_type;
// // END get access token
$url = 'https://api.test.sabre.com/v1/shop/flights?origin=NYC&destination=LAS&departuredate=2017-07-10&returndate=2017-07-20&onlineitinerariesonly=N&limit=10&offset=1&eticketsonly=Y&sortby=totalfare&order=asc&sortby2=departuretime&order2=asc&pointofsalecountry=US';
$headers2 = array(
'Authorization: bearer '.$access_token,
'protocol: HTTP 1.1 ',
"Content-Type: application/json"
);
$ch2 = curl_init();
curl_setopt($ch2,CURLOPT_HTTPHEADER,$headers2);
curl_setopt($ch2, CURLOPT_URL, $url);
//curl_setopt($ch2, CURLOPT_POST, TRUE);
//curl_setopt($ch2, CURLOPT_POSTFIELDS, $postData);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, FALSE);
//var_dump( $results = json_decode(curl_exec($ch2),true));
//echo $client_secret;
$results = json_decode(curl_exec($ch2),true);
echo '<pre>' . print_r( $results, 1 ) . '</pre>';
}
public function parseResult()
{
}
} // end of classss
} // end of checkdate
$sabre = new SabreClass('aTRMdEx5TDI=', 'VjE6dmZpNnlqd3hvMW5kZXJrazpERVZDRU5URVI6RVhU');
$sabre->_doConnect();
?>