1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Promopult\Dadata\Services; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Suggestions |
9
|
|
|
* |
10
|
|
|
* https://dadata.ru/api/#suggest |
11
|
|
|
*/ |
12
|
|
|
final class Suggestions extends \Promopult\Dadata\Service |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Организация по ИНН или ОГРН |
16
|
|
|
* |
17
|
|
|
* @param string $query |
18
|
|
|
* @return array |
19
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
20
|
|
|
* |
21
|
|
|
* @see https://dadata.ru/api/find-party/ |
22
|
|
|
*/ |
23
|
|
|
public function partyFindById(string $query): array |
24
|
|
|
{ |
25
|
|
|
$request = $this->requestFactory->createRequest( |
26
|
|
|
'POST', |
27
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/party', |
28
|
|
|
['query' => $query] |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
$response = $this->httpClient->sendRequest($request); |
32
|
|
|
|
33
|
|
|
return \json_decode($response->getBody()->getContents(), true); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Поиск аффилированных компаний |
38
|
|
|
* |
39
|
|
|
* @param string $query |
40
|
|
|
* @return array |
41
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
42
|
|
|
* |
43
|
|
|
* @see https://dadata.ru/api/find-affiliated/ |
44
|
|
|
*/ |
45
|
|
|
public function partyFindAffiliated(string $query): array |
46
|
|
|
{ |
47
|
|
|
$request = $this->requestFactory->createRequest( |
48
|
|
|
'POST', |
49
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findAffiliated/party', |
50
|
|
|
['query' => $query] |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$response = $this->httpClient->sendRequest($request); |
54
|
|
|
|
55
|
|
|
return \json_decode($response->getBody()->getContents(), true); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* API подсказок по организациям |
60
|
|
|
* |
61
|
|
|
* @param string $query ИНН или ОГРН |
62
|
|
|
* @return array |
63
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
64
|
|
|
* |
65
|
|
|
* @see https://dadata.ru/api/suggest/party/ |
66
|
|
|
*/ |
67
|
|
|
public function partySuggest(string $query): array |
68
|
|
|
{ |
69
|
|
|
return $this->suggest( |
70
|
|
|
['query' => $query], |
71
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/party' |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* API подсказок по банкам |
77
|
|
|
* |
78
|
|
|
* @param string $query |
79
|
|
|
* @param int|null $count Количество результатов (максимум — 20) |
80
|
|
|
* @param array|null $locationsBoost Приоритет города при ранжировании ([..["kladr_id":"6100000100000"], ...]) |
81
|
|
|
* @param array|null $locations Ограничение по региону или городу ([..["kladr_id":"6100000100000"], ...]) |
82
|
|
|
* @param string|null $status Ограничение по статусу банка (ACTIVE | LIQUIDATING | LIQUIDATED) |
83
|
|
|
* @param string|null $type Ограничение по типу банка (BANK | NKO | BANK_BRANCH | NKO_BRANCH | RKC | OTHER) |
84
|
|
|
* @return array |
85
|
|
|
* |
86
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
87
|
|
|
* |
88
|
|
|
* @see https://dadata.ru/api/suggest/bank/ |
89
|
|
|
*/ |
90
|
|
|
public function bankSuggest( |
91
|
|
|
string $query, |
92
|
|
|
?int $count = null, |
93
|
|
|
?array $locationsBoost = null, |
94
|
|
|
?array $locations = null, |
95
|
|
|
?string $status = null, |
96
|
|
|
?string $type = null |
97
|
|
|
): array { |
98
|
|
|
return $this->suggest( |
99
|
|
|
array_filter([ |
100
|
|
|
'query' => $query, |
101
|
|
|
'count' => $count, |
102
|
|
|
'status' => $status, |
103
|
|
|
'type' => $type, |
104
|
|
|
'locations' => $locations, |
105
|
|
|
'locations_boost' => $locationsBoost, |
106
|
|
|
]), |
107
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/bank' |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Банк по БИК, SWIFT, ИНН или регистрационному номеру |
113
|
|
|
* |
114
|
|
|
* @param string $query |
115
|
|
|
* @param string|null $kpp |
116
|
|
|
* @return array |
117
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
118
|
|
|
* |
119
|
|
|
* @see https://dadata.ru/api/find-bank/ |
120
|
|
|
*/ |
121
|
|
|
public function bankFindById(string $query, string $kpp = null): array |
122
|
|
|
{ |
123
|
|
|
return $this->suggest(array_filter([ |
124
|
|
|
'query' => $query, |
125
|
|
|
'kpp' => $kpp |
126
|
|
|
]), 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/bank'); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Обратное геокодирование (адрес по координатам) |
131
|
|
|
* |
132
|
|
|
* @param string $lat |
133
|
|
|
* @param string $lon |
134
|
|
|
* @param int|null $count |
135
|
|
|
* @param int|null $radiusMeters |
136
|
|
|
* @param string|null $language |
137
|
|
|
* @return array |
138
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
139
|
|
|
* |
140
|
|
|
* @see https://dadata.ru/api/geolocate/ |
141
|
|
|
*/ |
142
|
|
|
public function addressGeolocate( |
143
|
|
|
string $lat, |
144
|
|
|
string $lon, |
145
|
|
|
?int $count = null, |
146
|
|
|
?int $radiusMeters = null, |
147
|
|
|
?string $language = null |
148
|
|
|
): array { |
149
|
|
|
return $this->suggest( |
150
|
|
|
array_filter([ |
151
|
|
|
'lat' => $lat, |
152
|
|
|
'lon' => $lon, |
153
|
|
|
'count' => $count, |
154
|
|
|
'radius_meters' => $radiusMeters, |
155
|
|
|
'language' => $language |
156
|
|
|
]), |
157
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/geolocate/address' |
158
|
|
|
); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Адрес по коду КЛАДР или ФИАС |
163
|
|
|
* |
164
|
|
|
* @param string $query |
165
|
|
|
* @param int|null $count |
166
|
|
|
* @param string|null $language |
167
|
|
|
* @param array|null $filters |
168
|
|
|
* @return array |
169
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
170
|
|
|
* |
171
|
|
|
* @see https://dadata.ru/api/find-address/ |
172
|
|
|
*/ |
173
|
|
|
public function addressFindById( |
174
|
|
|
string $query, |
175
|
|
|
?int $count = null, |
176
|
|
|
?string $language = null, |
177
|
|
|
?array $filters = null |
178
|
|
|
): array { |
179
|
|
|
return $this->suggest( |
180
|
|
|
array_filter([ |
181
|
|
|
'query' => $query, |
182
|
|
|
'count' => $count, |
183
|
|
|
'language' => $language, |
184
|
|
|
'filters' => $filters, |
185
|
|
|
]), |
186
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/address' |
187
|
|
|
); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Отделения Почты России по геолокации |
192
|
|
|
* |
193
|
|
|
* @param string $lat |
194
|
|
|
* @param string $lon |
195
|
|
|
* @param int|null $count |
196
|
|
|
* @param int|null $radiusMeters |
197
|
|
|
* @param array|null $filters |
198
|
|
|
* @return array |
199
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
200
|
|
|
* |
201
|
|
|
* @see https://dadata.ru/api/suggest/postal_unit/ |
202
|
|
|
*/ |
203
|
|
|
public function postalUnitGeolocate( |
204
|
|
|
string $lat, |
205
|
|
|
string $lon, |
206
|
|
|
?int $count = null, |
207
|
|
|
?int $radiusMeters = null, |
208
|
|
|
?array $filters = null |
209
|
|
|
): array { |
210
|
|
|
return $this->suggest( |
211
|
|
|
array_filter([ |
212
|
|
|
'lat' => $lat, |
213
|
|
|
'lon' => $lon, |
214
|
|
|
'count' => $count, |
215
|
|
|
'radius_meters' => $radiusMeters, |
216
|
|
|
'filters' => $filters, |
217
|
|
|
]), |
218
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/geolocate/postal_unit' |
219
|
|
|
); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Отделения Почты России по адресу и индексу |
224
|
|
|
* |
225
|
|
|
* @param string $query |
226
|
|
|
* @param int|null $count |
227
|
|
|
* @param array|null $filters |
228
|
|
|
* @return array |
229
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
230
|
|
|
* |
231
|
|
|
* @see https://dadata.ru/api/suggest/postal_unit/ |
232
|
|
|
*/ |
233
|
|
|
public function postalUnitSuggest( |
234
|
|
|
string $query, |
235
|
|
|
?int $count = null, |
236
|
|
|
?array $filters = null |
237
|
|
|
): array { |
238
|
|
|
return $this->suggest( |
239
|
|
|
array_filter([ |
240
|
|
|
'query' => $query, |
241
|
|
|
'count' => $count, |
242
|
|
|
'filters' => $filters |
243
|
|
|
]), |
244
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/postal_unit' |
245
|
|
|
); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Город по IP-адресу |
250
|
|
|
* |
251
|
|
|
* @param string $query |
252
|
|
|
* @param int|null $count |
253
|
|
|
* @param string|null $language |
254
|
|
|
* @return array |
255
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
256
|
|
|
* |
257
|
|
|
* @see https://dadata.ru/api/iplocate/ |
258
|
|
|
*/ |
259
|
|
|
public function cityIplocate( |
260
|
|
|
string $query, |
261
|
|
|
?int $count = null, |
262
|
|
|
?string $language = null |
263
|
|
|
): array { |
264
|
|
|
return $this->suggest( |
265
|
|
|
array_filter([ |
266
|
|
|
'query' => $query, |
267
|
|
|
'count' => $count, |
268
|
|
|
'language' => $language |
269
|
|
|
]), |
270
|
|
|
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/iplocate/address' |
271
|
|
|
); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Идентификатор города в СДЭК, Boxberry и DPD |
276
|
|
|
* |
277
|
|
|
* @param string $query |
278
|
|
|
* @return array |
279
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
280
|
|
|
* |
281
|
|
|
* @see https://dadata.ru/api/delivery/ |
282
|
|
|
*/ |
283
|
|
|
public function deliveryFindById( |
284
|
|
|
string $query |
285
|
|
|
): array { |
286
|
|
|
return $this->suggest([ |
287
|
|
|
'query' => $query |
288
|
|
|
], 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/delivery'); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @param array $args |
293
|
|
|
* @param string $uri |
294
|
|
|
* @return mixed |
295
|
|
|
* @throws \Psr\Http\Client\ClientExceptionInterface |
296
|
|
|
*/ |
297
|
|
|
private function suggest(array $args, string $uri) |
298
|
|
|
{ |
299
|
|
|
$request = $this->requestFactory->createRequest('POST', $uri, $args); |
300
|
|
|
|
301
|
|
|
$response = $this->httpClient->sendRequest($request); |
302
|
|
|
|
303
|
|
|
return \json_decode($response->getBody()->getContents(), true); |
304
|
|
|
} |
305
|
|
|
} |
306
|
|
|
|