1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the overtrue/wechat. |
5
|
|
|
* |
6
|
|
|
* (c) overtrue <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* POI.php. |
14
|
|
|
* |
15
|
|
|
* @author overtrue <[email protected]> |
16
|
|
|
* @copyright 2015 overtrue <[email protected]> |
17
|
|
|
* |
18
|
|
|
* @see https://github.com/overtrue |
19
|
|
|
* @see http://overtrue.me |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace EasyWeChat\POI; |
23
|
|
|
|
24
|
|
|
use EasyWeChat\Core\AbstractAPI; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class POI. |
28
|
|
|
*/ |
29
|
|
|
class POI extends AbstractAPI |
30
|
|
|
{ |
31
|
|
|
const API_CREATE = 'http://api.weixin.qq.com/cgi-bin/poi/addpoi'; |
32
|
|
|
const API_GET = 'http://api.weixin.qq.com/cgi-bin/poi/getpoi'; |
33
|
|
|
const API_LIST = 'http://api.weixin.qq.com/cgi-bin/poi/getpoilist'; |
34
|
|
|
const API_UPDATE = 'http://api.weixin.qq.com/cgi-bin/poi/updatepoi'; |
35
|
|
|
const API_DELETE = 'http://api.weixin.qq.com/cgi-bin/poi/delpoi'; |
36
|
|
|
const API_GET_CATEGORIES = 'http://api.weixin.qq.com/cgi-bin/poi/getwxcategory'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get POI supported categories. |
40
|
|
|
* |
41
|
|
|
* @return \EasyWeChat\Support\Collection |
42
|
|
|
*/ |
43
|
1 |
|
public function getCategories() |
44
|
|
|
{ |
45
|
1 |
|
return $this->parseJSON('get', [self::API_GET_CATEGORIES]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get POI by ID. |
50
|
|
|
* |
51
|
|
|
* @param int $poiId |
52
|
|
|
* |
53
|
|
|
* @return \EasyWeChat\Support\Collection |
54
|
|
|
*/ |
55
|
1 |
|
public function get($poiId) |
56
|
|
|
{ |
57
|
1 |
|
return $this->parseJSON('json', [self::API_GET, ['poi_id' => $poiId]]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* List POI. |
62
|
|
|
* |
63
|
|
|
* @param int $offset |
64
|
|
|
* @param int $limit |
65
|
|
|
* |
66
|
|
|
* @return \EasyWeChat\Support\Collection |
67
|
|
|
*/ |
68
|
1 |
|
public function lists($offset = 0, $limit = 10) |
69
|
|
|
{ |
70
|
|
|
$params = [ |
71
|
1 |
|
'begin' => $offset, |
72
|
1 |
|
'limit' => $limit, |
73
|
1 |
|
]; |
74
|
|
|
|
75
|
1 |
|
return $this->parseJSON('json', [self::API_LIST, $params]); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Create a POI. |
80
|
|
|
* |
81
|
|
|
* @param array $data |
82
|
|
|
* |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
1 |
|
public function create(array $data) |
86
|
|
|
{ |
87
|
|
|
$params = [ |
88
|
1 |
|
'business' => ['base_info' => $data], |
89
|
1 |
|
]; |
90
|
|
|
|
91
|
1 |
|
return $this->parseJSON('json', [self::API_CREATE, $params]); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Update a POI. |
96
|
|
|
* |
97
|
|
|
* @param int $poiId |
98
|
|
|
* @param array $data |
99
|
|
|
* |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
1 |
|
public function update($poiId, array $data) |
103
|
|
|
{ |
104
|
1 |
|
$data = array_merge($data, ['poi_id' => $poiId]); |
105
|
|
|
|
106
|
|
|
$params = [ |
107
|
1 |
|
'business' => ['base_info' => $data], |
108
|
1 |
|
]; |
109
|
|
|
|
110
|
1 |
|
return $this->parseJSON('json', [self::API_UPDATE, $params]); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Delete a POI. |
115
|
|
|
* |
116
|
|
|
* @param int $poiId |
117
|
|
|
* |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
1 |
|
public function delete($poiId) |
121
|
|
|
{ |
122
|
1 |
|
$params = ['poi_id' => $poiId]; |
123
|
|
|
|
124
|
1 |
|
return $this->parseJSON('json', [self::API_DELETE, $params]); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|