|
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
|
|
|
* Page.php. |
|
14
|
|
|
* |
|
15
|
|
|
* @author allen05ren <[email protected]> |
|
16
|
|
|
* @copyright 2016 overtrue <[email protected]> |
|
17
|
|
|
* |
|
18
|
|
|
* @link https://github.com/overtrue |
|
19
|
|
|
* @link http://overtrue.me |
|
20
|
|
|
*/ |
|
21
|
|
|
namespace EasyWeChat\ShakeAround; |
|
22
|
|
|
|
|
23
|
|
|
use EasyWeChat\Core\AbstractAPI; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class Page. |
|
27
|
|
|
*/ |
|
28
|
|
|
class Page extends AbstractAPI |
|
29
|
|
|
{ |
|
30
|
|
|
const API_ADD = 'https://api.weixin.qq.com/shakearound/page/add'; |
|
31
|
|
|
const API_UPDATE = 'https://api.weixin.qq.com/shakearound/page/update'; |
|
32
|
|
|
const API_SEARCH = 'https://api.weixin.qq.com/shakearound/page/search'; |
|
33
|
|
|
const API_DELETE = 'https://api.weixin.qq.com/shakearound/page/delete'; |
|
34
|
|
|
const API_RELATION_SEARCH = 'https://api.weixin.qq.com/shakearound/relation/search'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Add a page. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $title |
|
40
|
|
|
* @param string $description |
|
41
|
|
|
* @param string $page_url |
|
42
|
|
|
* @param string $icon_url |
|
43
|
|
|
* @param string $comment |
|
44
|
|
|
* |
|
45
|
|
|
* @return \EasyWeChat\Support\Collection |
|
46
|
|
|
*/ |
|
47
|
|
View Code Duplication |
public function add($title, $description, $page_url, $icon_url, $comment = '') |
|
48
|
|
|
{ |
|
49
|
|
|
$params = [ |
|
50
|
|
|
'title' => $title, |
|
51
|
|
|
'description' => $description, |
|
52
|
|
|
'page_url' => $page_url, |
|
53
|
|
|
'icon_url' => $icon_url, |
|
54
|
|
|
]; |
|
55
|
|
|
if ($comment !== '') { |
|
56
|
|
|
$params['comment'] = $comment; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $this->parseJSON('json', [self::API_ADD, $params]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* update a page info. |
|
64
|
|
|
* |
|
65
|
|
|
* @param int $page_id |
|
66
|
|
|
* @param string $title |
|
67
|
|
|
* @param string $description |
|
68
|
|
|
* @param string $page_url |
|
69
|
|
|
* @param string $icon_url |
|
70
|
|
|
* @param string $comment |
|
71
|
|
|
* |
|
72
|
|
|
* @return \EasyWeChat\Support\Collection |
|
73
|
|
|
*/ |
|
74
|
|
View Code Duplication |
public function update($page_id, $title, $description, $page_url, $icon_url, $comment = '') |
|
75
|
|
|
{ |
|
76
|
|
|
$params = [ |
|
77
|
|
|
'page_id' => intval($page_id), |
|
78
|
|
|
'title' => $title, |
|
79
|
|
|
'description' => $description, |
|
80
|
|
|
'page_url' => $page_url, |
|
81
|
|
|
'icon_url' => $icon_url, |
|
82
|
|
|
]; |
|
83
|
|
|
if ($comment !== '') { |
|
84
|
|
|
$params['comment'] = $comment; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $this->parseJSON('json', [self::API_UPDATE, $params]); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Fetch batch of pages by page_ids. |
|
92
|
|
|
* |
|
93
|
|
|
* @param array $page_ids |
|
94
|
|
|
* |
|
95
|
|
|
* @return \EasyWeChat\Support\Collection |
|
96
|
|
|
*/ |
|
97
|
|
View Code Duplication |
public function fetchByIds(array $page_ids) |
|
98
|
|
|
{ |
|
99
|
|
|
$params = [ |
|
100
|
|
|
'type' => 1, |
|
101
|
|
|
'page_ids' => $page_ids, |
|
102
|
|
|
]; |
|
103
|
|
|
|
|
104
|
|
|
return $this->parseJSON('json', [self::API_SEARCH, $params]); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Pagination to fetch batch of pages. |
|
109
|
|
|
* |
|
110
|
|
|
* @param int $begin |
|
111
|
|
|
* @param int $count |
|
112
|
|
|
* |
|
113
|
|
|
* @return \EasyWeChat\Support\Collection |
|
114
|
|
|
*/ |
|
115
|
|
|
public function pagination($begin, $count) |
|
116
|
|
|
{ |
|
117
|
|
|
$params = [ |
|
118
|
|
|
'type' => 2, |
|
119
|
|
|
'begin' => intval($begin), |
|
120
|
|
|
'count' => intval($count), |
|
121
|
|
|
]; |
|
122
|
|
|
|
|
123
|
|
|
return $this->parseJSON('json', [self::API_SEARCH, $params]); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* delete a page. |
|
128
|
|
|
* |
|
129
|
|
|
* @param int $page_id |
|
130
|
|
|
* |
|
131
|
|
|
* @return \EasyWeChat\Support\Collection |
|
132
|
|
|
*/ |
|
133
|
|
|
public function delete($page_id) |
|
134
|
|
|
{ |
|
135
|
|
|
$params = [ |
|
136
|
|
|
'page_id' => intval($page_id), |
|
137
|
|
|
]; |
|
138
|
|
|
|
|
139
|
|
|
return $this->parseJSON('json', [self::API_DELETE, $params]); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|