From be78d8c1251400b8068c639a5a197b8a2bdddaba Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 16 Jun 2019 23:41:08 +0800 Subject: [PATCH] =?UTF-8?q?#252=20=E6=B7=BB=E5=8A=A0=E5=9B=BE=E6=96=87?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E7=95=99=E8=A8=80=E7=AE=A1=E7=90=86=E4=B8=AD?= =?UTF-8?q?=E6=89=93=E5=BC=80=E5=B7=B2=E7=BE=A4=E5=8F=91=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E7=9A=84=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 | 22 +++++++++++++++ .../me/chanjar/weixin/mp/api/WxMpService.java | 9 ++++++ .../mp/api/impl/BaseWxMpServiceImpl.java | 11 ++++++++ .../mp/api/impl/WxMpCommentServiceImpl.java | 27 ++++++++++++++++++ .../chanjar/weixin/mp/enums/WxMpApiUrl.java | 17 ++++++++++- .../api/impl/WxMpCommentServiceImplTest.java | 28 +++++++++++++++++++ 6 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCommentService.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImpl.java create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImplTest.java 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 new file mode 100644 index 00000000..2ba7a092 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCommentService.java @@ -0,0 +1,22 @@ +package me.chanjar.weixin.mp.api; + +import me.chanjar.weixin.common.error.WxErrorException; + +/** + * 评论数据管理. + * + * @author Binary Wang + * @date 2019-06-16 + */ +public interface WxMpCommentService { + /** + * 打开已群发文章评论. + * https://api.weixin.qq.com/cgi-bin/comment/open?access_token=ACCESS_TOKEN + * 参数 是否必须 类型 说明 + * + * @param msgDataId 群发返回的msg_data_id + * @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文 + * @throws WxErrorException 异常 + */ + void open(Integer msgDataId, Integer index) throws WxErrorException; +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 92d17dbb..35debff5 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -526,4 +526,13 @@ public interface WxMpService { void setAiOpenService(WxMpAiOpenService aiOpenService); void setMarketingService(WxMpMarketingService marketingService); + + /** + * 返回评论数据管理接口方法的实现类对象,以方便调用其各个接口. + * + * @return WxMpWifiService + */ + WxMpCommentService getCommentService(); + + void setCommentService(WxMpCommentService commentService); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java index fc467e99..98220cd9 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java @@ -62,6 +62,7 @@ public abstract class BaseWxMpServiceImpl implements WxMpService, RequestH private WxMpAiOpenService aiOpenService = new WxMpAiOpenServiceImpl(this); private WxMpWifiService wifiService = new WxMpWifiServiceImpl(this); private WxMpMarketingService marketingService = new WxMpMarketingServiceImpl(this); + private WxMpCommentService commentService = new WxMpCommentServiceImpl(this); private Map configStorageMap; @@ -608,4 +609,14 @@ public abstract class BaseWxMpServiceImpl implements WxMpService, RequestH public void setMarketingService(WxMpMarketingService marketingService) { this.marketingService = marketingService; } + + @Override + public WxMpCommentService getCommentService() { + return this.commentService; + } + + @Override + public void setCommentService(WxMpCommentService commentService) { + this.commentService = commentService; + } } 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 new file mode 100644 index 00000000..f58280ae --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImpl.java @@ -0,0 +1,27 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.gson.JsonObject; +import lombok.RequiredArgsConstructor; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpCommentService; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.enums.WxMpApiUrl; + +/** + * @author Binary Wang + * @date 2019-06-16 + */ +@RequiredArgsConstructor +public class WxMpCommentServiceImpl implements WxMpCommentService { + private final WxMpService wxMpService; + + @Override + public void open(Integer msgDataId, Integer index) throws WxErrorException { + JsonObject json = new JsonObject(); + json.addProperty("msg_data_id", msgDataId); + if (index != null) { + json.addProperty("index", index); + } + this.wxMpService.post(WxMpApiUrl.Comment.OPEN, json.toString()); + } +} 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 fd32840c..276c1c9e 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 @@ -807,7 +807,6 @@ public interface WxMpApiUrl { } } - @AllArgsConstructor enum User implements WxMpApiUrl { /** @@ -839,4 +838,20 @@ public interface WxMpApiUrl { return buildUrl(config.getHostConfig(), prefix, path); } } + + @AllArgsConstructor + enum Comment implements WxMpApiUrl { + /** + * 打开已群发文章评论. + */ + OPEN(API_DEFAULT_HOST_URL, "/cgi-bin/comment/open"); + + private String prefix; + private String path; + + @Override + public String getUrl(WxMpConfigStorage config) { + return buildUrl(config.getHostConfig(), prefix, 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 new file mode 100644 index 00000000..60551c32 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImplTest.java @@ -0,0 +1,28 @@ +package me.chanjar.weixin.mp.api.impl; + +import com.google.inject.Inject; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.test.ApiTestModule; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +/** + * 测试类. + * + * @author Binary Wang + * @date 2019-06-16 + */ + +@Test +@Guice(modules = ApiTestModule.class) +public class WxMpCommentServiceImplTest { + @Inject + private WxMpService wxService; + + @Test + public void testOpen() throws WxErrorException { + this.wxService.getCommentService().open(1, null); + this.wxService.getCommentService().open(1, 0); + } +}