1
0
mirror of synced 2025-12-22 09:58:07 +08:00

🆕 #1675 企业微信增加创建日历的接口,以及相关回调事件消息通知的支持

This commit is contained in:
Binary Wang
2020-09-20 15:37:40 +08:00
parent 6713787bb9
commit 1598c61e56
11 changed files with 316 additions and 9 deletions

View File

@@ -0,0 +1,29 @@
package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.oa.calendar.WxCpOaCalendar;
/**
* 企业微信日历接口.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-09-20
*/
public interface WxCpOaCalendarService {
/**
* 创建日历.
* <pre>
* 该接口用于通过应用在企业内创建一个日历。
* 注: 企业微信需要更新到3.0.2及以上版本
* 请求方式: POSTHTTPS
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/oa/calendar/add?access_token=ACCESS_TOKEN
*
* 文档地址https://work.weixin.qq.com/api/doc/90000/90135/92618
* </pre>
*
* @param calendar 日历对象
* @return 日历ID
* @throws WxErrorException .
*/
String add(WxCpOaCalendar calendar) throws WxErrorException;
}

View File

@@ -388,7 +388,14 @@ public interface WxCpService {
*
* @return the oa service
*/
WxCpOaService getOAService();
WxCpOaService getOaService();
/**
* 获取日历相关接口的服务类对象
*
* @return the menu service
*/
WxCpOaCalendarService getOaCalendarService();
/**
* 获取群机器人消息推送服务
@@ -445,4 +452,5 @@ public interface WxCpService {
* @param tagService the tag service
*/
void setTagService(WxCpTagService tagService);
}

View File

@@ -52,6 +52,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
private WxCpExternalContactService externalContactService = new WxCpExternalContactServiceImpl(this);
private WxCpGroupRobotService groupRobotService = new WxCpGroupRobotServiceImpl(this);
private WxCpMessageService messageService = new WxCpMessageServiceImpl(this);
private WxCpOaCalendarService oaCalendarService = new WxCpOaCalendarServiceImpl(this);
/**
* 全局的是否正在刷新access token的锁.
@@ -305,7 +306,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
return null;
} catch (IOException e) {
log.error("\n【请求地址】: {}\n【请求参数】{}\n【异常信息】{}", uri, data, e.getMessage());
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).errorCode(-1).build(),e);
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).errorCode(-1).build(), e);
}
}
@@ -421,10 +422,15 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
}
@Override
public WxCpOaService getOAService() {
public WxCpOaService getOaService() {
return oaService;
}
@Override
public WxCpOaCalendarService getOaCalendarService() {
return this.oaCalendarService;
}
@Override
public WxCpGroupRobotService getGroupRobotService() {
return groupRobotService;

View File

@@ -0,0 +1,25 @@
package me.chanjar.weixin.cp.api.impl;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpOaCalendarService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.oa.calendar.WxCpOaCalendar;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.CALENDAR_ADD;
/**
* .
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-09-20
*/
@RequiredArgsConstructor
public class WxCpOaCalendarServiceImpl implements WxCpOaCalendarService {
private final WxCpService wxCpService;
@Override
public String add(WxCpOaCalendar calendar) throws WxErrorException {
return this.wxCpService.post(this.wxCpService.getWxCpConfigStorage().getApiUrl(CALENDAR_ADD),calendar.toJson());
}
}

View File

@@ -294,6 +294,20 @@ public class WxCpXmlMessage implements Serializable {
@XStreamConverter(value = XStreamCDataConverter.class)
private String address;
/**
* 日程ID.
*/
@XStreamAlias("ScheduleId")
@XStreamConverter(value = XStreamCDataConverter.class)
private String scheduleId;
/**
* 日历ID.
*/
@XStreamAlias("CalId")
@XStreamConverter(value = XStreamCDataConverter.class)
private String calId;
/**
* 扩展属性.
*/

View File

@@ -0,0 +1,105 @@
package me.chanjar.weixin.cp.bean.oa.calendar;
import com.google.common.collect.ImmutableMap;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
import java.util.List;
/**
* 日历.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-09-20
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpOaCalendar implements Serializable {
private static final long serialVersionUID = -817988838579546989L;
/**
* 变量名organizer
* 是否必须:是
* 描述指定的组织者userid。注意该字段指定后不可更新
*/
@SerializedName("organizer")
private String organizer;
/**
* 变量名readonly
* 是否必须:否
* 描述日历组织者对日历是否只读权限即不可编辑日历不可在日历上添加日程仅可作为组织者删除日历。0-否1-是。默认为1即只读
*/
@SerializedName("readonly")
private Integer readonly;
/**
* 变量名set_as_default
* 是否必须:否
* 描述是否将该日历设置为组织者的默认日历。0-否1-是。默认为0即不设为默认日历
*/
@SerializedName("set_as_default")
private Integer setAsDefault;
/**
* 变量名summary
* 是否必须:是
* 描述日历标题。1 ~ 128 字符
*/
@SerializedName("summary")
private String summary;
/**
* 变量名color
* 是否必须:是
* 描述日历在终端上显示的颜色RGB颜色编码16进制表示例如”#0000FF” 表示纯蓝色
*/
@SerializedName("color")
private String color;
/**
* 变量名description
* 是否必须:否
* 描述日历描述。0 ~ 512 字符
*/
@SerializedName("description")
private String description;
/**
* 变量名shares
* 是否必须:否
* 描述日历共享成员列表。最多2000人
*/
@SerializedName("shares")
private List<ShareInfo> shares;
@Data
@AllArgsConstructor
public static class ShareInfo implements Serializable {
private static final long serialVersionUID = -4882781114860754679L;
/**
* 日历共享成员的id
*/
private String userid;
/**
* 共享成员对日历是否只读权限(即不可编辑日历,不可在日历上添加日程,仅可以退出日历)。
* 0-否1-是。默认为1即只读
*/
private Integer readonly;
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(ImmutableMap.of("calendar",this));
}
}

View File

@@ -101,6 +101,11 @@ public final class WxCpApiPathConsts {
public static final String GET_DIAL_RECORD = "/cgi-bin/dial/get_dial_record";
public static final String GET_TEMPLATE_DETAIL = "/cgi-bin/oa/gettemplatedetail";
public static final String APPLY_EVENT = "/cgi-bin/oa/applyevent";
public static final String CALENDAR_ADD = "/cgi-bin/oa/calendar/add";
public static final String CALENDAR_UPDATE = "/cgi-bin/oa/calendar/update";
public static final String CALENDAR_GET = "/cgi-bin/oa/calendar/get";
public static final String CALENDAR_DEL = "/cgi-bin/oa/calendar/del";
}
@UtilityClass

View File

@@ -103,6 +103,30 @@ public class WxCpConsts {
*/
public static final String OPEN_APPROVAL_CHANGE = "open_approval_change";
/**
* 修改日历事件
*/
public static final String MODIFY_CALENDAR = "modify_calendar";
/**
* 删除日历事件
*/
public static final String DELETE_CALENDAR = "delete_calendar";
/**
* 添加日程事件
*/
public static final String ADD_SCHEDULE = "add_schedule";
/**
* 修改日程事件
*/
public static final String MODIFY_SCHEDULE = "modify_schedule";
/**
* 删除日程事件
*/
public static final String DELETE_SCHEDULE = "delete_schedule";
}