Накидал на скорую руку, надеюсь дырку не закроют
[CODE]$login = "******";
$pass = "******";
$url_b24 = "******.bitrix24.ru";
$client_id = "******"; //APP ID
$client_secret = "******";
/*Авторизуемся на портале*/
curl_b24("https://{$url_b24}/crm/configs/import/lead.php?LOGIN=" . urlencode($login) . "&PASSWORD=" . urlencode($pass));
/*Поулчение токена доступа*/
$auth_url = curl_b24("https://{$url_b24}/oauth/authorize/?client_id=" . $client_id, true);
if (preg_match("/\?(.*?)$/i", $auth_url, $arRes)) {
parse_str($arRes[1]);
if ($code != "") {
$res = json_decode(curl_b24("https://oauth.bitrix.info/oauth/token/?grant_type=authorization_code&client_id={$client_id}&client_secret={$client_secret}&code={$code}"));
if ($res->access_token != "") {
$access_token = $res->access_token;
} else {
echo "Error: Not set access_token";
die();
}
} else {
echo "Error: Not set user code";
die();
}
}
/*Получаем список заказов*/
$res = curl_b24("https://{$url_b24}/rest/crm.deal.list.json?auth={$access_token}");
var_dump(json_decode($res));
function curl_b24($data, $header = false) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_COOKIEFILE, __DIR__ . "/cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, __DIR__ . "/cookie.txt");
$result = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\n/', $result, $matches);
$newurl = trim(array_pop($matches));
return $newurl;
}
curl_close($ch);
return $result;
}
[/CODE]