|
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
|
|
|
* Comment.php. |
|
14
|
|
|
* |
|
15
|
|
|
* Part of Overtrue\WeChat. |
|
16
|
|
|
* |
|
17
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
18
|
|
|
* file that was distributed with this source code. |
|
19
|
|
|
* |
|
20
|
|
|
* @author mingyoung <[email protected]> |
|
21
|
|
|
* @copyright 2017 |
|
22
|
|
|
* |
|
23
|
|
|
* @see https://github.com/overtrue |
|
24
|
|
|
* @see http://overtrue.me |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace EasyWeChat\Comment; |
|
28
|
|
|
|
|
29
|
|
|
use EasyWeChat\Core\AbstractAPI; |
|
30
|
|
|
|
|
31
|
|
|
class Comment extends AbstractAPI |
|
32
|
|
|
{ |
|
33
|
|
|
const API_OPEN_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/open'; |
|
34
|
|
|
const API_CLOSE_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/close'; |
|
35
|
|
|
const API_LIST_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/list'; |
|
36
|
|
|
const API_MARK_ELECT = 'https://api.weixin.qq.com/cgi-bin/comment/markelect'; |
|
37
|
|
|
const API_UNMARK_ELECT = 'https://api.weixin.qq.com/cgi-bin/comment/unmarkelect'; |
|
38
|
|
|
const API_DELETE_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/delete'; |
|
39
|
|
|
const API_REPLY_COMMENT = 'https://api.weixin.qq.com/cgi-bin/comment/reply/add'; |
|
40
|
|
|
const API_DELETE_REPLY = 'https://api.weixin.qq.com/cgi-bin/comment/reply/delete'; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Open article comment. |
|
44
|
|
|
* |
|
45
|
|
|
* @param int $dataId |
|
46
|
|
|
* @param int $index |
|
47
|
|
|
* |
|
48
|
|
|
* @return \EasyWeChat\Support\Collection |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function open($dataId, $index = null) |
|
51
|
|
|
{ |
|
52
|
|
|
$params = [ |
|
53
|
1 |
|
'msg_data_id' => $dataId, |
|
54
|
1 |
|
'index' => $index, |
|
55
|
1 |
|
]; |
|
56
|
|
|
|
|
57
|
1 |
|
return $this->parseJSON('post', [self::API_OPEN_COMMENT, $params]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Close comment. |
|
62
|
|
|
* |
|
63
|
|
|
* @param int $dataId |
|
64
|
|
|
* @param int $index |
|
65
|
|
|
* |
|
66
|
|
|
* @return \EasyWeChat\Support\Collection |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function close($dataId, $index = null) |
|
69
|
|
|
{ |
|
70
|
|
|
$params = [ |
|
71
|
1 |
|
'msg_data_id' => $dataId, |
|
72
|
1 |
|
'index' => $index, |
|
73
|
1 |
|
]; |
|
74
|
|
|
|
|
75
|
1 |
|
return $this->parseJSON('post', [self::API_CLOSE_COMMENT, $params]); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Get article comments. |
|
80
|
|
|
* |
|
81
|
|
|
* @param int $dataId |
|
82
|
|
|
* @param int $index |
|
83
|
|
|
* @param int $begin |
|
84
|
|
|
* @param int $count |
|
85
|
|
|
* @param int $type |
|
86
|
|
|
* |
|
87
|
|
|
* @return \EasyWeChat\Support\Collection |
|
88
|
|
|
*/ |
|
89
|
1 |
|
public function lists($dataId, $index, $begin, $count, $type = 0) |
|
90
|
|
|
{ |
|
91
|
|
|
$params = [ |
|
92
|
1 |
|
'msg_data_id' => $dataId, |
|
93
|
1 |
|
'index' => $index, |
|
94
|
1 |
|
'begin' => $begin, |
|
95
|
1 |
|
'count' => $count, |
|
96
|
1 |
|
'type' => $type, |
|
97
|
1 |
|
]; |
|
98
|
|
|
|
|
99
|
1 |
|
return $this->parseJSON('post', [self::API_LIST_COMMENT, $params]); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Mark elect comment. |
|
104
|
|
|
* |
|
105
|
|
|
* @param int $dataId |
|
106
|
|
|
* @param int $index |
|
107
|
|
|
* @param int $commentId |
|
108
|
|
|
* |
|
109
|
|
|
* @return \EasyWeChat\Support\Collection |
|
110
|
|
|
*/ |
|
111
|
1 |
View Code Duplication |
public function markElect($dataId, $index, $commentId) |
|
112
|
|
|
{ |
|
113
|
|
|
$params = [ |
|
114
|
1 |
|
'msg_data_id' => $dataId, |
|
115
|
1 |
|
'index' => $index, |
|
116
|
1 |
|
'user_comment_id' => $commentId, |
|
117
|
1 |
|
]; |
|
118
|
|
|
|
|
119
|
1 |
|
return $this->parseJSON('post', [self::API_MARK_ELECT, $params]); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Unmark elect comment. |
|
124
|
|
|
* |
|
125
|
|
|
* @param int $dataId |
|
126
|
|
|
* @param int $index |
|
127
|
|
|
* @param int $commentId |
|
128
|
|
|
* |
|
129
|
|
|
* @return \EasyWeChat\Support\Collection |
|
130
|
|
|
*/ |
|
131
|
1 |
View Code Duplication |
public function unmarkElect($dataId, $index, $commentId) |
|
132
|
|
|
{ |
|
133
|
|
|
$params = [ |
|
134
|
1 |
|
'msg_data_id' => $dataId, |
|
135
|
1 |
|
'index' => $index, |
|
136
|
1 |
|
'user_comment_id' => $commentId, |
|
137
|
1 |
|
]; |
|
138
|
|
|
|
|
139
|
1 |
|
return $this->parseJSON('post', [self::API_UNMARK_ELECT, $params]); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Delete comment. |
|
144
|
|
|
* |
|
145
|
|
|
* @param int $dataId |
|
146
|
|
|
* @param int $index |
|
147
|
|
|
* @param int $commentId |
|
148
|
|
|
* |
|
149
|
|
|
* @return \EasyWeChat\Support\Collection |
|
150
|
|
|
*/ |
|
151
|
1 |
View Code Duplication |
public function delete($dataId, $index, $commentId) |
|
152
|
|
|
{ |
|
153
|
|
|
$params = [ |
|
154
|
1 |
|
'msg_data_id' => $dataId, |
|
155
|
1 |
|
'index' => $index, |
|
156
|
1 |
|
'user_comment_id' => $commentId, |
|
157
|
1 |
|
]; |
|
158
|
|
|
|
|
159
|
1 |
|
return $this->parseJSON('post', [self::API_DELETE_COMMENT, $params]); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Reply to a comment. |
|
164
|
|
|
* |
|
165
|
|
|
* @param int $dataId |
|
166
|
|
|
* @param int $index |
|
167
|
|
|
* @param int $commentId |
|
168
|
|
|
* @param string $content |
|
169
|
|
|
* |
|
170
|
|
|
* @return \EasyWeChat\Support\Collection |
|
171
|
|
|
*/ |
|
172
|
1 |
View Code Duplication |
public function reply($dataId, $index, $commentId, $content) |
|
173
|
|
|
{ |
|
174
|
|
|
$params = [ |
|
175
|
1 |
|
'msg_data_id' => $dataId, |
|
176
|
1 |
|
'index' => $index, |
|
177
|
1 |
|
'user_comment_id' => $commentId, |
|
178
|
1 |
|
'content' => $content, |
|
179
|
1 |
|
]; |
|
180
|
|
|
|
|
181
|
1 |
|
return $this->parseJSON('post', [self::API_REPLY_COMMENT, $params]); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Delete a reply. |
|
186
|
|
|
* |
|
187
|
|
|
* @param int $dataId |
|
188
|
|
|
* @param int $index |
|
189
|
|
|
* @param int $commentId |
|
190
|
|
|
* |
|
191
|
|
|
* @return \EasyWeChat\Support\Collection |
|
192
|
|
|
*/ |
|
193
|
1 |
View Code Duplication |
public function deleteReply($dataId, $index, $commentId) |
|
194
|
|
|
{ |
|
195
|
|
|
$params = [ |
|
196
|
1 |
|
'msg_data_id' => $dataId, |
|
197
|
1 |
|
'index' => $index, |
|
198
|
1 |
|
'user_comment_id' => $commentId, |
|
199
|
1 |
|
]; |
|
200
|
|
|
|
|
201
|
1 |
|
return $this->parseJSON('post', [self::API_DELETE_REPLY, $params]); |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
|