Skip to content

Commit ce29529

Browse files
MsThinkbinarywang
authored andcommitted
🆕 #3016 【企业微信】增加获取客户数据统计接待人员明细数据的接口,并修复获取企业汇总数据接口返回值问题
1 parent b707ff5 commit ce29529

File tree

7 files changed

+244
-10
lines changed

7 files changed

+244
-10
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ WxCpKfCustomerBatchGetResp customerBatchGet(List<String> externalUserIdList)
203203
*/
204204
WxCpKfGetCorpStatisticResp getCorpStatistic(WxCpKfGetCorpStatisticRequest request) throws WxErrorException;
205205

206+
/**
207+
* <pre>
208+
* 获取「客户数据统计」接待人员明细数据
209+
* 通过此接口,可获取接入人工会话数、咨询会话数等与接待人员相关的统计信息
210+
* 请求方式:POST(HTTPS)
211+
* 请求地址:
212+
* <a href="https://qyapi.weixin.qq.com/cgi-bin/kf/get_servicer_statistic?access_token=ACCESS_TOKEN">https://qyapi.weixin.qq.com/cgi-bin/kf/get_servicer_statistic?access_token=ACCESS_TOKEN</a>
213+
* 文档地址:
214+
* <a href="https://developer.work.weixin.qq.com/document/path/95490">https://developer.work.weixin.qq.com/document/path/95490</a>
215+
* <pre>
216+
* @param request 查询参数
217+
* @return 客户数据统计 -企业汇总数据
218+
* @throws WxErrorException the wx error exception
219+
*/
220+
WxCpKfGetServicerStatisticResp getServicerStatistic(WxCpKfGetServicerStatisticRequest request) throws WxErrorException;
221+
206222
// 「升级服务」配置
207223

208224
/**

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,11 @@ public WxCpKfGetCorpStatisticResp getCorpStatistic(WxCpKfGetCorpStatisticRequest
271271
return WxCpKfGetCorpStatisticResp.fromJson(responseContent);
272272
}
273273

274+
@Override
275+
public WxCpKfGetServicerStatisticResp getServicerStatistic(WxCpKfGetServicerStatisticRequest request) throws WxErrorException {
276+
String url = cpService.getWxCpConfigStorage().getApiUrl(GET_SERVICER_STATISTIC);
277+
String responseContent = cpService.post(url, GSON.toJson(request));
278+
return WxCpKfGetServicerStatisticResp.fromJson(responseContent);
279+
}
280+
274281
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/kf/WxCpKfGetCorpStatisticResp.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static class Statistic {
6161
/**
6262
* 咨询客户数。在会话中发送过消息的客户数量,若客户多次咨询只计算一个客户
6363
*/
64-
@SerializedName("user_cnt")
64+
@SerializedName("customer_cnt")
6565
private Integer customerCnt;
6666

6767
/**
@@ -79,21 +79,27 @@ public static class Statistic {
7979
/**
8080
* 智能回复会话数。客户发过消息并分配给智能助手的咨询会话数。通过API发消息或者开启智能回复功能会将客户分配给智能助手
8181
*/
82-
@SerializedName("ai_transfer_rate")
82+
@SerializedName("ai_session_reply_cnt")
8383
private Integer aiSessionReplyCnt;
8484

8585
/**
8686
* 转人工率。一个自然日内,客户给智能助手发消息的会话中,转人工的会话的占比。
8787
*/
8888
@SerializedName("ai_transfer_rate")
89-
private Integer aiTransferRate;
89+
private Float aiTransferRate;
9090

9191
/**
9292
* 知识命中率。一个自然日内,客户给智能助手发送的消息中,命中知识库的占比。只有在开启了智能回复原生功能并配置了知识库的情况下,才会产生该项统计数据。当api
9393
* 托管了会话分配,智能回复原生功能失效。若不返回,代表没有向配置知识库的智能接待助手发送消息,该项无法计算
9494
*/
9595
@SerializedName("ai_knowledge_hit_rate")
96-
private Integer aiKnowledgeHitRate;
96+
private Float aiKnowledgeHitRate;
97+
98+
/**
99+
* 被拒收消息的客户数。被接待人员设置了“不再接收消息”的客户数
100+
*/
101+
@SerializedName("msg_rejected_customer_cnt")
102+
private Integer msgRejectedCustomerCnt;
97103
}
98104

99105
/**
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 MsThink created on 2023/5/13
11+
*/
12+
@NoArgsConstructor
13+
@Data
14+
public class WxCpKfGetServicerStatisticRequest {
15+
/**
16+
* 客服帐号ID
17+
*/
18+
@SerializedName("open_kfid")
19+
private String openKfId;
20+
21+
/**
22+
* 接待人员的userid。第三方应用为密文userid,即open_userid
23+
*/
24+
@SerializedName("servicer_userid")
25+
private String servicerUserid;
26+
27+
/**
28+
* 起始日期的时间戳,填这一天的0时0分0秒(否则系统自动处理为当天的0分0秒)。取值范围:昨天至前180天
29+
*/
30+
@SerializedName("start_time")
31+
private Long startTime;
32+
/**
33+
* 结束日期的时间戳,填这一天的0时0分0秒(否则系统自动处理为当天的0分0秒)。取值范围:昨天至前180天
34+
*/
35+
@SerializedName("end_time")
36+
private Long endTime;
37+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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 MsThink created on 2023/5/13
16+
*/
17+
@EqualsAndHashCode(callSuper = true)
18+
@NoArgsConstructor
19+
@Data
20+
public class WxCpKfGetServicerStatisticResp extends WxCpBaseResp {
21+
/**
22+
* 统计数据列表
23+
*/
24+
@SerializedName("statistic_list")
25+
private List<WxCpKfGetServicerStatisticResp.StatisticList> statisticList;
26+
27+
/**
28+
* The type Statistic list.
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 WxCpKfGetServicerStatisticResp.Statistic statistic;
44+
}
45+
46+
/**
47+
* The type Statistic.
48+
*/
49+
@NoArgsConstructor
50+
@Data
51+
public static class Statistic {
52+
53+
/**
54+
* 接入人工会话数。客户发过消息并分配给接待人员的咨询会话数
55+
*/
56+
@SerializedName("session_cnt")
57+
private Integer sessionCnt;
58+
59+
/**
60+
* 咨询客户数。在会话中发送过消息且接入了人工会话的客户数量,若客户多次咨询只计算一个客户
61+
*/
62+
@SerializedName("customer_cnt")
63+
private Integer customerCnt;
64+
65+
/**
66+
* 咨询消息总数。客户在会话中发送的消息的数量
67+
*/
68+
@SerializedName("customer_msg_cnt")
69+
private Integer customerMsgCnt;
70+
71+
/**
72+
* 人工回复率。一个自然日内,客户给接待人员发消息的会话中,接待人员回复了的会话的占比。若数据项不返回,代表没有给接待人员发送消息的客户,此项无法计算。
73+
*/
74+
@SerializedName("reply_rate")
75+
private Float replyRate;
76+
77+
/**
78+
* 平均首次响应时长,单位:秒。一个自然日内,客户给接待人员发送的第一条消息至接待人员回复之间的时长,为首次响应时长。所有的首次回复总时长/已回复的咨询会话数,
79+
* 即为平均首次响应时长 。若数据项不返回,代表没有给接待人员发送消息的客户,此项无法计算
80+
*/
81+
@SerializedName("first_reply_average_sec")
82+
private Float firstReplyAverageSec;
83+
84+
/**
85+
* 满意度评价发送数。当api托管了会话分配,满意度原生功能失效,满意度评价发送数为0
86+
*/
87+
@SerializedName("satisfaction_investgate_cnt")
88+
private Integer satisfactionInvestgateCnt;
89+
90+
/**
91+
* 满意度参评率 。当api托管了会话分配,满意度原生功能失效。若数据项不返回,代表没有发送满意度评价,此项无法计算
92+
*/
93+
@SerializedName("satisfaction_participation_rate")
94+
private Float satisfactionParticipationRate;
95+
96+
/**
97+
* “满意”评价占比 。在客户参评的满意度评价中,评价是“满意”的占比。当api托管了会话分配,满意度原生功能失效。若数据项不返回,代表没有客户参评的满意度评价,此项无法计算
98+
*/
99+
@SerializedName("satisfied_rate")
100+
private Float satisfiedRate;
101+
102+
/**
103+
* “一般”评价占比 。在客户参评的满意度评价中,评价是“一般”的占比。当api托管了会话分配,满意度原生功能失效。若数据项不返回,代表没有客户参评的满意度评价,此项无法计算
104+
*/
105+
@SerializedName("middling_rate")
106+
private Float middlingRate;
107+
108+
/**
109+
* “不满意”评价占比。在客户参评的满意度评价中,评价是“不满意”的占比。当api托管了会话分配,满意度原生功能失效。若数据项不返回,代表没有客户参评的满意度评价,此项无法计算
110+
*/
111+
@SerializedName("dissatisfied_rate")
112+
private Float dissatisfiedRate;
113+
114+
/**
115+
* 升级服务客户数。通过「升级服务」功能成功添加专员或加入客户群的客户数,若同一个客户添加多个专员或客户群,只计算一个客户。在2022年3月10日以后才会有对应统计数据
116+
*/
117+
@SerializedName("upgrade_service_customer_cnt")
118+
private Integer upgradeServiceCustomerCnt;
119+
120+
/**
121+
* 专员服务邀请数。接待人员通过「升级服务-专员服务」向客户发送服务专员名片的次数。在2022年3月10日以后才会有对应统计数据
122+
*/
123+
@SerializedName("upgrade_service_member_invite_cnt")
124+
private Integer upgradeServiceMemberInviteCnt;
125+
126+
/**
127+
* 添加专员的客户数 。客户成功添加专员为好友的数量,若同一个客户添加多个专员,则计算多个客户数。在2022年3月10日以后才会有对应统计数据
128+
*/
129+
@SerializedName("upgrade_service_member_customer_cnt")
130+
private Integer upgradeServiceMemberCustomerCnt;
131+
132+
/**
133+
* 客户群服务邀请数。接待人员通过「升级服务-客户群服务」向客户发送客户群二维码的次数。在2022年3月10日以后才会有对应统计数据
134+
*/
135+
@SerializedName("upgrade_service_groupchat_invite_cnt")
136+
private Integer upgradeServiceGroupchatInviteCnt;
137+
138+
/**
139+
* 加入客户群的客户数。客户成功加入客户群的数量,若同一个客户加多个客户群,则计算多个客户数。在2022年3月10日以后才会有对应统计数据
140+
*/
141+
@SerializedName("upgrade_service_groupchat_customer_cnt")
142+
private Integer upgradeServiceGroupchatCustomerCnt;
143+
144+
/**
145+
* 被拒收消息的客户数。被接待人员设置了“不再接收消息”的客户数
146+
*/
147+
@SerializedName("msg_rejected_customer_cnt")
148+
private Integer msgRejectedCustomerCnt;
149+
}
150+
/**
151+
* From json wx cp kf get servicer statistic resp.
152+
*
153+
* @param json the json
154+
* @return the wx cp kf get servicer statistic resp
155+
*/
156+
public static WxCpKfGetServicerStatisticResp fromJson(String json) {
157+
return WxCpGsonBuilder.create().fromJson(json, WxCpKfGetServicerStatisticResp.class);
158+
}
159+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,12 @@ interface Kf {
13641364
* The constant GET_CORP_STATISTIC.
13651365
*/
13661366
String GET_CORP_STATISTIC = "/cgi-bin/kf/get_corp_statistic";
1367+
1368+
/**
1369+
* The constant GET_SERVICER_STATISTIC.
1370+
*/
1371+
String GET_SERVICER_STATISTIC = "/cgi-bin/kf/get_servicer_statistic";
1372+
13671373
/**
13681374
* The constant CUSTOMER_GET_UPGRADE_SERVICE_CONFIG.
13691375
*/

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ public WxCpKfGetCorpStatisticResp.StatisticList deserialize(JsonElement jsonElem
2222
JsonElement statistic = asJsonObject.get("statistic");
2323
if (GsonHelper.isNotNull(statistic)) {
2424
WxCpKfGetCorpStatisticResp.Statistic statisticObj = new WxCpKfGetCorpStatisticResp.Statistic();
25-
statisticObj.setSessionCnt(statistic.getAsJsonObject().get("session_cnt").getAsInt());
26-
statisticObj.setCustomerCnt(statistic.getAsJsonObject().get("customer_cnt").getAsInt());
27-
statisticObj.setCustomerMsgCnt(statistic.getAsJsonObject().get("customer_msg_cnt").getAsInt());
28-
statisticObj.setUpgradeServiceCustomerCnt(statistic.getAsJsonObject().get("upgrade_service_customer_cnt").getAsInt());
29-
statisticObj.setAiTransferRate(statistic.getAsJsonObject().get("ai_transfer_rate").getAsInt());
30-
statisticObj.setAiKnowledgeHitRate(statistic.getAsJsonObject().get("ai_knowledge_hit_rate").getAsInt());
25+
statisticObj.setSessionCnt(GsonHelper.isNull(statistic.getAsJsonObject().get("session_cnt")) ? null : statistic.getAsJsonObject().get("session_cnt").getAsInt());
26+
statisticObj.setCustomerCnt(GsonHelper.isNull(statistic.getAsJsonObject().get("customer_cnt")) ? null : statistic.getAsJsonObject().get("customer_cnt").getAsInt());
27+
statisticObj.setCustomerMsgCnt(GsonHelper.isNull(statistic.getAsJsonObject().get("customer_msg_cnt")) ? null : statistic.getAsJsonObject().get("customer_msg_cnt").getAsInt());
28+
statisticObj.setUpgradeServiceCustomerCnt(GsonHelper.isNull(statistic.getAsJsonObject().get("upgrade_service_customer_cnt")) ? null : statistic.getAsJsonObject().get("upgrade_service_customer_cnt").getAsInt());
29+
statisticObj.setAiSessionReplyCnt(GsonHelper.isNull(statistic.getAsJsonObject().get("ai_session_reply_cnt")) ? null : statistic.getAsJsonObject().get("ai_session_reply_cnt").getAsInt());
30+
statisticObj.setAiTransferRate(GsonHelper.isNull(statistic.getAsJsonObject().get("ai_transfer_rate")) ? null : statistic.getAsJsonObject().get("ai_transfer_rate").getAsFloat());
31+
statisticObj.setAiKnowledgeHitRate(GsonHelper.isNull(statistic.getAsJsonObject().get("ai_knowledge_hit_rate")) ? null : statistic.getAsJsonObject().get("ai_knowledge_hit_rate").getAsFloat());
32+
statisticObj.setMsgRejectedCustomerCnt(GsonHelper.isNull(statistic.getAsJsonObject().get("msg_rejected_customer_cnt")) ? null : statistic.getAsJsonObject().get("msg_rejected_customer_cnt").getAsInt());
33+
statisticList.setStatistic(statisticObj);
3134
}
3235
return statisticList;
3336
}

0 commit comments

Comments
 (0)