diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/IFeishuService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/IFeishuService.java index 61fba821a..3d1eb5108 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/IFeishuService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/IFeishuService.java @@ -116,4 +116,10 @@ public interface IFeishuService { * @return */ Result getLarkApplinkByUserName(JSONObject json); + + /** + * 根据邮箱,获取来自飞书的用户信息 + * @param emailList + */ + JSONObject getUserInfoFromLarkByEmainList(List emailList) throws IOException ; } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/impl/FeishuServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/impl/FeishuServiceImpl.java index e3ed71c71..f493376e1 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/impl/FeishuServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/impl/FeishuServiceImpl.java @@ -1296,32 +1296,64 @@ public class FeishuServiceImpl implements IFeishuService { throw new JeroBootException("User not found" + userName + ", please check!"); } } - String phone = sysUserInfo.getPhone(); - JSONObject responseJson = null; - List phoneList = Arrays.asList(phone.split(",")); - try { - // 根据用户手机号获取该用户在飞书中的信息 - responseJson = this.getUserInfoFromLarkByPhoneList(phoneList); - }catch (Exception ex){ - ex.printStackTrace(); - log.error("根据用户手机号获取该用户在飞书中的信息失败:" + ex.getMessage()); - } + String phone = sysUserInfo.getTelephone(); + String email = sysUserInfo.getEmail(); + if(StringUtils.isNotEmpty(phone)){ + List phoneList = Arrays.asList(phone.split(",")); + try { + // 根据用户手机号获取该用户在飞书中的信息 + responseJson = this.getUserInfoFromLarkByPhoneList(phoneList); + }catch (Exception ex){ + ex.printStackTrace(); + log.error("根据用户手机号获取该用户在飞书中的信息失败:" + ex.getMessage()); - JSONArray userJsonArray = JSONObject.parseObject(JSONObject.toJSONString(responseJson.get("data"))).getJSONArray("user_list"); - Map userJsonMap = null; - for (Object userJson : userJsonArray) { - userJsonMap = JSONObject.parseObject(JSONObject.toJSONString(userJson),Map.class); - if(userJsonMap.get("user_id") != null){ - if(StringUtils.isNotEmpty(userJsonMap.get("user_id").toString()) && StringUtils.equals(userJsonMap.get("mobile").toString(),phone)){ - result = this.appLinkUrl + userJsonMap.get("user_id").toString(); - break; + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + throw new JeroBootException("暂无该用户联系方式"); + }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + throw new JeroBootException("No contact information for this user is available."); } - }else { - throw new JeroBootException("用户:" + userName + ",在飞书中未找到对应user_id信息"); + } + }else if(StringUtils.isNotEmpty(email)){ + List emailList = Arrays.asList(email.split(",")); + try { + // 根据用户邮箱获取该用户在飞书中的信息 + responseJson = this.getUserInfoFromLarkByEmainList(emailList); + }catch (Exception ex){ + ex.printStackTrace(); + log.error("根据用户邮箱获取该用户在飞书中的信息失败:" + ex.getMessage()); + + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + throw new JeroBootException("暂无该用户联系方式"); + }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + throw new JeroBootException("No contact information for this user is available."); + } + } + }else { + if(StringUtils.equals(cut,CutEnum.CN.getValue())){ + throw new JeroBootException("暂无该用户联系方式"); + }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + throw new JeroBootException("No contact information for this user is available."); } } + + if(responseJson != null){ + JSONArray userJsonArray = JSONObject.parseObject(JSONObject.toJSONString(responseJson.get("data"))).getJSONArray("user_list"); + Map userJsonMap = null; + for (Object userJson : userJsonArray) { + userJsonMap = JSONObject.parseObject(JSONObject.toJSONString(userJson),Map.class); + if(userJsonMap.get("user_id") != null){ + if(StringUtils.isNotEmpty(userJsonMap.get("user_id").toString()) && StringUtils.equals(userJsonMap.get("mobile").toString(),phone)){ + result = this.appLinkUrl + userJsonMap.get("user_id").toString(); + break; + } + }else { + throw new JeroBootException("用户:" + userName + ",在飞书中未找到对应user_id信息"); + } + } + } + if(StringUtils.isNotEmpty(result)){ return Result.OK("获取" +userName+ "用户飞书AppLink成功!",result); }else { @@ -1329,4 +1361,37 @@ public class FeishuServiceImpl implements IFeishuService { } } + /** + * 根据邮箱,获取来自飞书的用户信息 + * @param emailList + * @throws IOException + */ + @Override + public JSONObject getUserInfoFromLarkByEmainList(List emailList) throws IOException { + + String token = getTenantAccessToken(); + // 设置请求头 + Map headerMap = new HashMap<>(); + headerMap.put("Authorization", "Bearer " + token); + headerMap.put("Content-Type", "application/json; charset=utf-8"); + + // 设置请求参数 + JSONObject paramsMap = new JSONObject(); + paramsMap.put("emails", emailList); + + // 发送请求给飞书 + String response = null; + try { + response = HttpRequestUtil.getResponseOfPOST(getUserInfoUrl, headerMap, paramsMap.toJSONString()); + } catch (IOException e) { + e.printStackTrace(); + } + // 获取返回结果 + JSONObject responseJson = JSONObject.parseObject(response); + if(!responseJson.get("code").toString().equals("0")) { + log.error("请求出现异常:" + responseJson.get("msg") + " " + responseJson); + } + return responseJson; + } + }