package com.hotent.system.consts; import cn.hutool.core.util.StrUtil; import com.hotent.base.util.AppUtil; import com.hotent.system.enums.BaseUrlEnum; import com.hotent.system.model.SysExternalUnite; import com.hotent.system.persistence.manager.SysExternalUniteManager; import org.omg.CORBA.PUBLIC_MEMBER; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; /** * *
 * 描述:集成飞书的api常量
 * 作者:欧阳高龙
 * 日期:2022-04-25 16:07:01
 * 版权:广州宏天软件有限公司
 * 
*/ public class FlyBookConsts { public final static String METHOD_GET = "GET"; public final static String METHOD_POST = "POST"; /** * 认证相关的url */ private final static String OAUTH_URL = "https://passport.feishu.cn/suite/passport/oauth"; /** * 企业accessToken相关url */ private final static String OPEN_APIS_AUTH_URL = "https://open.feishu.cn/open-apis/auth/v3"; /** * 企业通讯录相关url */ private final static String OPEN_APIS_CONTACT_URL = "https://open.feishu.cn/open-apis/contact/v3"; /** * 通信相关url */ private final static String OPEN_APIS_MESSAGE_URL = "https://open.feishu.cn/open-apis/message/v4"; /** * 请求用户身份验证url */ private final static String OPEN_AUTH_URL = "https://open.feishu.cn/open-apis/authen/v1"; public static SysExternalUnite getUnite(){ SysExternalUniteManager manager= AppUtil.getBean(SysExternalUniteManager.class); return manager.getFlyBook(); } /** * 获取用户访问accessToken * @return */ public static String getTokenUrl() { return String.format("%s/token", OAUTH_URL); } public static String getUserInfoUrl() { return String.format("%s/userinfo", OAUTH_URL); } /** * 获取企业通讯录访问accessToken * @return url */ public static String getTenantTokenUrl() { return String.format("%s/tenant_access_token/internal", OPEN_APIS_AUTH_URL); } /** * 通过部门ID获取部门的子部门列表 * @return url */ public static String getDepartmentChildrenUrl(String departmentId) { return String.format("%s/departments/%s/children?user_id_type=user_id&department_id_type=department_id&page_size=50", OPEN_APIS_CONTACT_URL, departmentId); } /** * 通过部门ID获取部门的父部门列表 * @return url */ public static String getDepartmentParentUrl(String departmentId) { return String.format("%s/departments/parent?department_id=%s&user_id_type=user_id&department_id_type=department_id&page_size=50", OPEN_APIS_CONTACT_URL, departmentId); } /** * 通过部门ID获取单个部门信息 * @return url */ public static String getDepartmentUrl(String departmentId) { return String.format("%s/departments/%s?user_id_type=user_id&department_id_type=department_id", OPEN_APIS_CONTACT_URL, departmentId); } /** * 获取直属部门用户列表 * @return url */ public static String getUserListByDeptIdUrl(String departmentId) { return String.format("%s/users/find_by_department?department_id=%s&user_id_type=user_id&department_id_type=department_id&page_size=50", OPEN_APIS_CONTACT_URL, departmentId); } /** * 创建部门URL * @return url */ public static String createDeptUrl() { return String.format("%s/departments?user_id_type=user_id&department_id_type=department_id", OPEN_APIS_CONTACT_URL); } /** * 创建用户URL * @return url */ public static String createUserUrl() { return String.format("%s/users?user_id_type=user_id&department_id_type=department_id", OPEN_APIS_CONTACT_URL); } /** * 批量发送卡片消息URL * @return url */ public static String batchSendCardUrl() { return String.format("%s/batch_send", OPEN_APIS_MESSAGE_URL); } /** * 一键生成菜单url * @param baseUrl 本系统地址 * @param corpId 企业id * @return * @throws UnsupportedEncodingException */ public static String generateMenuUrl(String baseUrl,String corpId, BaseUrlEnum baseUrlEnum) throws UnsupportedEncodingException { String path = BaseUrlEnum.PC.equals(baseUrlEnum)?"index":"home"; if(!baseUrl.endsWith(StrUtil.SLASH)){ path = StrUtil.SLASH + path; } String redirectUri = baseUrl + "/flyBook?redirect=" + baseUrl + path; return OPEN_AUTH_URL + "/index?redirect_uri="+ URLEncoder.encode(redirectUri, "UTF-8") + "&app_id=" + corpId + "&state=hotent"; } /** * 获取飞书验证,并重定向到EIP系统的url * @param paramStr * @return */ public static String getAuthorize(String paramStr) throws UnsupportedEncodingException { SysExternalUnite unite = getUnite(); String corpId=unite.getCorpId(); String redirectUri = unite.getBaseUrl() + "/flyBook?params="+paramStr; return OPEN_AUTH_URL + "/index?redirect_uri="+ URLEncoder.encode(redirectUri, "UTF-8") + "&app_id=" + corpId + "&state=hotent"; } /** * 获取登录用户身份 url * @return */ public static String getAuthAccessToken(){ return String.format("%s/access_token", OPEN_AUTH_URL); } }