Joywork/ajax/getDadataAddress.php

43 lines
1018 B
PHP
Raw Normal View History

2026-05-22 20:21:54 +02:00
<?php
namespace Dadata;
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
if (isset($_POST['searchTerm'])) {
$search = $_POST['searchTerm'];// Search text
}
if (isset($_POST['page'])) {
$page = $_POST['page'];
}
$options = array(
'http' => array(
'method' => 'POST',
'header' => array(
'Content-type: application/json',
'Authorization: Token ' . $dadataToken,
'X-Secret: ' . $dadataSecret,
),
'content' => json_encode(array(
$search
)),
),
);
$context = stream_context_create($options);
$results = file_get_contents("https://cleaner.dadata.ru/api/v1/clean/address", false, $context);
$response = [];
$response['items'] = array();
// Read Data
foreach (json_decode($results) as $k => $result) {
$response['items'][] = array(
"id" => (string) $k,
"text" => $result->result
);
}
echo json_encode($response);
exit();