Client.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. namespace EasyWeChat\OfficialAccount\Comment;
  11. use EasyWeChat\Kernel\BaseClient;
  12. /**
  13. * Class Client.
  14. *
  15. * @author overtrue <i@overtrue.me>
  16. */
  17. class Client extends BaseClient
  18. {
  19. /**
  20. * Open article comment.
  21. *
  22. * @param string $msgId
  23. * @param int|null $index
  24. *
  25. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  26. */
  27. public function open(string $msgId, int $index = null)
  28. {
  29. $params = [
  30. 'msg_data_id' => $msgId,
  31. 'index' => $index,
  32. ];
  33. return $this->httpPostJson('cgi-bin/comment/open', $params);
  34. }
  35. /**
  36. * Close comment.
  37. *
  38. * @param string $msgId
  39. * @param int|null $index
  40. *
  41. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  42. */
  43. public function close(string $msgId, int $index = null)
  44. {
  45. $params = [
  46. 'msg_data_id' => $msgId,
  47. 'index' => $index,
  48. ];
  49. return $this->httpPostJson('cgi-bin/comment/close', $params);
  50. }
  51. /**
  52. * Get article comments.
  53. *
  54. * @param string $msgId
  55. * @param int $index
  56. * @param int $begin
  57. * @param int $count
  58. * @param int $type
  59. *
  60. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  61. */
  62. public function list(string $msgId, int $index, int $begin, int $count, int $type = 0)
  63. {
  64. $params = [
  65. 'msg_data_id' => $msgId,
  66. 'index' => $index,
  67. 'begin' => $begin,
  68. 'count' => $count,
  69. 'type' => $type,
  70. ];
  71. return $this->httpPostJson('cgi-bin/comment/list', $params);
  72. }
  73. /**
  74. * Mark elect comment.
  75. *
  76. * @param string $msgId
  77. * @param int $index
  78. * @param int $commentId
  79. *
  80. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  81. */
  82. public function markElect(string $msgId, int $index, int $commentId)
  83. {
  84. $params = [
  85. 'msg_data_id' => $msgId,
  86. 'index' => $index,
  87. 'user_comment_id' => $commentId,
  88. ];
  89. return $this->httpPostJson('cgi-bin/comment/markelect', $params);
  90. }
  91. /**
  92. * Unmark elect comment.
  93. *
  94. * @param string $msgId
  95. * @param int $index
  96. * @param int $commentId
  97. *
  98. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  99. */
  100. public function unmarkElect(string $msgId, int $index, int $commentId)
  101. {
  102. $params = [
  103. 'msg_data_id' => $msgId,
  104. 'index' => $index,
  105. 'user_comment_id' => $commentId,
  106. ];
  107. return $this->httpPostJson('cgi-bin/comment/unmarkelect', $params);
  108. }
  109. /**
  110. * Delete comment.
  111. *
  112. * @param string $msgId
  113. * @param int $index
  114. * @param int $commentId
  115. *
  116. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  117. */
  118. public function delete(string $msgId, int $index, int $commentId)
  119. {
  120. $params = [
  121. 'msg_data_id' => $msgId,
  122. 'index' => $index,
  123. 'user_comment_id' => $commentId,
  124. ];
  125. return $this->httpPostJson('cgi-bin/comment/delete', $params);
  126. }
  127. /**
  128. * Reply to a comment.
  129. *
  130. * @param string $msgId
  131. * @param int $index
  132. * @param int $commentId
  133. * @param string $content
  134. *
  135. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  136. */
  137. public function reply(string $msgId, int $index, int $commentId, string $content)
  138. {
  139. $params = [
  140. 'msg_data_id' => $msgId,
  141. 'index' => $index,
  142. 'user_comment_id' => $commentId,
  143. 'content' => $content,
  144. ];
  145. return $this->httpPostJson('cgi-bin/comment/reply/add', $params);
  146. }
  147. /**
  148. * Delete a reply.
  149. *
  150. * @param string $msgId
  151. * @param int $index
  152. * @param int $commentId
  153. *
  154. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  155. */
  156. public function deleteReply(string $msgId, int $index, int $commentId)
  157. {
  158. $params = [
  159. 'msg_data_id' => $msgId,
  160. 'index' => $index,
  161. 'user_comment_id' => $commentId,
  162. ];
  163. return $this->httpPostJson('cgi-bin/comment/reply/delete', $params);
  164. }
  165. }