Java集成飞书视频会议:根据员工工号拉会完整指南

发布时间:2026/7/23 22:20:50
Java集成飞书视频会议:根据员工工号拉会完整指南 1. 背景与需求在企业办公场景中经常需要根据员工的工号自动创建或拉起飞书视频会议。本文介绍如何通过 Java 集成飞书开放平台的视频会议 API实现根据工号批量邀请参会人、创建并启动视频会议的功能。2. 前置准备2.1 飞书应用配置在飞书开放平台open.feishu.cn创建企业自建应用获取以下凭证App ID应用的唯一标识App Secret应用的密钥用于获取 tenant_access_token同时需要在应用权限中开启以下权限vc:meeting视频会议权限contact:user.employee_id:readonly通过工号查询用户信息2.2 Maven 依赖在项目的pom.xml中添加以下依赖dependency groupIdcom.larksuite.oapi/groupId artifactIdoapi-sdk/artifactId version2.5.3/version /dependency版本说明2.5.3 是飞书官方 SDK 的最新稳定版本相比 2.0.12 有更好的稳定性和更多功能支持。3. 核心实现3.1 获取租户访问令牌import com.larksuite.oapi.core.Config; import com.larksuite.oapi.core.enums.BaseUrlEnum; import com.larksuite.oapi.service.vc.v1.Vc; import com.larksuite.oapi.service.vc.v1.model.*; public class FeishuMeetingService { private static final String APP_ID your_app_id; private static final String APP_SECRET your_app_secret; private Config config; private Vc vcService; public FeishuMeetingService() { // 创建配置 this.config Config.newBuilder(APP_ID, APP_SECRET) .baseUrl(BaseUrlEnum.FeiShu) .build(); // 创建视频会议服务 this.vcService new Vc(config); } /** 获取 tenant_access_token */ public String getTenantAccessToken() throws Exception { // SDK 内部会自动管理 token 的获取和刷新 return config.getTokenManager().getTenantAccessToken(); } /** 获取视频会议服务实例 */ public Vc getVcService() { return vcService; } }3.2 根据工号查询用户信息import com.larksuite.oapi.service.contact.v3.ContactService; import com.larksuite.oapi.service.contact.v3.model.User; public class UserService { private ContactService contactService; public UserService(Config config) { this.contactService new ContactService(config); } /** 根据工号查询飞书用户 param employeeId 员工工号 return 飞书用户 open_id */ public String getOpenIdByEmployeeId(String employeeId) throws Exception { User.GetReq req new User.GetReq(); req.setUserId(employeeId); req.setUserIdType(employee_id); User.GetResp resp contactService.getUsers().get(req); if (resp.getData() ! null amp;amp; resp.getData().getUser() ! null) { return resp.getData().getUser().getOpenId(); } throw new RuntimeException(未找到工号为 employeeId 的用户); } }3.3 创建视频会议import com.larksuite.oapi.service.vc.v1.model.*; public class MeetingCreator { private VcService vcService; public MeetingCreator(VcService vcService) { this.vcService vcService; } /** 创建视频会议 param topic 会议主题 param startTime 开始时间Unix 时间戳秒 param duration 会议时长分钟 return 会议对象 */ public Meeting createMeeting(String topic, long startTime, int duration) throws Exception { Meeting.CreateReq req new Meeting.CreateReq(); Meeting.CreateReqBody body new Meeting.CreateReqBody(); body.setTopic(topic); body.setStartTime(String.valueOf(startTime)); body.setDuration(duration); body.setMeetingType(1); // 1-视频会议2-语音会议 req.setCreateMeetingReqBody(body); Meeting.CreateResp resp vcService.getMeetings().create(req); if (resp.getData() ! null) { return resp.getData().getMeeting(); } throw new RuntimeException(创建会议失败); } }3.4 邀请参会人import java.util.List; import java.util.stream.Collectors; public class MeetingInviteService { private VcService vcService; public MeetingInviteService(VcService vcService) { this.vcService vcService; } /** 根据工号列表邀请参会人 param meetingId 会议 ID param employeeIds 工号列表 */ public void inviteByEmployeeIds(String meetingId, Listlt;Stringgt; employeeIds) throws Exception { UserService userService new UserService(vcService.getConfig()); // 批量查询 open_id Listlt;Stringgt; openIds employeeIds.stream() .map(id -gt; { try { return userService.getOpenIdByEmployeeId(id); } catch (Exception e) { throw new RuntimeException(查询工号 id 失败, e); } }) .collect(Collectors.toList()); // 邀请参会人 Meeting.InviteReq req new Meeting.InviteReq(); req.setMeetingId(meetingId); Meeting.InviteReqBody body new Meeting.InviteReqBody(); body.setInvitees(openIds.stream() .map(openId -gt; { Invitee invitee new Invitee(); invitee.setType(1); // 1-用户 invitee.setUserId(openId); return invitee; }) .collect(Collectors.toList())); req.setInviteMeetingReqBody(body); Meeting.InviteResp resp vcService.getMeetings().invite(req); if (!resp.getData().getFailList().isEmpty()) { // 处理邀请失败的成员 System.err.println(部分成员邀请失败 resp.getData().getFailList()); } } }3.5 一键拉会根据工号创建并邀请import java.util.Arrays; import java.util.List; public class QuickMeetingService { private FeishuMeetingService meetingService; private MeetingCreator meetingCreator; private MeetingInviteService inviteService; public QuickMeetingService() { this.meetingService new FeishuMeetingService(); this.meetingCreator new MeetingCreator(meetingService.getVcService()); this.inviteService new MeetingInviteService(meetingService.getVcService()); } /** 一键拉会根据工号创建会议并邀请 param topic 会议主题 param employeeIds 参会人工号列表 param duration 会议时长分钟 return 会议链接 */ public String createAndInvite(String topic, Listlt;Stringgt; employeeIds, int duration) throws Exception { // 1. 创建会议立即开始 long now System.currentTimeMillis() / 1000; Meeting meeting meetingCreator.createMeeting(topic, now, duration); // 2. 邀请参会人 inviteService.inviteByEmployeeIds(meeting.getMeetingId(), employeeIds); // 3. 返回会议链接 return meeting.getMeetingLink(); } // 使用示例 public static void main(String[] args) throws Exception { QuickMeetingService service new QuickMeetingService(); // 根据工号拉会 String meetingLink service.createAndInvite( 项目周会, Arrays.asList(E001, E002, E003), 60 ); System.out.println(会议已创建链接 meetingLink); } }4. 完整调用流程public class Demo { public static void main(String[] args) { try { QuickMeetingService service new QuickMeetingService(); // 根据工号列表拉视频会议 String link service.createAndInvite( 技术方案评审, Arrays.asList(E1001, E1002, E1003, E1004), 30 ); System.out.println(会议链接 link); System.out.println(会议已成功创建并邀请所有成员); } catch (Exception e) { System.err.println(创建会议失败 e.getMessage()); e.printStackTrace(); } } }5. 注意事项权限申请确保应用已在飞书开放平台申请了vc:meeting和contact:user.employee_id:readonly权限并且管理员已审批通过。Token 有效期tenant_access_token 有效期为 2 小时SDK 会自动刷新无需手动处理。工号格式飞书支持多种用户 ID 类型open_id、user_id、employee_id本文使用employee_id作为工号类型请确保与飞书后台配置一致。会议时长免费版飞书会议单次最长 60 分钟企业版可延长。错误处理实际生产环境中建议增加重试机制和更完善的异常处理。6. 总结本文通过 Java SDK 实现了飞书视频会议的集成核心流程包括获取访问令牌 → 根据工号查询用户 open_id → 创建会议 → 邀请参会人。开发者可以根据实际业务需求将此功能封装为 REST API 或集成到企业内部系统中。