-
-
Save JamesBondsky/e742c84a9abe634950deeb7e8d63bbe5 to your computer and use it in GitHub Desktop.
Bitrix24 integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//<?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