合并分支 'fix_2nd_20230103' 到 'master'

知识分享-联系创建人-获取用户飞书信息接口修改。

查看合并请求 laws-nio/laws-weilai!271
This commit is contained in:
高嵩
2023-01-03 13:57:29 +08:00
2 changed files with 91 additions and 20 deletions
@@ -116,4 +116,10 @@ public interface IFeishuService {
* @return
*/
Result<?> getLarkApplinkByUserName(JSONObject json);
/**
* 根据邮箱,获取来自飞书的用户信息
* @param emailList
*/
JSONObject getUserInfoFromLarkByEmainList(List<String> emailList) throws IOException ;
}
@@ -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<String> 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<String> 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<String,Object> 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<String> 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<String,Object> 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<String> emailList) throws IOException {
String token = getTenantAccessToken();
// 设置请求头
Map<String, String> 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;
}
}