-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlib.php
More file actions
41 lines (37 loc) · 1.28 KB
/
lib.php
File metadata and controls
41 lines (37 loc) · 1.28 KB
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
<?php
function getApiUrlByAction($action)
{
global $apiUrl, $accessToken;
return trim($apiUrl, '/') . '/api/' . $action . '.json?access_token='.$accessToken;
}
const REQUEST_GET = false;
const REQUEST_POST = true;
function request($requestUrl, $fields = [], $post = REQUEST_POST) {
$fields = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $requestUrl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 180);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$requestHeaders = array(
'Content-Type: application/x-www-form-urlencoded; ',
'Content-Length: ' . strlen($fields),
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
}
$response = curl_exec($ch);
$result = json_decode($response, true);
if ($result === null) {
$path = __DIR__ . '/error.log';
var_dump($response);
file_put_contents($path, $response);
echo "\nGOT NULL RESULT. Actual response: $path\n";
echo curl_error($ch);
}
curl_close($ch);
return $result;
}