|
|
@ -19,7 +19,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace DtApp\ThinkLibrary\service\amap;
|
|
|
|
namespace DtApp\ThinkLibrary\service\amap;
|
|
|
|
|
|
|
|
|
|
|
|
use DtApp\ThinkLibrary\exception\DtaException;
|
|
|
|
|
|
|
|
use DtApp\ThinkLibrary\Service;
|
|
|
|
use DtApp\ThinkLibrary\Service;
|
|
|
|
use DtApp\ThinkLibrary\service\curl\HttpService;
|
|
|
|
use DtApp\ThinkLibrary\service\curl\HttpService;
|
|
|
|
|
|
|
|
|
|
|
@ -50,38 +49,21 @@ class AmApService extends Service
|
|
|
|
* @param string $key
|
|
|
|
* @param string $key
|
|
|
|
* @return $this
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function key(string $key)
|
|
|
|
public function key(string $key): self
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->key = $key;
|
|
|
|
$this->key = $key;
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取配置信息
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private function getConfig(): self
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->key = config('dtapp.amap.key');
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 天气查询
|
|
|
|
* 天气查询
|
|
|
|
* https://lbs.amap.com/api/webservice/guide/api/weatherinfo
|
|
|
|
* https://lbs.amap.com/api/webservice/guide/api/weatherinfo
|
|
|
|
* @param string $city
|
|
|
|
* @param string $city
|
|
|
|
* @param string $extensions
|
|
|
|
* @param string $extensions
|
|
|
|
* @return array|bool|mixed|string
|
|
|
|
* @return array|bool|mixed|string
|
|
|
|
* @throws DtaException
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function weather($city = "110101", $extensions = "base")
|
|
|
|
public function weather($city = "110101", $extensions = "base")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (empty($this->key)) {
|
|
|
|
|
|
|
|
$this->getConfig();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->key)) {
|
|
|
|
|
|
|
|
throw new DtaException('请检查key参数');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = http_build_query([
|
|
|
|
$data = http_build_query([
|
|
|
|
"city" => $city,
|
|
|
|
"city" => $city,
|
|
|
|
"extensions" => $extensions,
|
|
|
|
"extensions" => $extensions,
|
|
|
@ -92,4 +74,42 @@ class AmApService extends Service
|
|
|
|
->url("{$this->url}weather/weatherInfo?{$data}")
|
|
|
|
->url("{$this->url}weather/weatherInfo?{$data}")
|
|
|
|
->toArray();
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 地理编码
|
|
|
|
|
|
|
|
* https://lbs.amap.com/api/webservice/guide/api/georegeo#geo
|
|
|
|
|
|
|
|
* @param $address
|
|
|
|
|
|
|
|
* @param string $city
|
|
|
|
|
|
|
|
* @return array|bool|mixed|string
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function gCoderGeo($address, $city = '')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$data = http_build_query([
|
|
|
|
|
|
|
|
"city" => $city,
|
|
|
|
|
|
|
|
"address" => $address,
|
|
|
|
|
|
|
|
"key" => $this->key,
|
|
|
|
|
|
|
|
"output" => $this->output,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
return HttpService::instance()
|
|
|
|
|
|
|
|
->url("{$this->url}geocode/geo?{$data}")
|
|
|
|
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 逆地理编码
|
|
|
|
|
|
|
|
* https://lbs.amap.com/api/webservice/guide/api/georegeo#regeo
|
|
|
|
|
|
|
|
* @param $location
|
|
|
|
|
|
|
|
* @return array|bool|mixed|string
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function gCoderReGeo($location)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$data = http_build_query([
|
|
|
|
|
|
|
|
"location" => $location,
|
|
|
|
|
|
|
|
"key" => $this->key,
|
|
|
|
|
|
|
|
"output" => $this->output,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
return HttpService::instance()
|
|
|
|
|
|
|
|
->url("{$this->url}geocode/regeo?{$data}")
|
|
|
|
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|