From f90f4540d7e10ca8dca26b3999f618871782d132 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 16 Feb 2020 16:02:36 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#252=20=E5=AE=9E=E7=8E=B0=E5=9B=BE?= =?UTF-8?q?=E6=96=87=E6=B6=88=E6=81=AF=E7=95=99=E8=A8=80=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9A=84=E4=BA=94=E4=B8=AA=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=8C=85?= =?UTF-8?q?=E6=8B=AC=E6=A0=87=E8=AE=B0=E5=8F=8A=E5=8F=96=E6=B6=88=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E4=B8=BA=E7=B2=BE=E9=80=89=E3=80=81=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E3=80=81=E6=B7=BB=E5=8A=A0=E5=8F=8A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=9B=9E=E5=A4=8D=E7=AD=89=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpCommentService.java | 56 +++++++++++++++++++ .../mp/api/impl/WxMpCommentServiceImpl.java | 43 ++++++++++++++ .../chanjar/weixin/mp/enums/WxMpApiUrl.java | 27 ++++++++- .../api/impl/WxMpCommentServiceImplTest.java | 27 ++++++++- 4 files changed, 150 insertions(+), 3 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCommentService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCommentService.java index 1d96c968..c4ba7ca3 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCommentService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCommentService.java @@ -44,4 +44,60 @@ public interface WxMpCommentService { * @throws WxErrorException 异常 */ WxMpCommentListVo list(String msgDataId, Integer index, int begin, int count, int type) throws WxErrorException; + + /** + * 2.4 将评论标记精选. + * 接口调用请求: POST https://api.weixin.qq.com/cgi-bin/comment/markelect?access_token=ACCESS_TOKEN + * + * @param msgDataId 群发返回的msg_data_id + * @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文 + * @param userCommentId 用户评论id + * @throws WxErrorException 异常 + */ + void markElect(String msgDataId, Integer index, Long userCommentId) throws WxErrorException; + + /** + * 2.5 将评论取消精选. + * 接口调用请求: POST https://api.weixin.qq.com/cgi-bin/comment/unmarkelect?access_token=ACCESS_TOKEN + * + * @param msgDataId 群发返回的msg_data_id + * @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文 + * @param userCommentId 用户评论id + * @throws WxErrorException 异常 + */ + void unmarkElect(String msgDataId, Integer index, Long userCommentId) throws WxErrorException; + + /** + * 2.6 删除评论. + * 接口调用请求: POST https://api.weixin.qq.com/cgi-bin/comment/delete?access_token=ACCESS_TOKEN + * + * @param msgDataId 群发返回的msg_data_id + * @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文 + * @param userCommentId 用户评论id + * @throws WxErrorException 异常 + */ + void delete(String msgDataId, Integer index, Long userCommentId) throws WxErrorException; + + /** + * 2.7 回复评论. + * 接口调用请求: POST https://api.weixin.qq.com/cgi-bin/comment/reply/add?access_token=ACCESS_TOKEN + * + * @param msgDataId 群发返回的msg_data_id + * @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文 + * @param userCommentId 用户评论id + * @param content 回复内容 + * @throws WxErrorException 异常 + */ + void replyAdd(String msgDataId, Integer index, Long userCommentId, String content) throws WxErrorException; + + /** + * 2.8 删除回复. + * 接口调用请求: POST https://api.weixin.qq.com/cgi-bin/comment/reply/delete?access_token=ACCESS_TOKEN + * + * @param msgDataId 群发返回的msg_data_id + * @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文 + * @param userCommentId 用户评论id + * @throws WxErrorException 异常 + */ + void replyDelete(String msgDataId, Integer index, Long userCommentId) throws WxErrorException; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImpl.java index 02315cc2..8f287a80 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImpl.java @@ -53,4 +53,47 @@ public class WxMpCommentServiceImpl implements WxMpCommentService { return WxMpCommentListVo.fromJson(this.wxMpService.post(LIST, json.toString())); } + + @Override + public void markElect(String msgDataId, Integer index, Long userCommentId) throws WxErrorException { + JsonObject json = this.buildJson(msgDataId, index, userCommentId); + this.wxMpService.post(MARK_ELECT, json.toString()); + } + + @Override + public void unmarkElect(String msgDataId, Integer index, Long userCommentId) throws WxErrorException { + JsonObject json = this.buildJson(msgDataId, index, userCommentId); + this.wxMpService.post(UNMARK_ELECT, json.toString()); + } + + @Override + public void delete(String msgDataId, Integer index, Long userCommentId) throws WxErrorException { + JsonObject json = this.buildJson(msgDataId, index, userCommentId); + + this.wxMpService.post(DELETE, json.toString()); + } + + @Override + public void replyAdd(String msgDataId, Integer index, Long userCommentId, String content) throws WxErrorException { + JsonObject json = this.buildJson(msgDataId, index, userCommentId); + json.addProperty("content", content); + + this.wxMpService.post(REPLY_ADD, json.toString()); + } + + @Override + public void replyDelete(String msgDataId, Integer index, Long userCommentId) throws WxErrorException { + JsonObject json = this.buildJson(msgDataId, index, userCommentId); + this.wxMpService.post(REPLY_DELETE, json.toString()); + } + + private JsonObject buildJson(String msgDataId, Integer index, Long userCommentId) { + JsonObject json = new JsonObject(); + json.addProperty("msg_data_id", msgDataId); + json.addProperty("user_comment_id", userCommentId); + if (index != null) { + json.addProperty("index", index); + } + return json; + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java index c296481a..cbe3d4df 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java @@ -1002,7 +1002,32 @@ public interface WxMpApiUrl { /** * 查看指定文章的评论数据. */ - LIST(API_DEFAULT_HOST_URL, "/cgi-bin/comment/list"); + LIST(API_DEFAULT_HOST_URL, "/cgi-bin/comment/list"), + + /** + * 将评论标记精选. + */ + MARK_ELECT(API_DEFAULT_HOST_URL, "/cgi-bin/comment/markelect"), + + /** + * 将评论取消精选. + */ + UNMARK_ELECT(API_DEFAULT_HOST_URL, "/cgi-bin/comment/unmarkelect"), + + /** + * 删除评论. + */ + DELETE(API_DEFAULT_HOST_URL, "/cgi-bin/comment/delete"), + + /** + * 回复评论. + */ + REPLY_ADD(API_DEFAULT_HOST_URL, "/cgi-bin/comment/reply/add"), + + /** + * 删除回复. + */ + REPLY_DELETE(API_DEFAULT_HOST_URL, "/cgi-bin/comment/reply/delete"); private String prefix; private String path; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImplTest.java index 5f4bdecf..8efb70f9 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImplTest.java @@ -9,9 +9,7 @@ import me.chanjar.weixin.mp.bean.comment.WxMpCommentListVo; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Comment.LIST; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; @@ -74,4 +72,29 @@ public class WxMpCommentServiceImplTest { assertThat(commentListVo.getComment().get(0).getReply()).isNotNull(); } + + @Test + public void testMarkElect() throws WxErrorException { + this.wxService.getCommentService().markElect("1000000001", null, 1L); + } + + @Test + public void testUnmarkElect() throws WxErrorException { + this.wxService.getCommentService().unmarkElect("1000000001", null, 1L); + } + + @Test + public void testDelete() throws WxErrorException { + this.wxService.getCommentService().delete("1000000001", null, 1L); + } + + @Test + public void testReplyAdd() throws WxErrorException { + this.wxService.getCommentService().replyAdd("1000000001", null, 1L, "haha"); + } + + @Test + public void testReplyADelete() throws WxErrorException { + this.wxService.getCommentService().replyDelete("1000000001", null, 1L); + } }