|
@@ -662,14 +662,15 @@ public class IFeiShuCommonService {
|
|
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
// log.info("jsonObject:{}", jsonObject.toJSONString());
|
|
|
if (!jsonObject.isEmpty()) {
|
|
|
- JSONObject enNameFieldsObj = jsonObject.getJSONObject("英文名称");
|
|
|
- JSONArray enNameDataArray = enNameFieldsObj.getJSONArray("value");
|
|
|
- String enNameKey = enNameDataArray.getJSONObject(0).getString("text");
|
|
|
-
|
|
|
- if (!kfGroupData.containsKey(enNameKey)) {
|
|
|
- kfGroupData.put(enNameKey, new ArrayList<>());
|
|
|
+ if (jsonObject.containsKey("英文名称")) {
|
|
|
+ JSONObject enNameFieldsObj = jsonObject.getJSONObject("英文名称");
|
|
|
+ JSONArray enNameDataArray = enNameFieldsObj.getJSONArray("value");
|
|
|
+ String enNameKey = enNameDataArray.getJSONObject(0).getString("text");
|
|
|
+ if (!kfGroupData.containsKey(enNameKey)) {
|
|
|
+ kfGroupData.put(enNameKey, new ArrayList<>());
|
|
|
+ }
|
|
|
+ kfGroupData.get(enNameKey).add(jsonObject);
|
|
|
}
|
|
|
- kfGroupData.get(enNameKey).add(jsonObject);
|
|
|
}
|
|
|
}
|
|
|
log.info("kfGroupData:{}", FastJsonUtil.toJSONString(kfGroupData));
|
|
@@ -714,4 +715,77 @@ public class IFeiShuCommonService {
|
|
|
log.error("******* sendGroupMsg-error ******** :{}", String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拉入机器人加入飞书群
|
|
|
+ *
|
|
|
+ * @param chatId
|
|
|
+ * @param needJoinIdList
|
|
|
+ */
|
|
|
+ public void joinFeiShuGroupRequest(String chatId, List<String> needJoinIdList) {
|
|
|
+ FeiShuConfigEnum configEnum = FeiShuConfigManager.getInstance().getConfigEnum();
|
|
|
+
|
|
|
+ Client client = Client.newBuilder(configEnum.getAppId(), configEnum.getAppSecret()).build();
|
|
|
+ String[] needJoinIdsArr = needJoinIdList.toArray(new String[0]);
|
|
|
+
|
|
|
+ // 创建请求对象
|
|
|
+ CreateChatMembersReq req = CreateChatMembersReq.newBuilder()
|
|
|
+ .chatId(chatId)
|
|
|
+ .memberIdType("app_id")
|
|
|
+ .createChatMembersReqBody(CreateChatMembersReqBody.newBuilder()
|
|
|
+ .idList(needJoinIdsArr)
|
|
|
+ .build())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ // 发起请求
|
|
|
+ CreateChatMembersResp resp = null;
|
|
|
+ try {
|
|
|
+ resp = client.im().chatMembers().create(req);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理服务端错误
|
|
|
+ if (!resp.success()) {
|
|
|
+ System.out.println(String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 业务数据处理
|
|
|
+ System.out.println(Jsons.DEFAULT.toJson(resp.getData()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查机器人或用户是否在群里
|
|
|
+ *
|
|
|
+ * @param chatId
|
|
|
+ */
|
|
|
+ public boolean checkBotOrUserIsExistGroup(String chatId) {
|
|
|
+ FeiShuConfigEnum configEnum = FeiShuConfigManager.getInstance().getConfigEnum();
|
|
|
+ // 构建client
|
|
|
+ Client client = Client.newBuilder(configEnum.getAppId(), configEnum.getAppSecret()).build();
|
|
|
+
|
|
|
+ // 创建请求对象
|
|
|
+ IsInChatChatMembersReq req = IsInChatChatMembersReq.newBuilder()
|
|
|
+ .chatId(chatId)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ // 发起请求
|
|
|
+ IsInChatChatMembersResp resp = null;
|
|
|
+ try {
|
|
|
+ resp = client.im().chatMembers().isInChat(req);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理服务端错误
|
|
|
+ if (!resp.success()) {
|
|
|
+ log.error(String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 业务数据处理
|
|
|
+// log.info(Jsons.DEFAULT.toJson(resp.getData()));
|
|
|
+
|
|
|
+ return resp.getData().getIsInChat();
|
|
|
+ }
|
|
|
}
|