Skip to content

Commit a685e8f

Browse files
authored
🆕 #2620 【企业微信】微信客服统计管理模块增加获取「客户数据统计」企业汇总数据的接口
1 parent 010c184 commit a685e8f

File tree

7 files changed

+192
-32
lines changed

7 files changed

+192
-32
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpKfService.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
package me.chanjar.weixin.cp.api;
22

3-
import java.util.List;
43
import me.chanjar.weixin.common.error.WxErrorException;
54
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAdd;
7-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAddResp;
8-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountDel;
9-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountLink;
10-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountLinkResp;
11-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountListResp;
12-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountUpd;
13-
import me.chanjar.weixin.cp.bean.kf.WxCpKfCustomerBatchGetResp;
14-
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgListResp;
15-
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgSendRequest;
16-
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgSendResp;
17-
import me.chanjar.weixin.cp.bean.kf.WxCpKfServiceStateResp;
18-
import me.chanjar.weixin.cp.bean.kf.WxCpKfServiceStateTransResp;
19-
import me.chanjar.weixin.cp.bean.kf.WxCpKfServicerListResp;
20-
import me.chanjar.weixin.cp.bean.kf.WxCpKfServicerOpResp;
5+
import me.chanjar.weixin.cp.bean.kf.*;
6+
7+
import java.util.List;
218

229
/**
2310
* 微信客服接口
@@ -188,4 +175,17 @@ WxCpKfMsgListResp syncMsg(String cursor, String token, Integer limit, Integer vo
188175
*/
189176
WxCpKfCustomerBatchGetResp customerBatchGet(List<String> externalUserIdList)
190177
throws WxErrorException;
178+
179+
/**
180+
* <pre>
181+
* 获取「客户数据统计」企业汇总数据
182+
* 通过此接口,可以获取咨询会话数、咨询客户数等企业汇总统计数据
183+
* 请求方式:POST(HTTPS)
184+
* 请求地址:<a href="https://qyapi.weixin.qq.com/cgi-bin/kf/get_corp_statistic?access_token=ACCESS_TOKEN">https://qyapi.weixin.qq.com/cgi-bin/kf/get_corp_statistic?access_token=ACCESS_TOKEN</a>
185+
* 文档地址:<a href="https://developer.work.weixin.qq.com/document/path/95489">https://developer.work.weixin.qq.com/document/path/95489</a>
186+
* <pre>
187+
* @param request 查询参数
188+
* @return 客户数据统计-企业汇总数据
189+
*/
190+
WxCpKfGetCorpStatisticResp getCorpStatistic(WxCpKfGetCorpStatisticRequest request) throws WxErrorException;
191191
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpKfServiceImpl.java

+10-16
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,16 @@
44
import com.google.gson.GsonBuilder;
55
import com.google.gson.JsonArray;
66
import com.google.gson.JsonObject;
7-
import java.util.List;
87
import lombok.RequiredArgsConstructor;
98
import me.chanjar.weixin.common.error.WxErrorException;
109
import me.chanjar.weixin.cp.api.WxCpKfService;
1110
import me.chanjar.weixin.cp.api.WxCpService;
1211
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
13-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAdd;
14-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAddResp;
15-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountDel;
16-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountLink;
17-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountLinkResp;
18-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountListResp;
19-
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountUpd;
20-
import me.chanjar.weixin.cp.bean.kf.WxCpKfCustomerBatchGetResp;
21-
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgListResp;
22-
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgSendRequest;
23-
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgSendResp;
24-
import me.chanjar.weixin.cp.bean.kf.WxCpKfServiceStateResp;
25-
import me.chanjar.weixin.cp.bean.kf.WxCpKfServiceStateTransResp;
26-
import me.chanjar.weixin.cp.bean.kf.WxCpKfServicerListResp;
27-
import me.chanjar.weixin.cp.bean.kf.WxCpKfServicerOpResp;
12+
import me.chanjar.weixin.cp.bean.kf.*;
2813
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
2914

15+
import java.util.List;
16+
3017
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Kf.*;
3118

3219
/**
@@ -188,4 +175,11 @@ public WxCpKfCustomerBatchGetResp customerBatchGet(List<String> externalUserIdLi
188175
return WxCpKfCustomerBatchGetResp.fromJson(responseContent);
189176
}
190177

178+
@Override
179+
public WxCpKfGetCorpStatisticResp getCorpStatistic(WxCpKfGetCorpStatisticRequest request) throws WxErrorException {
180+
String url = cpService.getWxCpConfigStorage().getApiUrl(GET_CORP_STATISTIC);
181+
String responseContent = cpService.post(url, GSON.toJson(request));
182+
return WxCpKfGetCorpStatisticResp.fromJson(responseContent);
183+
}
184+
191185
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package me.chanjar.weixin.cp.bean.kf;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
/**
8+
* 获取「客户数据统计」企业汇总数据
9+
*
10+
* @author zhongjun
11+
* @date 2022/4/25
12+
**/
13+
@NoArgsConstructor
14+
@Data
15+
public class WxCpKfGetCorpStatisticRequest {
16+
17+
/**
18+
* 客服帐号ID。不传入时返回的数据为企业维度汇总的数据
19+
*/
20+
@SerializedName("open_kfid")
21+
private String openKfId;
22+
23+
/**
24+
* 起始日期的时间戳,填这一天的0时0分0秒(否则系统自动处理为当天的0分0秒)。取值范围:昨天至前180天
25+
*/
26+
@SerializedName("start_time")
27+
private Long startTime;
28+
/**
29+
* 结束日期的时间戳,填这一天的0时0分0秒(否则系统自动处理为当天的0分0秒)。取值范围:昨天至前180天
30+
*/
31+
@SerializedName("end_time")
32+
private Long endTime;
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package me.chanjar.weixin.cp.bean.kf;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.NoArgsConstructor;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.util.List;
11+
12+
/**
13+
* 获取「客户数据统计」企业汇总数据
14+
*
15+
* @author zhongjun
16+
* @date 2022/4/25
17+
**/
18+
@EqualsAndHashCode(callSuper = true)
19+
@NoArgsConstructor
20+
@Data
21+
public class WxCpKfGetCorpStatisticResp extends WxCpBaseResp {
22+
private static final long serialVersionUID = -89898989898989898L;
23+
24+
/**
25+
* 统计数据列表
26+
*/
27+
@SerializedName("statistic_list")
28+
private List<StatisticList> statisticList;
29+
30+
@NoArgsConstructor
31+
@Data
32+
public static class StatisticList {
33+
/**
34+
* 数据统计日期,为当日0点的时间戳
35+
*/
36+
@SerializedName("stat_time")
37+
private Long statTime;
38+
39+
/**
40+
* 一天的统计数据。若当天未产生任何下列统计数据或统计数据还未计算完成则不会返回此项
41+
*/
42+
@SerializedName("statistic")
43+
private Statistic statistic;
44+
}
45+
46+
@NoArgsConstructor
47+
@Data
48+
public static class Statistic {
49+
50+
/**
51+
* 咨询会话数。客户发过消息并分配给接待人员或智能助手的客服会话数,转接不会产生新的会话
52+
*/
53+
@SerializedName("session_cnt")
54+
private Integer sessionCnt;
55+
56+
/**
57+
* 咨询客户数。在会话中发送过消息的客户数量,若客户多次咨询只计算一个客户
58+
*/
59+
@SerializedName("user_cnt")
60+
private Integer customerCnt;
61+
62+
/**
63+
* 咨询消息总数。客户在会话中发送的消息的数量
64+
*/
65+
@SerializedName("customer_msg_cnt")
66+
private Integer customerMsgCnt;
67+
68+
/**
69+
* 升级服务客户数。通过「升级服务」功能成功添加专员或加入客户群的客户数,若同一个客户添加多个专员或客户群,只计算一个客户。在2022年3月10日以后才会有对应统计数据
70+
*/
71+
@SerializedName("upgrade_service_customer_cnt")
72+
private Integer upgradeServiceCustomerCnt;
73+
74+
/**
75+
* 智能回复会话数。客户发过消息并分配给智能助手的咨询会话数。通过API发消息或者开启智能回复功能会将客户分配给智能助手
76+
*/
77+
@SerializedName("ai_transfer_rate")
78+
private Integer aiSessionReplyCnt;
79+
80+
/**
81+
* 转人工率。一个自然日内,客户给智能助手发消息的会话中,转人工的会话的占比。
82+
*/
83+
@SerializedName("ai_transfer_rate")
84+
private Integer aiTransferRate;
85+
86+
/**
87+
* 知识命中率。一个自然日内,客户给智能助手发送的消息中,命中知识库的占比。只有在开启了智能回复原生功能并配置了知识库的情况下,才会产生该项统计数据。当api托管了会话分配,智能回复原生功能失效。若不返回,代表没有向配置知识库的智能接待助手发送消息,该项无法计算
88+
*/
89+
@SerializedName("ai_knowledge_hit_rate")
90+
private Integer aiKnowledgeHitRate;
91+
}
92+
93+
public static WxCpKfGetCorpStatisticResp fromJson(String json) {
94+
return WxCpGsonBuilder.create().fromJson(json, WxCpKfGetCorpStatisticResp.class);
95+
}
96+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

+1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ interface Kf {
328328

329329
String SEND_MSG_ON_EVENT = "/cgi-bin/kf/send_msg_on_event";
330330
String CUSTOMER_BATCH_GET = "/cgi-bin/kf/customer/batchget";
331+
String GET_CORP_STATISTIC = "/cgi-bin/kf/get_corp_statistic";
331332

332333
}
333334

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package me.chanjar.weixin.cp.util.json;
2+
3+
import com.google.gson.*;
4+
import me.chanjar.weixin.common.util.json.GsonHelper;
5+
import me.chanjar.weixin.cp.bean.kf.WxCpKfGetCorpStatisticResp;
6+
7+
import java.lang.reflect.Type;
8+
9+
/**
10+
* @author zhongjun
11+
* @date 2022/4/25
12+
**/
13+
public class StatisticListAdapter implements JsonDeserializer<WxCpKfGetCorpStatisticResp.StatisticList> {
14+
15+
@Override
16+
public WxCpKfGetCorpStatisticResp.StatisticList deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
17+
WxCpKfGetCorpStatisticResp.StatisticList statisticList = new WxCpKfGetCorpStatisticResp.StatisticList();
18+
JsonObject asJsonObject = jsonElement.getAsJsonObject();
19+
statisticList.setStatTime(asJsonObject.get("stat_time").getAsLong());
20+
JsonElement statistic = asJsonObject.get("statistic");
21+
if (GsonHelper.isNotNull(statistic)) {
22+
WxCpKfGetCorpStatisticResp.Statistic statisticObj = new WxCpKfGetCorpStatisticResp.Statistic();
23+
statisticObj.setSessionCnt(statistic.getAsJsonObject().get("session_cnt").getAsInt());
24+
statisticObj.setCustomerCnt(statistic.getAsJsonObject().get("customer_cnt").getAsInt());
25+
statisticObj.setCustomerMsgCnt(statistic.getAsJsonObject().get("customer_msg_cnt").getAsInt());
26+
statisticObj.setUpgradeServiceCustomerCnt(statistic.getAsJsonObject().get("upgrade_service_customer_cnt").getAsInt());
27+
statisticObj.setAiTransferRate(statistic.getAsJsonObject().get("ai_transfer_rate").getAsInt());
28+
statisticObj.setAiKnowledgeHitRate(statistic.getAsJsonObject().get("ai_knowledge_hit_rate").getAsInt());
29+
}
30+
return statisticList;
31+
}
32+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpGsonBuilder.java

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import me.chanjar.weixin.cp.bean.WxCpDepart;
1010
import me.chanjar.weixin.cp.bean.WxCpTag;
1111
import me.chanjar.weixin.cp.bean.WxCpUser;
12+
import me.chanjar.weixin.cp.bean.kf.WxCpKfGetCorpStatisticResp;
13+
1214
import java.util.Objects;
1315

1416
/**
@@ -27,6 +29,7 @@ public class WxCpGsonBuilder {
2729
INSTANCE.registerTypeAdapter(WxError.class, new WxErrorAdapter());
2830
INSTANCE.registerTypeAdapter(WxMenu.class, new WxCpMenuGsonAdapter());
2931
INSTANCE.registerTypeAdapter(WxCpTag.class, new WxCpTagGsonAdapter());
32+
INSTANCE.registerTypeAdapter(WxCpKfGetCorpStatisticResp.StatisticList.class, new StatisticListAdapter());
3033
}
3134

3235
public static Gson create() {

0 commit comments

Comments
 (0)