100 lines
3.0 KiB
PHP
100 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class BitrixSender
|
|
{
|
|
private $IBLOCK_TYPE_ID = 'lists';
|
|
|
|
//CONFIG для Альфы
|
|
|
|
private $URL = 'https://b24alfa.pro/rest/3165/v90a792nderzu0dj/lists.element.add.json';
|
|
private $IBLOCK_ID = 27;
|
|
private $ID;
|
|
const CLIENT_SECOND_NAME = "PROPERTY_94";
|
|
const CLIENT_FIRST_NAME = "PROPERTY_95";
|
|
const CLIENT_PHONE = "PROPERTY_96";
|
|
const BROKER_SECOND_NAME = "PROPERTY_97";
|
|
const BROKER_FIRST_NAME = "PROPERTY_98";
|
|
const BROKER_PHONE = "PROPERTY_99";
|
|
const OBJECT_NAME = "PROPERTY_100";
|
|
const CALLBACK_URL = "PROPERTY_105";
|
|
|
|
//CONFIG для VSSDOM
|
|
/*
|
|
private $URL = 'https://crm.vssdom.ru/rest/8802/diju1sn3w7rbuhmm/lists.element.add.json';
|
|
private $IBLOCK_ID = 52;
|
|
const CLIENT_SECOND_NAME = "PROPERTY_118";
|
|
const CLIENT_FIRST_NAME = "PROPERTY_119";
|
|
const CLIENT_PHONE = "PROPERTY_120";
|
|
const BROKER_SECOND_NAME = "PROPERTY_121";
|
|
const BROKER_FIRST_NAME = "PROPERTY_122";
|
|
const BROKER_PHONE = "PROPERTY_123";
|
|
const OBJECT_NAME = "PROPERTY_124";
|
|
const CALLBACK_URL = "PROPERTY_128";
|
|
*/
|
|
private $data = [];
|
|
|
|
public function __construct($id, $data) {
|
|
$this->ID = $id;
|
|
$data = array_change_key_case($data, CASE_UPPER);
|
|
$finalData = [];
|
|
$refl = new \ReflectionClass(__CLASS__);
|
|
$constants = $refl->getConstants();
|
|
foreach ( $constants as $constName => $constValue )
|
|
{
|
|
foreach ($data as $key => $value)
|
|
{
|
|
if ( $constName == $key ) {
|
|
$finalData[$constValue] = $value;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$finalData['NAME'] = $finalData[self::CLIENT_FIRST_NAME] . ' ' . $finalData[self::CLIENT_SECOND_NAME];
|
|
$this->data = $finalData;
|
|
return;
|
|
}
|
|
|
|
public function send() {
|
|
$postdata = http_build_query(
|
|
[
|
|
'IBLOCK_TYPE_ID' => $this->IBLOCK_TYPE_ID,
|
|
'IBLOCK_ID' => $this->IBLOCK_ID,
|
|
'ELEMENT_CODE' => $this->ID,
|
|
'FIELDS' => $this->data
|
|
]
|
|
);
|
|
|
|
$opts = array(
|
|
'ssl' => array(
|
|
'verify_peer' => false,
|
|
'verify_peername' => false
|
|
),
|
|
'http' => array(
|
|
'method' => 'POST',
|
|
'header' =>
|
|
'Content-type: application/x-www-form-urlencoded'."\r\n".
|
|
'',
|
|
'content' => $postdata
|
|
)
|
|
);
|
|
return true;
|
|
try {
|
|
$context = stream_context_create($opts);
|
|
$result = file_get_contents($this->URL, false, $context);
|
|
$result = json_decode($result, $associative = true);
|
|
if (array_key_exists('result', $result)) {
|
|
return $result['result'];
|
|
} else {
|
|
return false;
|
|
}
|
|
} catch (\Exception $e) {
|
|
dd($e);
|
|
return false;
|
|
}
|
|
}
|
|
}
|