1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Services\Vendor;
- use App\Services\Service;
- use GuzzleHttp\Client;
- class LbsService extends Service
- {
- private $httpClient;
- private $key;
- public function __construct()
- {
- $this->key = config('services.lbs.key');
- $this->httpClient = new Client();
- }
- /**
- * 行政区域查询
- * @param array $parameters
- * @return mixed
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function district(array $parameters)
- {
- $parameters['key'] = $this->key;
- $url = 'https://restapi.amap.com/v3/config/district';
- $response = $this->httpClient->request('GET', $url, [
- 'query' => $parameters,
- ]);
- return json_decode($response->getBody(), true);
- }
- /**
- * IP定位
- * @param array $parameters
- * @return mixed
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function ip(array $parameters)
- {
- $parameters['key'] = $this->key;
- $url = 'https://restapi.amap.com/v3/ip';
- $response = $this->httpClient->request('GET', $url, [
- 'query' => $parameters,
- ]);
- return json_decode($response->getBody(), true);
- }
- /**
- * 地理编码
- * @param array $parameters
- * @return mixed
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function geocode(array $parameters)
- {
- $parameters['key'] = $this->key;
- $url = 'https://restapi.amap.com/v3/geocode/geo';
- $response = $this->httpClient->request('GET', $url, [
- 'query' => $parameters,
- ]);
- return json_decode($response->getBody(), true);
- }
- /**
- * 逆地理编码
- * @param array $parameters
- * @return mixed
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function reGeocode(array $parameters)
- {
- $parameters['key'] = $this->key;
- $url = 'https://restapi.amap.com/v3/geocode/regeo';
- $response = $this->httpClient->request('GET', $url, [
- 'query' => $parameters,
- ]);
- return json_decode($response->getBody(), true);
- }
- }
|