#252 添加图文消息留言管理中打开已群发文章评论的接口

This commit is contained in:
Binary Wang 2019-06-16 23:41:08 +08:00
parent 9c149bb1e2
commit be78d8c125
6 changed files with 113 additions and 1 deletions

View File

@ -0,0 +1,22 @@
package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 评论数据管理.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @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;
}

View File

@ -526,4 +526,13 @@ public interface WxMpService {
void setAiOpenService(WxMpAiOpenService aiOpenService);
void setMarketingService(WxMpMarketingService marketingService);
/**
* 返回评论数据管理接口方法的实现类对象以方便调用其各个接口.
*
* @return WxMpWifiService
*/
WxMpCommentService getCommentService();
void setCommentService(WxMpCommentService commentService);
}

View File

@ -62,6 +62,7 @@ public abstract class BaseWxMpServiceImpl<H, P> 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<String, WxMpConfigStorage> configStorageMap;
@ -608,4 +609,14 @@ public abstract class BaseWxMpServiceImpl<H, P> 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;
}
}

View File

@ -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 <a href="https://github.com/binarywang">Binary Wang</a>
* @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());
}
}

View File

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

View File

@ -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 <a href="https://github.com/binarywang">Binary Wang</a>
* @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);
}
}