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);
+ }
+}