Skip to content

Commit

Permalink
🆕 #2698【企业微信】增加家校应用-上课直播相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
0katekate0 authored Jun 20, 2022
1 parent 5ac2e69 commit d5c6803
Show file tree
Hide file tree
Showing 12 changed files with 446 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface WxCpLivingService {
* @return
* @throws WxErrorException
*/
WxCpWatchStat getWatchStat(@NonNull String livingId, Integer nextKey) throws WxErrorException;
WxCpWatchStat getWatchStat(@NonNull String livingId, String nextKey) throws WxErrorException;

/**
* 获取成员直播ID列表
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package me.chanjar.weixin.cp.api;

import lombok.NonNull;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.school.WxCpCustomizeHealthInfo;
import me.chanjar.weixin.cp.bean.school.WxCpPaymentResult;
import me.chanjar.weixin.cp.bean.school.WxCpResultList;
import me.chanjar.weixin.cp.bean.school.WxCpTrade;
import me.chanjar.weixin.cp.bean.living.WxCpLivingResult;
import me.chanjar.weixin.cp.bean.school.*;

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

/**
* 获取直播详情
* 请求方式:GET(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/living/get_living_info?access_token=ACCESS_TOKEN&livingid=LIVINGID
*
* @param livingId
* @return
*/
WxCpSchoolLivingInfo getLivingInfo(@NotNull String livingId) throws WxErrorException;

/**
* 获取老师直播ID列表
* 通过此接口可以获取指定老师的所有直播ID
* <p>
* 请求方式:POST(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/living/get_user_all_livingid?access_token=ACCESS_TOKEN
*
* @param userId
* @param cursor
* @param limit
* @return
* @throws WxErrorException
*/
WxCpLivingResult.LivingIdResult getUserAllLivingId(@NonNull String userId, String cursor, Integer limit) throws WxErrorException;

/**
* 获取观看直播统计
* 通过该接口可以获取所有观看直播的人员统计
* <p>
* 请求方式:POST(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/living/get_watch_stat?access_token=ACCESS_TOKEN
*
* @param livingId
* @param nextKey
* @return
* @throws WxErrorException
*/
WxCpSchoolWatchStat getWatchStat(@NonNull String livingId, String nextKey) throws WxErrorException;

/**
* 获取未观看直播统计
* 通过该接口可以获取未观看直播的学生统计,学生的家长必须是已经关注「学校通知」才会纳入统计范围。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/living/get_unwatch_stat?access_token=ACCESS_TOKEN
*
* @param livingId
* @param nextKey
* @return
* @throws WxErrorException
*/
WxCpSchoolUnwatchStat getUnwatchStat(@NonNull String livingId, String nextKey) throws WxErrorException;

/**
* 删除直播回放
* 请求方式: POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/living/delete_replay_data?access_token=ACCESS_TOKEN
*
* @param livingId
* @return
* @throws WxErrorException
*/
WxCpLivingResult deleteReplayData(@NonNull String livingId) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.living.*;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import org.apache.commons.lang3.StringUtils;

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

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

@Override
public WxCpWatchStat getWatchStat(String livingId, Integer nextKey) throws WxErrorException {
public WxCpWatchStat getWatchStat(String livingId, String nextKey) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_WATCH_STAT);
JsonObject jsonObject = new JsonObject();
if (nextKey != null) {
jsonObject.addProperty("next_key", String.valueOf(nextKey));
if (StringUtils.isNotBlank(nextKey)) {
jsonObject.addProperty("next_key", nextKey);
}
jsonObject.addProperty("livingid", livingId);
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package me.chanjar.weixin.cp.api.impl;

import com.google.gson.JsonObject;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpSchoolService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.school.WxCpCustomizeHealthInfo;
import me.chanjar.weixin.cp.bean.school.WxCpPaymentResult;
import me.chanjar.weixin.cp.bean.school.WxCpResultList;
import me.chanjar.weixin.cp.bean.school.WxCpTrade;
import me.chanjar.weixin.cp.bean.living.WxCpLivingResult;
import me.chanjar.weixin.cp.bean.school.*;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;
import java.util.List;
Expand Down Expand Up @@ -85,4 +85,45 @@ public WxCpTrade getTrade(@NotNull String paymentId, @NotNull String tradeNo) th
return WxCpTrade.fromJson(responseContent);
}

@Override
public WxCpSchoolLivingInfo getLivingInfo(@NotNull String livingId) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_LIVING_INFO) + livingId;
String responseContent = this.cpService.get(apiUrl, null);
return WxCpSchoolLivingInfo.fromJson(responseContent);
}

@Override
public WxCpLivingResult.LivingIdResult getUserAllLivingId(@NonNull String userId, String cursor, Integer limit) throws WxErrorException {
return this.cpService.getLivingService().getUserAllLivingId(userId, cursor, limit);
}

@Override
public WxCpSchoolWatchStat getWatchStat(@NonNull String livingId, String nextKey) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_WATCH_STAT);
JsonObject jsonObject = new JsonObject();
if (StringUtils.isNotBlank(nextKey)) {
jsonObject.addProperty("next_key", nextKey);
}
jsonObject.addProperty("livingid", livingId);
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpSchoolWatchStat.fromJson(responseContent);
}

@Override
public WxCpSchoolUnwatchStat getUnwatchStat(@NonNull String livingId, String nextKey) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_UNWATCH_STAT);
JsonObject jsonObject = new JsonObject();
if (StringUtils.isNotBlank(nextKey)) {
jsonObject.addProperty("next_key", nextKey);
}
jsonObject.addProperty("livingid", livingId);
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpSchoolUnwatchStat.fromJson(responseContent);
}

@Override
public WxCpLivingResult deleteReplayData(@NonNull String livingId) throws WxErrorException {
return cpService.getLivingService().deleteReplayData(livingId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class WxCpLivingInfo implements Serializable {
private Long livingStart;

@SerializedName("living_duration")
private Long livingDurationme;
private Long livingDuration;

@SerializedName("status")
private Integer status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static class LivingIdResult implements Serializable {
private String nextCursor;

@SerializedName("livingid_list")
private String[] livingidList;
private String[] livingIdList;

public static LivingIdResult fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, LivingIdResult.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package me.chanjar.weixin.cp.bean.school;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
* 获取直播详情.
*
* @author Wang_Wong
*/
@Data
public class WxCpSchoolLivingInfo extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625140879571L;

@SerializedName("living_info")
private LivingInfo livingInfo;

@Getter
@Setter
public static class LivingInfo implements Serializable {

@SerializedName("theme")
private String theme;

@SerializedName("living_start")
private Long livingStart;

@SerializedName("living_duration")
private Long livingDuration;

@SerializedName("anchor_userid")
private String anchorUserId;

@SerializedName("living_range")
private LivingRange livingRange;

@SerializedName("viewer_num")
private Integer viewerNum;

@SerializedName("comment_num")
private Integer commentNum;

@SerializedName("open_replay")
private Integer openReplay;

@SerializedName("push_stream_url")
private String pushStreamUrl;

public static LivingInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, LivingInfo.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

@Getter
@Setter
public static class LivingRange implements Serializable {

@SerializedName("partyids")
private List<Integer> partyIds;

@SerializedName("group_names")
private List<String> groupNames;

public static LivingRange fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, LivingRange.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

public static WxCpSchoolLivingInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSchoolLivingInfo.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package me.chanjar.weixin.cp.bean.school;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
* 获取未观看直播统计
*
* @author Wang_Wong
*/
@Data
public class WxCpSchoolUnwatchStat extends WxCpBaseResp {
private static final long serialVersionUID = -5028321625140879571L;

@SerializedName("ending")
private Integer ending;

@SerializedName("next_key")
private String nextKey;

@SerializedName("stat_info")
private StatInfo statInfo;

@Getter
@Setter
public static class StatInfo implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;

@SerializedName("students")
private List<Student> students;

}

@Getter
@Setter
public static class Student implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;

@SerializedName("student_userid")
private String studentUserId;

@SerializedName("parent_userid")
private String parentUserId;

@SerializedName("partyids")
private List<Integer> partyIds;

}

public static WxCpSchoolUnwatchStat fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSchoolUnwatchStat.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Loading

0 comments on commit d5c6803

Please sign in to comment.