Comment.php 5.0 KB

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