[
{
"to_entity_id": <ID ТОВАРА>,
"to_entity_type": "catalog_elements",
"metadata": {
"catalog_id": <ID КАТАЛОГА>,
"quantity": <КОЛИЧЕСТВО>
}
}
]
$.ajax({
url: `/api/v4/leads/${lead_id}/link`,
method: 'POST',
contentType: 'applcation/json',
data: JSON.stringify([
{
"to_entity_id": <ID ТОВАРА>,
"to_entity_type": "catalog_elements",
"metadata": {
"catalog_id": <ID КАТАЛОГА>,
"quantity": <КОЛИЧЕСТВО>
}
])
})
PATCH /api/v4/{entity_type}/{entity_id}
[[{"name":"\u041a\u043e\u043d\u0442\u0430\u043a\u04421","custom_fields_values":[{"field_id":764147,"values":[{"value":"\u0410\u0440\u0430\u0431\u0438\u043a\u0430","enum_id":"1011877"}]}],"id":"22130181"}]]
должно быть {"name":"\u041a\u043e\u043d\u0442\u0430\u043a\u04421","custom_fields_values":[{"field_id":764147,"values":[{"value":"\u0410\u0440\u0430\u0431\u0438\u043a\u0430","enum_id":"1011877"}]}]}
<?php
function getSourceServerInfo(string $ip, string $port): array
{
$info = [
'status' => 0,
'ip' => $ip,
'port' => $port
];
$socket = @fsockopen("udp://{$ip}", $port, $errno, $errstr, 1);
if (!$socket) {
return $info;
}
stream_set_timeout($socket, 1);
stream_set_blocking($socket, true);
fwrite($socket, "\xFF\xFF\xFF\xFF\x54Source Engine Query\x00");
$packet = fread($socket, 4096);
@fclose($socket);
if (!$packet) {
return $info;
}
if (substr($packet, 4, 1) != "I") {
exit("NOT A SOURCE SERVER");
}
$packet_array = explode("\x00", substr($packet, 6), 5);
$info['name'] = $packet_array[0];
$info['map'] = $packet_array[1];
$info['game'] = $packet_array[2];
$info['description'] = $packet_array[3];
$packet = $packet_array[4];
$info['players'] = ord(substr($packet, 2, 1));
$info['playersmax'] = ord(substr($packet, 3, 1));
$info['bots'] = ord(substr($packet, 4, 1));
$info['status'] = 1;
$info['vac'] = ord(substr($packet, 8, 1));
return $info;
}
$query = getSourceServerInfo("51.89.142.229", '27016');
echo '<pre>';
echo print_r($query, 1);
echo '</pre>';
/*
Array
(
[status] => 1
[ip] => 51.89.142.229
[port] => 27016
[name] => PuschiRP [Bitmining] [Printer] [Custom]
[map] => rp_downtown_tits_v2
[game] => garrysmod
[description] => DarkRP
[players] => 12
[playersmax] => 32
[bots] => 0
[vac] => 1
)
*/
var axios = require('axios');
var data = JSON.stringify({
"route": [[37.9271659429, 55.7487291122], [37.943649, 55.799156]], // координаты откуда - куда
"skip_estimated_waiting": true,
"supports_forced_surge": false
});
var config = {
method: 'post',
url: 'https://taxi.yandex.ru/3.0/routestats',
headers: {
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(function (response) {
console.log(`Маршрут составит ${response.data.distance} и займет ${response.data.time}`);
response.data.service_levels.forEach(function (i) {
console.log(`${i.name} - ${i.price}`);
})
})
.catch(function (error) {
console.log(error);
});
/* Output:
Маршрут составит 7,2 км и займет 28 мин
Эконом - 430 руб.
Комфорт - 610 руб.
Комфорт+ - 790 руб.
Business - 1060 руб.
Детский - 710 руб.
Минивэн - 690 руб.
Доставка - 460 руб.
Курьер - 390 руб.
Грузовой - 1000 руб.
*/
<?php
use AmoCRM\Client;
require __DIR__ . '/vendor/autoload.php';
if (isset($_POST['phone'])) {
try {
$subdomain = 'ДОМЕН';
$login = 'ЛОГИН';
$apikey = 'КЛЮЧ';
$amo = new Client($subdomain, $login, $apikey);
$unsorted = $amo->unsorted;
$unsorted['source'] = 'my-site';
$unsorted['source_uid'] = 'uid_source';
$unsorted['source_data'] = [
'data' => [],
'form_id' => 'form_id',
'form_type' => 1,
'date' => time(),
'from' => 'my-site-url',
'form_name' => 'my-site-name',
'origin' => [
'ip' => '127.0.0.1',
'datetime' => '',
'referer' => '',
],
];
$lead = $amo->lead;
$lead['name'] = $_POST['product_name'];
$unsorted->addDataLead($lead);
$contact = $amo->contact;
$contact['name'] = isset($_POST['name']) ? $_POST['name'] : 'Не указано';
$contact->addCustomField(
224429,
[
[$_POST['phone'], 'MOB'],
]
);
$contact->addCustomField(
224431,
[
[$_POST['email'], 'PRIV'],
]
);
$unsorted->addDataContact($contact);
$unsortedId = $unsorted->apiAddForms();
} catch (\AmoCRM\Exception $e) {
var_dump(json_decode($e->getMessage(), 1));
printf('Error (%d): %s' . PHP_EOL, $e->getCode(), $e->getMessage());
}
}
?>
<form method="post" action="call.php">
<div class="form_group">
<p class="input-txt">Имя: <span>*</span></p>
<input type="text" id="name" class="form__input" name="name" required="required">
</div>
<div class="form_group">
<p class="input-txt">Электронная почта: <span>(не обязательно)</span></p>
<input type="email" id="email" class="form__input" name="email" required="required">
</div>
<div class="form_group">
<p class="input-txt">Телефон: <span>*</span></p>
<input type="text" id="phone" class="form__input phone-mask" name="phone" required="required">
</div>
<div>
</div>
<button type="submit" class="btn form-btn">СВЯЗАТЬСЯ</button>
</form>
<?php
$data = $_POST['leads']['update'][0];
$data['custom_fields'] = isset($data['custom_fields']) ? $data['custom_fields'] : array();
$id = $data['id'];
$lead_cf = array();
foreach ($data['custom_fields'] as $custom_field) {
$lead_cf[$custom_field['id']] = $custom_field;
}
if (!isset($lead_cf[514667]) || !isset($lead_cf[514669])) {
exit();
}
$predoplata = intval($lead_cf[514667]['values'][0]['value']);
$postoplata = intval($lead_cf[514669]['values'][0]['value']);
if ($predoplata === 0 || $postoplata === 0) {
exit();
}
$sale = $postoplata + $predoplata;
$prev_sale = isset($lead_cf[514689]) ? intval($lead_cf[514689]['values'][0]['value']) : null;
if ($prev_sale !== $sale) {
$lead = array(
'update' => array(
array(
'id' => $id,
'updated_at' => time(),
'custom_fields' => array(
array(
'id' => 514689,
'values' => array(
array(
'value' => $sale
),
),
),
),
),
),
);
// TODO: SEND TO AMO
}