🆕 #252 实现图文消息留言管理的五个接口,包括标记及取消评论为精选、删除评论、添加及删除回复等接口

This commit is contained in:
Binary Wang 2020-02-16 16:02:36 +08:00
parent 94064752ab
commit f90f4540d7
4 changed files with 150 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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