1
0
mirror of synced 2025-12-26 04:27:56 +08:00

🆕 #1723 企业微信增加查询应用消息发送统计的接口

This commit is contained in:
Binary Wang
2020-09-13 09:51:40 +08:00
parent 91d484f730
commit 37a009c790
6 changed files with 131 additions and 28 deletions

View File

@@ -4,6 +4,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.message.WxCpLinkedCorpMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendStatistics;
/**
* 消息推送接口.
@@ -24,6 +25,21 @@ public interface WxCpMessageService {
*/
WxCpMessageSendResult send(WxCpMessage message) throws WxErrorException;
/**
* <pre>
* 查询应用消息发送统计
* 请求方式POSTHTTPS
* 请求地址https://qyapi.weixin.qq.com/cgi-bin/message/get_statistics?access_token=ACCESS_TOKEN
*
* 详情请见: https://work.weixin.qq.com/api/doc/90000/90135/92369
* </pre>
*
* @param timeType 查询哪天的数据0当天1昨天。默认为0。
* @return 统计结果
* @throws WxErrorException the wx error exception
*/
WxCpMessageSendStatistics getStatistics(int timeType) throws WxErrorException;
/**
* <pre>
* 互联企业的应用支持推送文本、图片、视频、文件、图文等类型。

View File

@@ -1,5 +1,6 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.common.collect.ImmutableMap;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpMessageService;
@@ -7,7 +8,9 @@ import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.message.WxCpLinkedCorpMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendStatistics;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Message;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
/**
* 消息推送接口实现类.
@@ -27,7 +30,13 @@ public class WxCpMessageServiceImpl implements WxCpMessageService {
}
return WxCpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
.getApiUrl(WxCpApiPathConsts.Message.MESSAGE_SEND), message.toJson()));
.getApiUrl(Message.MESSAGE_SEND), message.toJson()));
}
@Override
public WxCpMessageSendStatistics getStatistics(int timeType) throws WxErrorException {
return WxCpMessageSendStatistics.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(Message.GET_STATISTICS),
WxCpGsonBuilder.create().toJson(ImmutableMap.of("time_type", timeType))));
}
@Override
@@ -38,6 +47,6 @@ public class WxCpMessageServiceImpl implements WxCpMessageService {
}
return WxCpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
.getApiUrl(WxCpApiPathConsts.Message.LINKEDCORP_MESSAGE_SEND), message.toJson()));
.getApiUrl(Message.LINKEDCORP_MESSAGE_SEND), message.toJson()));
}
}

View File

@@ -0,0 +1,43 @@
package me.chanjar.weixin.cp.bean.message;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.util.List;
/**
* 应用消息发送统计信息.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-09-13
*/
@Data
public class WxCpMessageSendStatistics {
public static WxCpMessageSendStatistics fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMessageSendStatistics.class);
}
private List<StatisticItem> statistics;
@Data
public static class StatisticItem {
/**
* 应用名
*/
@SerializedName("app_name")
private String appName;
/**
* 应用id
*/
@SerializedName("agentid")
private Integer agentId;
/**
* 发消息成功人次
*/
@SerializedName("count")
private Integer count;
}
}

View File

@@ -36,6 +36,11 @@ public final class WxCpApiPathConsts {
*/
public static final String MESSAGE_SEND = "/cgi-bin/message/send";
/**
* 查询应用消息发送统计
*/
public static final String GET_STATISTICS = "/cgi-bin/message/get_statistics";
/**
* 互联企业发送应用消息
*/