|
@@ -1,11 +1,13 @@
|
|
|
package cn.com.ctop.job.bytedance.utils;
|
|
package cn.com.ctop.job.bytedance.utils;
|
|
|
|
|
|
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import org.apache.http.HttpEntity;
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
@@ -132,6 +134,52 @@ public class FeishuRobotUtil {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 批量获取用户信息
|
|
|
|
|
+ * return: userId -> userInfo
|
|
|
|
|
+ */
|
|
|
|
|
+ public static Map<String, JSONObject> batchGetUserInfo(String token, List<String> userIds) throws IOException{
|
|
|
|
|
+ Map<String, JSONObject> map = new HashMap<>();
|
|
|
|
|
+ int size = userIds.size();
|
|
|
|
|
+ int pageSize = 50;
|
|
|
|
|
+ int pageNum = size / pageSize + (size % pageSize == 0 ? 0 : 1);
|
|
|
|
|
+ for (int i = 0; i < pageNum; i++) {
|
|
|
|
|
+ int start = i * pageSize;
|
|
|
|
|
+ int end = Math.min(start + pageSize, size);
|
|
|
|
|
+ List<String> subList = userIds.subList(start, end);
|
|
|
|
|
+ Map<String, JSONObject> subMap = batchGetUserInfoOnePage(token, subList);
|
|
|
|
|
+ if (!Check.isNull(subMap)){
|
|
|
|
|
+ map.putAll(subMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static Map<String, JSONObject> batchGetUserInfoOnePage(String token, List<String> userIds) throws IOException{
|
|
|
|
|
+ String url = "https://open.feishu.cn/open-apis/contact/v3/users/batch?user_id_type=user_id&department_id_type=open_department_id";
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("Authorization", "Bearer "+token);
|
|
|
|
|
+ for (String u : userIds){
|
|
|
|
|
+ url = url + "&user_ids="+u;
|
|
|
|
|
+ }
|
|
|
|
|
+ String res = HttpUtils.httpGet(url, null, headers);
|
|
|
|
|
+ JSONObject obj = JSON.parseObject(res);
|
|
|
|
|
+ if (obj != null && obj.getInteger("code") == 0){
|
|
|
|
|
+ Map<String, JSONObject> map = new HashMap<>();
|
|
|
|
|
+ JSONObject data = obj.getJSONObject("data");
|
|
|
|
|
+ JSONArray items = data.getJSONArray("items");
|
|
|
|
|
+ for (int i = 0; i < items.size(); i++) {
|
|
|
|
|
+ JSONObject user = items.getJSONObject(i);
|
|
|
|
|
+ String userId = user.getString("user_id");
|
|
|
|
|
+ map.put(userId, user);
|
|
|
|
|
+ }
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ System.out.println(obj);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static void sendTextToDt(String text, List<String> userIds) throws IOException {
|
|
public static void sendTextToDt(String text, List<String> userIds) throws IOException {
|
|
|
JSONObject content = new JSONObject();
|
|
JSONObject content = new JSONObject();
|
|
|
content.put("text", text);
|
|
content.put("text", text);
|