-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcUrls.php
43 lines (42 loc) · 1.49 KB
/
cUrls.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
<?php
include 'pass.php';
global $subdomain;
$subdomain = 'apahe';
function Send_amo($method,$date=null){
global $subdomain;
$link = 'https://' . $subdomain . '.amocrm.ru/api/v2/'.$method;
$cvant = strpos($method,'?') ? '&' : '?';
$link = $link.$cvant.http_build_query( $user);
$curl = curl_init($link);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-API-client/1.0');
curl_setopt($curl, CURLOPT_HEADER, false);
if($date!=null){
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($date));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
}
$out = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$code = (int)$code;
$errors = array(
301 => 'Moved permanently',
400 => 'Bad request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Not found',
500 => 'Internal server error',
502 => 'Bad gateway',
503 => 'Service unavailable'
);
try {
if ($code != 200 && $code != 204) {
throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error', $code);
}
} catch (Exception $E) {
die('Ошибка: ' . $E->getMessage() . PHP_EOL . 'Код ошибки: ' . $E->getCode());
}
global $Response;
$Response = json_decode($out, true);
}