77 lines
2.6 KiB
PHP
77 lines
2.6 KiB
PHP
|
|
<?
|
||
|
|
|
||
|
|
namespace integration;
|
||
|
|
|
||
|
|
class Dadata {
|
||
|
|
|
||
|
|
static function suggestionsByCord($api,$lat,$lon){
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
if ($ch = \curl_init("https://suggestions.dadata.ru/suggestions/api/4_1/rs/geolocate/address")) {
|
||
|
|
$fields['lat'] = $lat;
|
||
|
|
$fields['lon'] = $lon;
|
||
|
|
|
||
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
|
||
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
|
||
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $h = array(
|
||
|
|
'Content-Type: application/json',
|
||
|
|
'Accept: application/json',
|
||
|
|
'Authorization: Token '.$api
|
||
|
|
));
|
||
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
|
||
|
|
$result = curl_exec($ch);
|
||
|
|
$result = json_decode($result, true);
|
||
|
|
curl_close($ch);
|
||
|
|
$res = $result['suggestions'];
|
||
|
|
}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function getOrg($api,$inn = '',$fields = []){
|
||
|
|
$res = null;
|
||
|
|
if ($ch = \curl_init("http://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/party")) {
|
||
|
|
$fields['query'] = $inn;
|
||
|
|
$fields['count'] = 20;
|
||
|
|
|
||
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||
|
|
'Content-Type: application/json',
|
||
|
|
'Accept: application/json',
|
||
|
|
'Authorization: Token '.$api
|
||
|
|
));
|
||
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
|
||
|
|
$result = curl_exec($ch);
|
||
|
|
$result = json_decode($result, true);
|
||
|
|
curl_close($ch);
|
||
|
|
$res = $result['suggestions'];
|
||
|
|
}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function getAddress($api,$address = '',$fields = []){
|
||
|
|
$res = null;
|
||
|
|
if ($ch = \curl_init("http://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/address")) {
|
||
|
|
$fields['query'] = $address;
|
||
|
|
$fields['count'] = ($c = intval($fields['count']))?$c:20;
|
||
|
|
|
||
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||
|
|
'Content-Type: application/json',
|
||
|
|
'Accept: application/json',
|
||
|
|
'Authorization: Token '.$api
|
||
|
|
));
|
||
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
|
||
|
|
$result = curl_exec($ch);
|
||
|
|
$result = json_decode($result, true);
|
||
|
|
curl_close($ch);
|
||
|
|
$res = $result['suggestions'];
|
||
|
|
}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|