Skip to content

Commit f90f454

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

File tree

4 files changed

+150
-3
lines changed

4 files changed

+150
-3
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCommentService.java

+56
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,60 @@ public interface WxMpCommentService {
4444
* @throws WxErrorException 异常
4545
*/
4646
WxMpCommentListVo list(String msgDataId, Integer index, int begin, int count, int type) throws WxErrorException;
47+
48+
/**
49+
* 2.4 将评论标记精选.
50+
* 接口调用请求: POST https://api.weixin.qq.com/cgi-bin/comment/markelect?access_token=ACCESS_TOKEN
51+
*
52+
* @param msgDataId 群发返回的msg_data_id
53+
* @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文
54+
* @param userCommentId 用户评论id
55+
* @throws WxErrorException 异常
56+
*/
57+
void markElect(String msgDataId, Integer index, Long userCommentId) throws WxErrorException;
58+
59+
/**
60+
* 2.5 将评论取消精选.
61+
* 接口调用请求: POST https://api.weixin.qq.com/cgi-bin/comment/unmarkelect?access_token=ACCESS_TOKEN
62+
*
63+
* @param msgDataId 群发返回的msg_data_id
64+
* @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文
65+
* @param userCommentId 用户评论id
66+
* @throws WxErrorException 异常
67+
*/
68+
void unmarkElect(String msgDataId, Integer index, Long userCommentId) throws WxErrorException;
69+
70+
/**
71+
* 2.6 删除评论.
72+
* 接口调用请求: POST https://api.weixin.qq.com/cgi-bin/comment/delete?access_token=ACCESS_TOKEN
73+
*
74+
* @param msgDataId 群发返回的msg_data_id
75+
* @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文
76+
* @param userCommentId 用户评论id
77+
* @throws WxErrorException 异常
78+
*/
79+
void delete(String msgDataId, Integer index, Long userCommentId) throws WxErrorException;
80+
81+
/**
82+
* 2.7 回复评论.
83+
* 接口调用请求: POST https://api.weixin.qq.com/cgi-bin/comment/reply/add?access_token=ACCESS_TOKEN
84+
*
85+
* @param msgDataId 群发返回的msg_data_id
86+
* @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文
87+
* @param userCommentId 用户评论id
88+
* @param content 回复内容
89+
* @throws WxErrorException 异常
90+
*/
91+
void replyAdd(String msgDataId, Integer index, Long userCommentId, String content) throws WxErrorException;
92+
93+
/**
94+
* 2.8 删除回复.
95+
* 接口调用请求: POST https://api.weixin.qq.com/cgi-bin/comment/reply/delete?access_token=ACCESS_TOKEN
96+
*
97+
* @param msgDataId 群发返回的msg_data_id
98+
* @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文
99+
* @param userCommentId 用户评论id
100+
* @throws WxErrorException 异常
101+
*/
102+
void replyDelete(String msgDataId, Integer index, Long userCommentId) throws WxErrorException;
47103
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImpl.java

+43
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,47 @@ public WxMpCommentListVo list(String msgDataId, Integer index, int begin, int co
5353

5454
return WxMpCommentListVo.fromJson(this.wxMpService.post(LIST, json.toString()));
5555
}
56+
57+
@Override
58+
public void markElect(String msgDataId, Integer index, Long userCommentId) throws WxErrorException {
59+
JsonObject json = this.buildJson(msgDataId, index, userCommentId);
60+
this.wxMpService.post(MARK_ELECT, json.toString());
61+
}
62+
63+
@Override
64+
public void unmarkElect(String msgDataId, Integer index, Long userCommentId) throws WxErrorException {
65+
JsonObject json = this.buildJson(msgDataId, index, userCommentId);
66+
this.wxMpService.post(UNMARK_ELECT, json.toString());
67+
}
68+
69+
@Override
70+
public void delete(String msgDataId, Integer index, Long userCommentId) throws WxErrorException {
71+
JsonObject json = this.buildJson(msgDataId, index, userCommentId);
72+
73+
this.wxMpService.post(DELETE, json.toString());
74+
}
75+
76+
@Override
77+
public void replyAdd(String msgDataId, Integer index, Long userCommentId, String content) throws WxErrorException {
78+
JsonObject json = this.buildJson(msgDataId, index, userCommentId);
79+
json.addProperty("content", content);
80+
81+
this.wxMpService.post(REPLY_ADD, json.toString());
82+
}
83+
84+
@Override
85+
public void replyDelete(String msgDataId, Integer index, Long userCommentId) throws WxErrorException {
86+
JsonObject json = this.buildJson(msgDataId, index, userCommentId);
87+
this.wxMpService.post(REPLY_DELETE, json.toString());
88+
}
89+
90+
private JsonObject buildJson(String msgDataId, Integer index, Long userCommentId) {
91+
JsonObject json = new JsonObject();
92+
json.addProperty("msg_data_id", msgDataId);
93+
json.addProperty("user_comment_id", userCommentId);
94+
if (index != null) {
95+
json.addProperty("index", index);
96+
}
97+
return json;
98+
}
5699
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,32 @@ enum Comment implements WxMpApiUrl {
10021002
/**
10031003
* 查看指定文章的评论数据.
10041004
*/
1005-
LIST(API_DEFAULT_HOST_URL, "/cgi-bin/comment/list");
1005+
LIST(API_DEFAULT_HOST_URL, "/cgi-bin/comment/list"),
1006+
1007+
/**
1008+
* 将评论标记精选.
1009+
*/
1010+
MARK_ELECT(API_DEFAULT_HOST_URL, "/cgi-bin/comment/markelect"),
1011+
1012+
/**
1013+
* 将评论取消精选.
1014+
*/
1015+
UNMARK_ELECT(API_DEFAULT_HOST_URL, "/cgi-bin/comment/unmarkelect"),
1016+
1017+
/**
1018+
* 删除评论.
1019+
*/
1020+
DELETE(API_DEFAULT_HOST_URL, "/cgi-bin/comment/delete"),
1021+
1022+
/**
1023+
* 回复评论.
1024+
*/
1025+
REPLY_ADD(API_DEFAULT_HOST_URL, "/cgi-bin/comment/reply/add"),
1026+
1027+
/**
1028+
* 删除回复.
1029+
*/
1030+
REPLY_DELETE(API_DEFAULT_HOST_URL, "/cgi-bin/comment/reply/delete");
10061031

10071032
private String prefix;
10081033
private String path;

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImplTest.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import org.testng.annotations.Guice;
1010
import org.testng.annotations.Test;
1111

12-
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Comment.LIST;
1312
import static org.assertj.core.api.Assertions.assertThat;
14-
import static org.mockito.Matchers.any;
1513
import static org.mockito.Matchers.anyString;
1614
import static org.mockito.Mockito.doReturn;
1715
import static org.mockito.Mockito.spy;
@@ -74,4 +72,29 @@ public void testList() throws WxErrorException {
7472

7573
assertThat(commentListVo.getComment().get(0).getReply()).isNotNull();
7674
}
75+
76+
@Test
77+
public void testMarkElect() throws WxErrorException {
78+
this.wxService.getCommentService().markElect("1000000001", null, 1L);
79+
}
80+
81+
@Test
82+
public void testUnmarkElect() throws WxErrorException {
83+
this.wxService.getCommentService().unmarkElect("1000000001", null, 1L);
84+
}
85+
86+
@Test
87+
public void testDelete() throws WxErrorException {
88+
this.wxService.getCommentService().delete("1000000001", null, 1L);
89+
}
90+
91+
@Test
92+
public void testReplyAdd() throws WxErrorException {
93+
this.wxService.getCommentService().replyAdd("1000000001", null, 1L, "haha");
94+
}
95+
96+
@Test
97+
public void testReplyADelete() throws WxErrorException {
98+
this.wxService.getCommentService().replyDelete("1000000001", null, 1L);
99+
}
77100
}

0 commit comments

Comments
 (0)