-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponsible.php
63 lines (61 loc) · 2.76 KB
/
responsible.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
#Ěŕńńčâ ń ďŕđŕěĺňđŕěč, ęîňîđűĺ íóćíî ďĺđĺäŕňü ěĺňîäîě POST ę API ńčńňĺěű
$user = array(
'USER_LOGIN' => '[email protected]', #Âŕř ëîăčí (ýëĺęňđîííŕ˙ ďî÷ňŕ)
'USER_HASH' => '7ebefd1d4741106a4daa0e0a673bba2e4dc16054', #Őýř äë˙ äîńňóďŕ ę API (ńěîňđčňĺ â ďđîôčëĺ ďîëüçîâŕňĺë˙)
);
$subdomain = 'test'; #Íŕř ŕęęŕóíň - ďîääîěĺí
#Ôîđěčđóĺě ńńűëęó äë˙ çŕďđîńŕ
$link = 'https://' . $subdomain . '.amocrm.ru/private/api/auth.php?type=json';
/* Íŕě íĺîáőîäčěî číčöččđîâŕňü çŕďđîń ę ńĺđâĺđó. Âîńďîëüçóĺěń˙ áčáëčîňĺęîé cURL (ďîńňŕâë˙ĺňń˙ â ńîńňŕâĺ PHP). Âű ňŕęćĺ
ěîćĺňĺ
čńďîëüçîâŕňü č ęđîńńďëŕňôîđěĺííóţ ďđîăđŕěěó cURL, ĺńëč âű íĺ ďđîăđŕěěčđóĺňĺ íŕ PHP. */
$curl = curl_init(); #Ńîőđŕí˙ĺě äĺńęđčďňîđ ńĺŕíńŕ cURL
#Óńňŕíŕâëčâŕĺě íĺîáőîäčěűĺ îďöčč äë˙ ńĺŕíńŕ cURL
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-API-client/1.0');
curl_setopt($curl, CURLOPT_URL, $link);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($user));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_COOKIEFILE, dirname
(__FILE__) . '/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
curl_setopt($curl, CURLOPT_COOKIEJAR, dirname
(__FILE__) . '/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$out = curl_exec($curl); #Číčöččđóĺě çŕďđîń ę API č ńîőđŕí˙ĺě îňâĺň â ďĺđĺěĺííóţ
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); #Ďîëó÷čě HTTP-ęîä îňâĺňŕ ńĺđâĺđŕ
curl_close($curl); #Çŕâĺđřŕĺě ńĺŕíń 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
{
#Ĺńëč ęîä îňâĺňŕ íĺ đŕâĺí 200 čëč 204 - âîçâđŕůŕĺě ńîîáůĺíčĺ îá îřčáęĺ
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());
}
/*
Äŕííűĺ ďîëó÷ŕĺě â ôîđěŕňĺ JSON, ďîýňîěó, äë˙ ďîëó÷ĺíč˙ ÷čňŕĺěűő äŕííűő,
íŕě ďđčä¸ňń˙ ďĺđĺâĺńňč îňâĺň â ôîđěŕň, ďîí˙ňíűé PHP
*/
$Response = json_decode($out, true);
$Response = $Response['response'];
if (isset($Response['auth'])) #Ôëŕă ŕâňîđčçŕöčč äîńňóďĺí â ńâîéńňâĺ "auth"
{
return 'Ŕâňîđčçŕöč˙ ďđîřëŕ óńďĺříî';
}
return 'Ŕâňîđčçŕöč˙ íĺ óäŕëŕńü';