mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🆕 #2689【企业微信】增加获取用户填写答案的接口
This commit is contained in:
parent
508d053ed3
commit
bb8c82d25c
@ -3,6 +3,7 @@ package me.chanjar.weixin.cp.api;
|
||||
import lombok.NonNull;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetHealthReportStat;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportAnswer;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
|
||||
|
||||
@ -54,4 +55,20 @@ public interface WxCpSchoolHealthService {
|
||||
*/
|
||||
WxCpGetReportJobInfo getReportJobInfo(@NonNull String jobId, @NonNull String date) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取用户填写答案
|
||||
* 通过此接口可以获取指定的健康上报任务详情。
|
||||
* <p>
|
||||
* 请求方式:POST(HTTPS)
|
||||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/health/get_report_answer?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param jobId
|
||||
* @param date
|
||||
* @param offset
|
||||
* @param limit
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxCpGetReportAnswer getReportAnswer(@NonNull String jobId, @NonNull String date, Integer offset, Integer limit) throws WxErrorException;
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.WxCpSchoolHealthService;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetHealthReportStat;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportAnswer;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
|
||||
|
||||
@ -56,4 +57,20 @@ public class WxCpSchoolHealthServiceImpl implements WxCpSchoolHealthService {
|
||||
return WxCpGetReportJobInfo.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpGetReportAnswer getReportAnswer(@NonNull String jobId, @NonNull String date, Integer offset, Integer limit) throws WxErrorException {
|
||||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_REPORT_ANSWER);
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("jobid", jobId);
|
||||
jsonObject.addProperty("date", date);
|
||||
if (offset != null) {
|
||||
jsonObject.addProperty("offset", offset);
|
||||
}
|
||||
if (limit != null) {
|
||||
jsonObject.addProperty("limit", limit);
|
||||
}
|
||||
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
|
||||
return WxCpGetReportAnswer.fromJson(responseContent);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,96 @@
|
||||
package me.chanjar.weixin.cp.bean.school.health;
|
||||
|
||||
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 WxCpGetReportAnswer extends WxCpBaseResp implements Serializable {
|
||||
private static final long serialVersionUID = -5028321625142879581L;
|
||||
|
||||
@SerializedName("answers")
|
||||
private List<Answer> answers;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class Answer implements Serializable {
|
||||
private static final long serialVersionUID = -5696099236344075582L;
|
||||
|
||||
@SerializedName("userid")
|
||||
private String userId;
|
||||
|
||||
@SerializedName("id_type")
|
||||
private Integer idType;
|
||||
|
||||
@SerializedName("report_time")
|
||||
private Long reportTime;
|
||||
|
||||
@SerializedName("student_userid")
|
||||
private String studentUserId;
|
||||
|
||||
@SerializedName("parent_userid")
|
||||
private String parentUserId;
|
||||
|
||||
@SerializedName("report_values")
|
||||
private List<ReportValue> reportValues;
|
||||
|
||||
public static Answer fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, Answer.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class ReportValue implements Serializable {
|
||||
private static final long serialVersionUID = -5696099236344075582L;
|
||||
|
||||
@SerializedName("question_id")
|
||||
private Integer questionId;
|
||||
|
||||
@SerializedName("single_chose")
|
||||
private Integer singleChose;
|
||||
|
||||
@SerializedName("multi_choice")
|
||||
private List<Integer> multiChoice;
|
||||
|
||||
@SerializedName("text")
|
||||
private String text;
|
||||
|
||||
@SerializedName("fileid")
|
||||
private List<String> fileId;
|
||||
|
||||
public static ReportValue fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, ReportValue.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static WxCpGetReportAnswer fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportAnswer.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
@ -177,6 +177,7 @@ public interface WxCpApiPathConsts {
|
||||
String GET_HEALTH_REPORT_STAT = "/cgi-bin/health/get_health_report_stat";
|
||||
String GET_REPORT_JOBIDS = "/cgi-bin/health/get_report_jobids";
|
||||
String GET_REPORT_JOB_INFO = "/cgi-bin/health/get_report_job_info";
|
||||
String GET_REPORT_ANSWER = "/cgi-bin/health/get_report_answer";
|
||||
|
||||
String GET_TEACHER_CUSTOMIZE_HEALTH_INFO = "/cgi-bin/school/user/get_teacher_customize_health_info";
|
||||
String GET_STUDENT_CUSTOMIZE_HEALTH_INFO = "/cgi-bin/school/user/get_student_customize_health_info";
|
||||
|
@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetHealthReportStat;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportAnswer;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
|
||||
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
@ -39,6 +40,18 @@ public class WxCpSchoolHealthTest {
|
||||
String currDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
|
||||
|
||||
// Test
|
||||
String reportAnswerStr = "{\"errcode\":0,\"errmsg\":\"ok\",\"answers\":[{\"id_type\":1,\"userid\":\"userid2\",\"report_time\":123456789,\"report_values\":[{\"question_id\":1,\"single_choice\":2},{\"question_id\":2,\"text\":\"广东省广州市\"},{\"question_id\":3,\"multi_choice\":[1,3]},{\"question_id\":4,\"fileid\":[\"XXXXXXX\"]}]},{\"id_type\":2,\"student_userid\":\"student_userid1\",\"parent_userid\":\"parent_userid1\",\"report_time\":123456789,\"report_values\":[{\"question_id\":1,\"single_choice\":1},{\"question_id\":2,\"text\":\"广东省深圳市\"},{\"question_id\":3,\"multi_choice\":[1,2,3]},{\"question_id\":4,\"fileid\":[\"XXXXXXX\"]}]}]}";
|
||||
WxCpGetReportAnswer getReportAnswer = WxCpGetReportAnswer.fromJson(reportAnswerStr);
|
||||
log.info("获取对应的getReportAnswer:{}", getReportAnswer.toJson());
|
||||
|
||||
/**
|
||||
* 获取用户填写答案
|
||||
* https://developer.work.weixin.qq.com/document/path/93679
|
||||
*/
|
||||
WxCpGetReportAnswer reportAnswer = cpService.getSchoolHealthService().getReportAnswer("xxxx", currDate, null, null);
|
||||
log.info("返回的reportAnswer为:{}", reportAnswer.toJson());
|
||||
|
||||
/**
|
||||
* 获取健康上报任务ID列表
|
||||
* https://developer.work.weixin.qq.com/document/path/93677
|
||||
|
Loading…
Reference in New Issue
Block a user