|
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\baidu; |
|
21
|
|
|
|
|
22
|
|
|
use DtApp\ThinkLibrary\exception\DtaException; |
|
23
|
|
|
use DtApp\ThinkLibrary\Service; |
|
24
|
|
|
use DtApp\ThinkLibrary\service\curl\HttpService; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* 百度地图 |
|
28
|
|
|
* http://lbsyun.baidu.com/index.php?title=webapi |
|
29
|
|
|
* Class LbsYunService |
|
30
|
|
|
* @package DtApp\ThinkLibrary\service\baidu |
|
31
|
|
|
*/ |
|
32
|
|
|
class LbsYunService extends Service |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
private $ak = ""; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
private $output = "json"; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param string $ak |
|
46
|
|
|
* @return $this |
|
47
|
|
|
*/ |
|
48
|
|
|
public function ak(string $ak): self |
|
49
|
|
|
{ |
|
50
|
|
|
$this->ak = $ak; |
|
51
|
|
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* 国内天气查询 |
|
56
|
|
|
* http://lbsyun.baidu.com/index.php?title=webapi/weather |
|
57
|
|
|
* @param int $district_id |
|
58
|
|
|
* @param string $coordtype |
|
59
|
|
|
* @param string $location |
|
60
|
|
|
* @return array|bool|mixed|string |
|
61
|
|
|
* @throws DtaException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "") |
|
64
|
|
|
{ |
|
65
|
|
|
if (empty($this->ak)) { |
|
66
|
|
|
throw new DtaException('请检查ak参数'); |
|
67
|
|
|
} |
|
68
|
|
|
$data = http_build_query([ |
|
69
|
|
|
"district_id" => $district_id, |
|
70
|
|
|
"coordtype" => $coordtype, |
|
71
|
|
|
"ak" => $this->ak, |
|
72
|
|
|
"location" => $location, |
|
73
|
|
|
"data_type" => 'all', |
|
74
|
|
|
"output" => $this->output, |
|
75
|
|
|
]); |
|
76
|
|
|
return HttpService::instance() |
|
77
|
|
|
->url("http://api.map.baidu.com/weather/v1/?{$data}") |
|
78
|
|
|
->toArray(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* 国外天气查询 |
|
83
|
|
|
* http://lbsyun.baidu.com/index.php?title=webapi/weather-abroad |
|
84
|
|
|
* @param int $district_id |
|
85
|
|
|
* @param string $coordtype |
|
86
|
|
|
* @param string $location |
|
87
|
|
|
* @param string $language |
|
88
|
|
|
* @return array|bool|mixed|string |
|
89
|
|
|
* @throws DtaException |
|
90
|
|
|
*/ |
|
91
|
|
|
public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn") |
|
92
|
|
|
{ |
|
93
|
|
|
if (empty($this->ak)) { |
|
94
|
|
|
throw new DtaException('请检查ak参数'); |
|
95
|
|
|
} |
|
96
|
|
|
$data = http_build_query([ |
|
97
|
|
|
"district_id" => $district_id, |
|
98
|
|
|
"coordtype" => $coordtype, |
|
99
|
|
|
"ak" => $this->ak, |
|
100
|
|
|
"location" => $location, |
|
101
|
|
|
"data_type" => 'all', |
|
102
|
|
|
"language" => $language, |
|
103
|
|
|
"output" => $this->output, |
|
104
|
|
|
]); |
|
105
|
|
|
return HttpService::instance() |
|
106
|
|
|
->url("http://api.map.baidu.com/weather_abroad/v1/?{$data}") |
|
107
|
|
|
->toArray(); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|