mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-17 13:49:26 +08:00
✨ #252 增加关闭已群发文章评论和查看指定文章的评论数据的接口
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.comment.WxMpCommentListVo;
|
||||
|
||||
/**
|
||||
* 评论数据管理.
|
||||
* 图文消息留言管理接口.
|
||||
* https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1494572718_WzHIY
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
* @date 2019-06-16
|
||||
@@ -12,11 +14,34 @@ 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;
|
||||
|
||||
/**
|
||||
* 关闭已群发文章评论.
|
||||
* https://api.weixin.qq.com/cgi-bin/comment/close?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param msgDataId 群发返回的msg_data_id
|
||||
* @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文
|
||||
* @throws WxErrorException 异常
|
||||
*/
|
||||
void close(Integer msgDataId, Integer index) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 查看指定文章的评论数据.
|
||||
* https://api.weixin.qq.com/cgi-bin/comment/list?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param msgDataId 群发返回的msg_data_id
|
||||
* @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文
|
||||
* @param begin 起始位置
|
||||
* @param count 获取数目(>=50会被拒绝)
|
||||
* @param type type=0 普通评论&精选评论 type=1 普通评论 type=2 精选评论
|
||||
* @return 评论列表数据
|
||||
* @throws WxErrorException 异常
|
||||
*/
|
||||
WxMpCommentListVo list(Integer msgDataId, Integer index, int begin, int count, int type) throws WxErrorException;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ 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;
|
||||
import me.chanjar.weixin.mp.bean.comment.WxMpCommentListVo;
|
||||
|
||||
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Comment.*;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
@@ -22,6 +24,33 @@ public class WxMpCommentServiceImpl implements WxMpCommentService {
|
||||
if (index != null) {
|
||||
json.addProperty("index", index);
|
||||
}
|
||||
this.wxMpService.post(WxMpApiUrl.Comment.OPEN, json.toString());
|
||||
|
||||
this.wxMpService.post(OPEN, json.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(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(CLOSE, json.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpCommentListVo list(Integer msgDataId, Integer index, int begin, int count, int type) throws WxErrorException {
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("msg_data_id", msgDataId);
|
||||
json.addProperty("begin", begin);
|
||||
json.addProperty("count", count);
|
||||
json.addProperty("type", type);
|
||||
|
||||
if (index != null) {
|
||||
json.addProperty("index", index);
|
||||
}
|
||||
|
||||
return WxMpCommentListVo.fromJson(this.wxMpService.post(LIST, json.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package me.chanjar.weixin.mp.bean.comment;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.xml.IntegerArrayConverter;
|
||||
import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 群发图文评论数据.
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
* @date 2019-08-30
|
||||
*/
|
||||
@Data
|
||||
public class WxMpCommentListVo implements Serializable {
|
||||
private static final long serialVersionUID = 7604754799359751247L;
|
||||
|
||||
/**
|
||||
* 总数,非comment的size.
|
||||
*/
|
||||
private Integer total;
|
||||
|
||||
/**
|
||||
* 评论列表.
|
||||
*/
|
||||
private List<WxMpComment> comment;
|
||||
|
||||
@Data
|
||||
public static class Reply implements Serializable {
|
||||
private static final long serialVersionUID = 9174739515408520429L;
|
||||
|
||||
/**
|
||||
* 作者回复时间 .
|
||||
*/
|
||||
@SerializedName("create_time")
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 作者回复内容.
|
||||
*/
|
||||
private String content;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class WxMpComment implements Serializable {
|
||||
private static final long serialVersionUID = 5401188720891942634L;
|
||||
|
||||
/**
|
||||
* 用户评论id .
|
||||
*/
|
||||
@SerializedName("user_comment_id")
|
||||
private Integer userCommentId;
|
||||
|
||||
/**
|
||||
* 用户openid.
|
||||
*/
|
||||
private String openid;
|
||||
|
||||
/**
|
||||
* 评论时间.
|
||||
*/
|
||||
@SerializedName("create_time")
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 评论内容.
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 是否精选评论,0为即非精选,1为true,即精选.
|
||||
*/
|
||||
@SerializedName("comment_type")
|
||||
private Integer commentType;
|
||||
|
||||
/**
|
||||
* 作者回复.
|
||||
*/
|
||||
private Reply reply;
|
||||
}
|
||||
|
||||
public static WxMpCommentListVo fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(json, WxMpCommentListVo.class);
|
||||
}
|
||||
}
|
||||
@@ -875,7 +875,17 @@ public interface WxMpApiUrl {
|
||||
/**
|
||||
* 打开已群发文章评论.
|
||||
*/
|
||||
OPEN(API_DEFAULT_HOST_URL, "/cgi-bin/comment/open");
|
||||
OPEN(API_DEFAULT_HOST_URL, "/cgi-bin/comment/open"),
|
||||
|
||||
/**
|
||||
* 关闭已群发文章评论.
|
||||
*/
|
||||
CLOSE(API_DEFAULT_HOST_URL, "/cgi-bin/comment/close"),
|
||||
|
||||
/**
|
||||
* 查看指定文章的评论数据.
|
||||
*/
|
||||
LIST(API_DEFAULT_HOST_URL, "/cgi-bin/comment/list");
|
||||
|
||||
private String prefix;
|
||||
private String path;
|
||||
|
||||
Reference in New Issue
Block a user