-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathXapoUtil.php
48 lines (40 loc) · 1.14 KB
/
XapoUtil.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
<?php
// payload encryption and service calling function
class XapoUtil {
// payload encryption method
static public function encrypt($value, $key) {
if (!empty($value)) {
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $value, 'ecb'));
} else {
return '';
}
}
// REST API call method
static function callAPI($method, $url, $data = false) {
$curl = curl_init();
switch ($method) {
case "POST":
curl_setopt($curl, CURLOPT_POST, true);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, true);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
if ($result === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
return $result;
}
}
?>