FlyBookConsts.java
4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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;
/**
*
* <pre>
* 描述:集成飞书的api常量
* 作者:欧阳高龙
* 日期:2022-04-25 16:07:01
* 版权:广州宏天软件有限公司
* </pre>
*/
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);
}
}