|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// +---------------------------------------------------------------------- |
|
4
|
|
|
// | ThinkLibrary 6.0 for ThinkPhP 6.0 |
|
5
|
|
|
// +---------------------------------------------------------------------- |
|
6
|
|
|
// | 版权所有 2017~2020 [ https://www.dtapp.net ] |
|
7
|
|
|
// +---------------------------------------------------------------------- |
|
8
|
|
|
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary |
|
9
|
|
|
// +---------------------------------------------------------------------- |
|
10
|
|
|
// | 开源协议 ( https://mit-license.org ) |
|
11
|
|
|
// +---------------------------------------------------------------------- |
|
12
|
|
|
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary |
|
13
|
|
|
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary |
|
14
|
|
|
// | gitlab 仓库地址 :https://gitlab.com/liguangchun/thinklibrary |
|
15
|
|
|
// | weixin 仓库地址 :https://git.weixin.qq.com/liguangchun/ThinkLibrary |
|
16
|
|
|
// | huaweicloud 仓库地址 :https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git |
|
17
|
|
|
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library |
|
18
|
|
|
// +---------------------------------------------------------------------- |
|
19
|
|
|
|
|
20
|
|
|
namespace DtApp\ThinkLibrary\service\amap; |
|
21
|
|
|
|
|
22
|
|
|
use DtApp\ThinkLibrary\Service; |
|
23
|
|
|
use DtApp\ThinkLibrary\service\curl\HttpService; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* 高德地图 |
|
27
|
|
|
* https://lbs.amap.com/api/webservice/summary |
|
28
|
|
|
* Class AmApService |
|
29
|
|
|
* @package DtApp\ThinkLibrary\service\amap |
|
30
|
|
|
*/ |
|
31
|
|
|
class AmApService extends Service |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
private $url = "https://restapi.amap.com/v3/"; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private $key = ""; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
private $output = "JSON"; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param string $key |
|
50
|
|
|
* @return $this |
|
51
|
|
|
*/ |
|
52
|
|
|
public function key(string $key): self |
|
53
|
|
|
{ |
|
54
|
|
|
$this->key = $key; |
|
55
|
|
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* 天气查询 |
|
60
|
|
|
* https://lbs.amap.com/api/webservice/guide/api/weatherinfo |
|
61
|
|
|
* @param string $city |
|
62
|
|
|
* @param string $extensions |
|
63
|
|
|
* @return array|bool|mixed|string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function weather($city = "110101", $extensions = "base") |
|
66
|
|
|
{ |
|
67
|
|
|
$data = http_build_query([ |
|
68
|
|
|
"city" => $city, |
|
69
|
|
|
"extensions" => $extensions, |
|
70
|
|
|
"key" => $this->key, |
|
71
|
|
|
"output" => $this->output, |
|
72
|
|
|
]); |
|
73
|
|
|
return HttpService::instance() |
|
74
|
|
|
->url("{$this->url}weather/weatherInfo?{$data}") |
|
75
|
|
|
->toArray(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* 地理编码 |
|
80
|
|
|
* https://lbs.amap.com/api/webservice/guide/api/georegeo#geo |
|
81
|
|
|
* @param $address |
|
82
|
|
|
* @param string $city |
|
83
|
|
|
* @return array|bool|mixed|string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function gCoderGeo($address, $city = '') |
|
86
|
|
|
{ |
|
87
|
|
|
$data = http_build_query([ |
|
88
|
|
|
"city" => $city, |
|
89
|
|
|
"address" => $address, |
|
90
|
|
|
"key" => $this->key, |
|
91
|
|
|
"output" => $this->output, |
|
92
|
|
|
]); |
|
93
|
|
|
return HttpService::instance() |
|
94
|
|
|
->url("{$this->url}geocode/geo?{$data}") |
|
95
|
|
|
->toArray(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* 逆地理编码 |
|
100
|
|
|
* https://lbs.amap.com/api/webservice/guide/api/georegeo#regeo |
|
101
|
|
|
* @param $location |
|
102
|
|
|
* @return array|bool|mixed|string |
|
103
|
|
|
*/ |
|
104
|
|
|
public function gCoderReGeo($location) |
|
105
|
|
|
{ |
|
106
|
|
|
$data = http_build_query([ |
|
107
|
|
|
"location" => $location, |
|
108
|
|
|
"key" => $this->key, |
|
109
|
|
|
"output" => $this->output, |
|
110
|
|
|
]); |
|
111
|
|
|
return HttpService::instance() |
|
112
|
|
|
->url("{$this->url}geocode/regeo?{$data}") |
|
113
|
|
|
->toArray(); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|