Skip to content

Commit d5c6803

Browse files
authored
🆕 #2698【企业微信】增加家校应用-上课直播相关接口
1 parent 5ac2e69 commit d5c6803

12 files changed

+446
-20
lines changed

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpLivingService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface WxCpLivingService {
4848
* @return
4949
* @throws WxErrorException
5050
*/
51-
WxCpWatchStat getWatchStat(@NonNull String livingId, Integer nextKey) throws WxErrorException;
51+
WxCpWatchStat getWatchStat(@NonNull String livingId, String nextKey) throws WxErrorException;
5252

5353
/**
5454
* 获取成员直播ID列表

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolService.java

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

3+
import lombok.NonNull;
34
import me.chanjar.weixin.common.error.WxErrorException;
4-
import me.chanjar.weixin.cp.bean.school.WxCpCustomizeHealthInfo;
5-
import me.chanjar.weixin.cp.bean.school.WxCpPaymentResult;
6-
import me.chanjar.weixin.cp.bean.school.WxCpResultList;
7-
import me.chanjar.weixin.cp.bean.school.WxCpTrade;
5+
import me.chanjar.weixin.cp.bean.living.WxCpLivingResult;
6+
import me.chanjar.weixin.cp.bean.school.*;
87

98
import javax.validation.constraints.NotNull;
109
import java.util.List;
@@ -82,4 +81,68 @@ public interface WxCpSchoolService {
8281
*/
8382
WxCpTrade getTrade(@NotNull String paymentId, @NotNull String tradeNo) throws WxErrorException;
8483

84+
/**
85+
* 获取直播详情
86+
* 请求方式:GET(HTTPS)
87+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/living/get_living_info?access_token=ACCESS_TOKEN&livingid=LIVINGID
88+
*
89+
* @param livingId
90+
* @return
91+
*/
92+
WxCpSchoolLivingInfo getLivingInfo(@NotNull String livingId) throws WxErrorException;
93+
94+
/**
95+
* 获取老师直播ID列表
96+
* 通过此接口可以获取指定老师的所有直播ID
97+
* <p>
98+
* 请求方式:POST(HTTPS)
99+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/living/get_user_all_livingid?access_token=ACCESS_TOKEN
100+
*
101+
* @param userId
102+
* @param cursor
103+
* @param limit
104+
* @return
105+
* @throws WxErrorException
106+
*/
107+
WxCpLivingResult.LivingIdResult getUserAllLivingId(@NonNull String userId, String cursor, Integer limit) throws WxErrorException;
108+
109+
/**
110+
* 获取观看直播统计
111+
* 通过该接口可以获取所有观看直播的人员统计
112+
* <p>
113+
* 请求方式:POST(HTTPS)
114+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/living/get_watch_stat?access_token=ACCESS_TOKEN
115+
*
116+
* @param livingId
117+
* @param nextKey
118+
* @return
119+
* @throws WxErrorException
120+
*/
121+
WxCpSchoolWatchStat getWatchStat(@NonNull String livingId, String nextKey) throws WxErrorException;
122+
123+
/**
124+
* 获取未观看直播统计
125+
* 通过该接口可以获取未观看直播的学生统计,学生的家长必须是已经关注「学校通知」才会纳入统计范围。
126+
* <p>
127+
* 请求方式:POST(HTTPS)
128+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/living/get_unwatch_stat?access_token=ACCESS_TOKEN
129+
*
130+
* @param livingId
131+
* @param nextKey
132+
* @return
133+
* @throws WxErrorException
134+
*/
135+
WxCpSchoolUnwatchStat getUnwatchStat(@NonNull String livingId, String nextKey) throws WxErrorException;
136+
137+
/**
138+
* 删除直播回放
139+
* 请求方式: POST(HTTPS)
140+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/living/delete_replay_data?access_token=ACCESS_TOKEN
141+
*
142+
* @param livingId
143+
* @return
144+
* @throws WxErrorException
145+
*/
146+
WxCpLivingResult deleteReplayData(@NonNull String livingId) throws WxErrorException;
147+
85148
}

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpLivingServiceImpl.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
import me.chanjar.weixin.cp.api.WxCpService;
1313
import me.chanjar.weixin.cp.bean.living.*;
1414
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
15+
import org.apache.commons.lang3.StringUtils;
1516

1617
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Living.*;
1718

1819
/**
1920
* 企业微信直播接口实现类.
21+
* https://developer.work.weixin.qq.com/document/path/93633
2022
*
21-
* @author Wang_Wong
23+
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
2224
* @date 2021-12-21
2325
*/
2426
@Slf4j
@@ -48,11 +50,11 @@ public WxCpLivingInfo getLivingInfo(String livingId) throws WxErrorException {
4850
}
4951

5052
@Override
51-
public WxCpWatchStat getWatchStat(String livingId, Integer nextKey) throws WxErrorException {
53+
public WxCpWatchStat getWatchStat(String livingId, String nextKey) throws WxErrorException {
5254
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_WATCH_STAT);
5355
JsonObject jsonObject = new JsonObject();
54-
if (nextKey != null) {
55-
jsonObject.addProperty("next_key", String.valueOf(nextKey));
56+
if (StringUtils.isNotBlank(nextKey)) {
57+
jsonObject.addProperty("next_key", nextKey);
5658
}
5759
jsonObject.addProperty("livingid", livingId);
5860
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolServiceImpl.java

+45-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package me.chanjar.weixin.cp.api.impl;
22

33
import com.google.gson.JsonObject;
4+
import lombok.NonNull;
45
import lombok.RequiredArgsConstructor;
56
import lombok.extern.slf4j.Slf4j;
67
import me.chanjar.weixin.common.error.WxErrorException;
78
import me.chanjar.weixin.cp.api.WxCpSchoolService;
89
import me.chanjar.weixin.cp.api.WxCpService;
9-
import me.chanjar.weixin.cp.bean.school.WxCpCustomizeHealthInfo;
10-
import me.chanjar.weixin.cp.bean.school.WxCpPaymentResult;
11-
import me.chanjar.weixin.cp.bean.school.WxCpResultList;
12-
import me.chanjar.weixin.cp.bean.school.WxCpTrade;
10+
import me.chanjar.weixin.cp.bean.living.WxCpLivingResult;
11+
import me.chanjar.weixin.cp.bean.school.*;
12+
import org.apache.commons.lang3.StringUtils;
1313

1414
import javax.validation.constraints.NotNull;
1515
import java.util.List;
@@ -85,4 +85,45 @@ public WxCpTrade getTrade(@NotNull String paymentId, @NotNull String tradeNo) th
8585
return WxCpTrade.fromJson(responseContent);
8686
}
8787

88+
@Override
89+
public WxCpSchoolLivingInfo getLivingInfo(@NotNull String livingId) throws WxErrorException {
90+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_LIVING_INFO) + livingId;
91+
String responseContent = this.cpService.get(apiUrl, null);
92+
return WxCpSchoolLivingInfo.fromJson(responseContent);
93+
}
94+
95+
@Override
96+
public WxCpLivingResult.LivingIdResult getUserAllLivingId(@NonNull String userId, String cursor, Integer limit) throws WxErrorException {
97+
return this.cpService.getLivingService().getUserAllLivingId(userId, cursor, limit);
98+
}
99+
100+
@Override
101+
public WxCpSchoolWatchStat getWatchStat(@NonNull String livingId, String nextKey) throws WxErrorException {
102+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_WATCH_STAT);
103+
JsonObject jsonObject = new JsonObject();
104+
if (StringUtils.isNotBlank(nextKey)) {
105+
jsonObject.addProperty("next_key", nextKey);
106+
}
107+
jsonObject.addProperty("livingid", livingId);
108+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
109+
return WxCpSchoolWatchStat.fromJson(responseContent);
110+
}
111+
112+
@Override
113+
public WxCpSchoolUnwatchStat getUnwatchStat(@NonNull String livingId, String nextKey) throws WxErrorException {
114+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_UNWATCH_STAT);
115+
JsonObject jsonObject = new JsonObject();
116+
if (StringUtils.isNotBlank(nextKey)) {
117+
jsonObject.addProperty("next_key", nextKey);
118+
}
119+
jsonObject.addProperty("livingid", livingId);
120+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
121+
return WxCpSchoolUnwatchStat.fromJson(responseContent);
122+
}
123+
124+
@Override
125+
public WxCpLivingResult deleteReplayData(@NonNull String livingId) throws WxErrorException {
126+
return cpService.getLivingService().deleteReplayData(livingId);
127+
}
128+
88129
}

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/living/WxCpLivingInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class WxCpLivingInfo implements Serializable {
2222
private Long livingStart;
2323

2424
@SerializedName("living_duration")
25-
private Long livingDurationme;
25+
private Long livingDuration;
2626

2727
@SerializedName("status")
2828
private Integer status;

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/living/WxCpLivingResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static class LivingIdResult implements Serializable {
3232
private String nextCursor;
3333

3434
@SerializedName("livingid_list")
35-
private String[] livingidList;
35+
private String[] livingIdList;
3636

3737
public static LivingIdResult fromJson(String json) {
3838
return WxCpGsonBuilder.create().fromJson(json, LivingIdResult.class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package me.chanjar.weixin.cp.bean.school;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.io.Serializable;
11+
import java.util.List;
12+
13+
/**
14+
* 获取直播详情.
15+
*
16+
* @author Wang_Wong
17+
*/
18+
@Data
19+
public class WxCpSchoolLivingInfo extends WxCpBaseResp implements Serializable {
20+
private static final long serialVersionUID = -5028321625140879571L;
21+
22+
@SerializedName("living_info")
23+
private LivingInfo livingInfo;
24+
25+
@Getter
26+
@Setter
27+
public static class LivingInfo implements Serializable {
28+
29+
@SerializedName("theme")
30+
private String theme;
31+
32+
@SerializedName("living_start")
33+
private Long livingStart;
34+
35+
@SerializedName("living_duration")
36+
private Long livingDuration;
37+
38+
@SerializedName("anchor_userid")
39+
private String anchorUserId;
40+
41+
@SerializedName("living_range")
42+
private LivingRange livingRange;
43+
44+
@SerializedName("viewer_num")
45+
private Integer viewerNum;
46+
47+
@SerializedName("comment_num")
48+
private Integer commentNum;
49+
50+
@SerializedName("open_replay")
51+
private Integer openReplay;
52+
53+
@SerializedName("push_stream_url")
54+
private String pushStreamUrl;
55+
56+
public static LivingInfo fromJson(String json) {
57+
return WxCpGsonBuilder.create().fromJson(json, LivingInfo.class);
58+
}
59+
60+
public String toJson() {
61+
return WxCpGsonBuilder.create().toJson(this);
62+
}
63+
64+
}
65+
66+
@Getter
67+
@Setter
68+
public static class LivingRange implements Serializable {
69+
70+
@SerializedName("partyids")
71+
private List<Integer> partyIds;
72+
73+
@SerializedName("group_names")
74+
private List<String> groupNames;
75+
76+
public static LivingRange fromJson(String json) {
77+
return WxCpGsonBuilder.create().fromJson(json, LivingRange.class);
78+
}
79+
80+
public String toJson() {
81+
return WxCpGsonBuilder.create().toJson(this);
82+
}
83+
84+
}
85+
86+
public static WxCpSchoolLivingInfo fromJson(String json) {
87+
return WxCpGsonBuilder.create().fromJson(json, WxCpSchoolLivingInfo.class);
88+
}
89+
90+
public String toJson() {
91+
return WxCpGsonBuilder.create().toJson(this);
92+
}
93+
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package me.chanjar.weixin.cp.bean.school;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.io.Serializable;
11+
import java.util.List;
12+
13+
/**
14+
* 获取未观看直播统计
15+
*
16+
* @author Wang_Wong
17+
*/
18+
@Data
19+
public class WxCpSchoolUnwatchStat extends WxCpBaseResp {
20+
private static final long serialVersionUID = -5028321625140879571L;
21+
22+
@SerializedName("ending")
23+
private Integer ending;
24+
25+
@SerializedName("next_key")
26+
private String nextKey;
27+
28+
@SerializedName("stat_info")
29+
private StatInfo statInfo;
30+
31+
@Getter
32+
@Setter
33+
public static class StatInfo implements Serializable {
34+
private static final long serialVersionUID = -5696099236344075582L;
35+
36+
@SerializedName("students")
37+
private List<Student> students;
38+
39+
}
40+
41+
@Getter
42+
@Setter
43+
public static class Student implements Serializable {
44+
private static final long serialVersionUID = -5696099236344075582L;
45+
46+
@SerializedName("student_userid")
47+
private String studentUserId;
48+
49+
@SerializedName("parent_userid")
50+
private String parentUserId;
51+
52+
@SerializedName("partyids")
53+
private List<Integer> partyIds;
54+
55+
}
56+
57+
public static WxCpSchoolUnwatchStat fromJson(String json) {
58+
return WxCpGsonBuilder.create().fromJson(json, WxCpSchoolUnwatchStat.class);
59+
}
60+
61+
public String toJson() {
62+
return WxCpGsonBuilder.create().toJson(this);
63+
}
64+
65+
}

0 commit comments

Comments
 (0)