mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
#698 企业微信增加OA数据接口
This commit is contained in:
@@ -28,6 +28,11 @@ public interface WxCpChatService {
|
||||
*/
|
||||
String chatCreate(String name, String owner, List<String> users, String chatId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* chatCreate 同名方法
|
||||
*/
|
||||
String create(String name, String owner, List<String> users, String chatId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 修改群聊会话.
|
||||
*
|
||||
@@ -40,6 +45,11 @@ public interface WxCpChatService {
|
||||
*/
|
||||
void chatUpdate(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* chatUpdate 同名方法
|
||||
*/
|
||||
void update(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取群聊会话.
|
||||
*
|
||||
@@ -49,6 +59,11 @@ public interface WxCpChatService {
|
||||
*/
|
||||
WxCpChat chatGet(String chatId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* chatGet 同名方法
|
||||
*/
|
||||
WxCpChat get(String chatId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 应用支持推送文本、图片、视频、文件、图文等类型.
|
||||
* 请求方式: POST(HTTPS)
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.bean.WxCpApprovalDataResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpCheckinData;
|
||||
import me.chanjar.weixin.cp.bean.WxCpCheckinOption;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDialRecord;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Element
|
||||
* @Package me.chanjar.weixin.cp.api
|
||||
* @date 2019-04-06 10:52
|
||||
* @Description: <pre>
|
||||
* 企业微信OA相关接口
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
public interface WxCpOAService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取打卡数据
|
||||
* API doc : https://work.weixin.qq.com/api/doc#90000/90135/90262
|
||||
* </pre>
|
||||
*
|
||||
* @param openCheckinDataType 打卡类型。1:上下班打卡;2:外出打卡;3:全部打卡
|
||||
* @param starttime 获取打卡记录的开始时间
|
||||
* @param endtime 获取打卡记录的结束时间
|
||||
* @param userIdList 需要获取打卡记录的用户列表
|
||||
*/
|
||||
List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date starttime, Date endtime, List<String> userIdList) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取打卡规则
|
||||
* API doc : https://work.weixin.qq.com/api/doc#90000/90135/90263
|
||||
* </pre>
|
||||
*
|
||||
* @param datetime 需要获取规则的当天日期
|
||||
* @param userIdList 需要获取打卡规则的用户列表
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
List<WxCpCheckinOption> getCheckinOption(Date datetime, List<String> userIdList) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取审批数据
|
||||
* 通过本接口来获取公司一段时间内的审批记录。一次拉取调用最多拉取10000个审批记录,可以通过多次拉取的方式来满足需求,但调用频率不可超过600次/分。
|
||||
* API doc : https://work.weixin.qq.com/api/doc#90000/90135/91530
|
||||
* </pre>
|
||||
*
|
||||
* @param starttime 获取审批记录的开始时间
|
||||
* @param endtime 获取审批记录的结束时间
|
||||
* @param nextSpnum 第一个拉取的审批单号,不填从该时间段的第一个审批单拉取
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxCpApprovalDataResult getApprovalData(Date starttime, Date endtime, Long nextSpnum) throws WxErrorException;
|
||||
|
||||
List<WxCpDialRecord> getDialRecord(Date starttime, Date endtime, Integer offset, Integer limit) throws WxErrorException;
|
||||
|
||||
}
|
||||
@@ -303,6 +303,8 @@ public interface WxCpService {
|
||||
|
||||
WxCpAgentService getAgentService();
|
||||
|
||||
WxCpOAService getOAService();
|
||||
|
||||
/**
|
||||
* http请求对象
|
||||
*/
|
||||
|
||||
@@ -45,6 +45,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
|
||||
private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this);
|
||||
private WxCpTagService tagService = new WxCpTagServiceImpl(this);
|
||||
private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
|
||||
private WxCpOAService oaService = new WxCpOAServiceImpl(this);
|
||||
|
||||
/**
|
||||
* 全局的是否正在刷新access token的锁
|
||||
@@ -386,6 +387,11 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
|
||||
return chatService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpOAService getOAService() {
|
||||
return oaService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestHttp<?, ?> getRequestHttp() {
|
||||
return this;
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
package me.chanjar.weixin.cp.api.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
@@ -14,6 +8,11 @@ import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpAppChatMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpChat;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 群聊服务实现.
|
||||
@@ -52,6 +51,11 @@ public class WxCpChatServiceImpl implements WxCpChatService {
|
||||
return new JsonParser().parse(result).getAsJsonObject().get("chatid").getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String create(String name, String owner, List<String> users, String chatId) throws WxErrorException {
|
||||
return chatCreate(name, owner, users, chatId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chatUpdate(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete)
|
||||
throws WxErrorException {
|
||||
@@ -75,6 +79,11 @@ public class WxCpChatServiceImpl implements WxCpChatService {
|
||||
this.cpService.post(APPCHAT_UPDATE, WxGsonBuilder.create().toJson(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete) throws WxErrorException {
|
||||
chatUpdate(chatId, name, owner, usersToAdd, usersToDelete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpChat chatGet(String chatId) throws WxErrorException {
|
||||
String result = this.cpService.get(APPCHAT_GET_CHATID + chatId, null);
|
||||
@@ -82,6 +91,11 @@ public class WxCpChatServiceImpl implements WxCpChatService {
|
||||
.fromJson(JSON_PARSER.parse(result).getAsJsonObject().getAsJsonObject("chat_info").toString(), WxCpChat.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpChat get(String chatId) throws WxErrorException {
|
||||
return chatGet(chatId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMsg(WxCpAppChatMessage message) throws WxErrorException {
|
||||
this.cpService.post("https://qyapi.weixin.qq.com/cgi-bin/appchat/send", message.toJson());
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
package me.chanjar.weixin.cp.api.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.WxCpOAService;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpApprovalDataResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpCheckinData;
|
||||
import me.chanjar.weixin.cp.bean.WxCpCheckinOption;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDialRecord;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Element
|
||||
* @Package me.chanjar.weixin.cp.api.impl
|
||||
* @date 2019-04-06 11:20
|
||||
* @Description: TODO
|
||||
*/
|
||||
public class WxCpOAServiceImpl implements WxCpOAService {
|
||||
|
||||
private WxCpService mainService;
|
||||
|
||||
public WxCpOAServiceImpl(WxCpService mainService) {
|
||||
this.mainService = mainService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date starttime, Date endtime, List<String> userIdList) throws WxErrorException {
|
||||
|
||||
if (starttime == null || endtime == null) {
|
||||
throw new RuntimeException("starttime and endtime can't be null");
|
||||
}
|
||||
|
||||
if (userIdList == null || userIdList.size() > 100) {
|
||||
throw new RuntimeException("用户列表不能为空,不超过100个,若用户超过100个,请分批获取");
|
||||
}
|
||||
|
||||
long endtimestamp = endtime.getTime() / 1000L;
|
||||
long starttimestamp = starttime.getTime() / 1000L;
|
||||
|
||||
if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= 30 * 24 * 60 * 60) {
|
||||
throw new RuntimeException("获取记录时间跨度不超过一个月");
|
||||
}
|
||||
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata";
|
||||
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
|
||||
jsonObject.addProperty("opencheckindatatype", openCheckinDataType);
|
||||
jsonObject.addProperty("starttime", starttimestamp);
|
||||
jsonObject.addProperty("endtime", endtimestamp);
|
||||
|
||||
for (String userid : userIdList) {
|
||||
jsonArray.add(userid);
|
||||
}
|
||||
|
||||
jsonObject.add("useridlist", jsonArray);
|
||||
|
||||
String responseContent = this.mainService.post(url, jsonObject.toString());
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
return WxCpGsonBuilder.create()
|
||||
.fromJson(
|
||||
tmpJsonElement.getAsJsonObject().get("checkindata"),
|
||||
new TypeToken<List<WxCpCheckinData>>() {
|
||||
}.getType()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxCpCheckinOption> getCheckinOption(Date datetime, List<String> userIdList) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckinoption";
|
||||
if (datetime == null) {
|
||||
throw new RuntimeException("datetime can't be null");
|
||||
}
|
||||
|
||||
if (userIdList == null || userIdList.size() > 100) {
|
||||
throw new RuntimeException("用户列表不能为空,不超过100个,若用户超过100个,请分批获取");
|
||||
}
|
||||
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for (String userid : userIdList) {
|
||||
jsonArray.add(userid);
|
||||
}
|
||||
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("datetime", datetime.getTime() / 1000L);
|
||||
jsonObject.add("useridlist", jsonArray);
|
||||
|
||||
String responseContent = this.mainService.post(url, jsonObject.toString());
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
|
||||
return WxCpGsonBuilder.create()
|
||||
.fromJson(
|
||||
tmpJsonElement.getAsJsonObject().get("info"),
|
||||
new TypeToken<List<WxCpCheckinOption>>() {
|
||||
}.getType()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpApprovalDataResult getApprovalData(Date starttime, Date endtime, Long nextSpnum) throws WxErrorException {
|
||||
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/corp/getapprovaldata";
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("starttime", starttime.getTime() / 1000L);
|
||||
jsonObject.addProperty("endtime", endtime.getTime() / 1000L);
|
||||
if (nextSpnum != null) {
|
||||
jsonObject.addProperty("next_spnum", nextSpnum);
|
||||
}
|
||||
|
||||
String responseContent = this.mainService.post(url, jsonObject.toString());
|
||||
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDataResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxCpDialRecord> getDialRecord(Date starttime, Date endtime, Integer offset, Integer limit) throws WxErrorException {
|
||||
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/dial/get_dial_record";
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
||||
if (offset == null) {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
if (limit == null || limit <= 0) {
|
||||
limit = 100;
|
||||
}
|
||||
|
||||
jsonObject.addProperty("offset", offset);
|
||||
jsonObject.addProperty("limit", limit);
|
||||
|
||||
if (starttime != null && endtime != null) {
|
||||
|
||||
long endtimestamp = endtime.getTime() / 1000L;
|
||||
long starttimestamp = starttime.getTime() / 1000L;
|
||||
|
||||
if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= 30 * 24 * 60 * 60) {
|
||||
throw new RuntimeException("受限于网络传输,起止时间的最大跨度为30天,如超过30天,则以结束时间为基准向前取30天进行查询");
|
||||
}
|
||||
|
||||
jsonObject.addProperty("start_time", starttimestamp);
|
||||
jsonObject.addProperty("end_time", endtimestamp);
|
||||
|
||||
|
||||
}
|
||||
|
||||
String responseContent = this.mainService.post(url, jsonObject.toString());
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
|
||||
return WxCpGsonBuilder.create()
|
||||
.fromJson(
|
||||
tmpJsonElement.getAsJsonObject().get("record"),
|
||||
new TypeToken<List<WxCpDialRecord>>() {
|
||||
}.getType()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.HttpType;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.cp.api.WxCpOAService;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
|
||||
Reference in New Issue
Block a user