Skip to content

Instantly share code, notes, and snippets.

@mnoskov
Created July 2, 2019 05:02
Show Gist options
  • Save mnoskov/0ba64d30be0835d658971ac2905371f4 to your computer and use it in GitHub Desktop.
Save mnoskov/0ba64d30be0835d658971ac2905371f4 to your computer and use it in GitHub Desktop.
Bitrix24 integration
//<?php
/**
* Bitrix24
*
* Интеграция с Битрикс24 - создание лидов
*
* @category snippet
* @version 0.1
* @internal @properties &url=URL;text; &user_id=Assigned user ID;text;
* @internal @installset sample
*/
if (empty($params['url'])) {
$modx->logEvent(0, 3, 'URL empty!', 'Bitrix24');
}
$url = rtrim($params['url'], '/') . '/crm.lead.add';
$request = [
'TITLE' => 'Заявка с сайта ' . $_SERVER['HTTP_HOST'],
'SOURCE_ID' => 'WEB',
'STATUS_ID' => 'NEW',
];
if (!empty($params['user_id']) && is_numeric($params['user_id'])) {
$request['ASSIGNED_BY_ID'] = $params['user_id'];
}
if (!empty($data['name'])) {
$request['NAME'] = $data['name'];
}
foreach (['phone' => 'PHONE', 'email' => 'EMAIL'] as $field => $param) {
if (!empty($data[$field])) {
$request[$param] = [[
'VALUE' => $data[$field],
'VALUE_TYPE' => 'WORK',
]];
}
}
$query = http_build_query(['fields' => $request]);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $query);
curl_setopt($curl, CURLOPT_POST, 1);
$response = curl_exec($curl);
$error = curl_error($curl);
if (!empty($error)) {
$response = 'Ошибка: ' . print_r($error, true);
}
curl_close($curl);
$modx->logEvent(0, 1, 'Ответ сервера: ' . $response, 'Bitrix24');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment