package com.qianwen.smartman.modules.notify.api;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.dingtalk.api.DefaultDingTalkClient;
|
import com.dingtalk.api.request.OapiGettokenRequest;
|
import com.dingtalk.api.request.OapiV2DepartmentGetRequest;
|
import com.dingtalk.api.request.OapiV2UserGetbymobileRequest;
|
import com.dingtalk.api.response.OapiGettokenResponse;
|
import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
|
import com.dingtalk.api.response.OapiV2UserGetbymobileResponse;
|
import com.taobao.api.ApiException;
|
import java.lang.invoke.SerializedLambda;
|
import java.util.Map;
|
import com.qianwen.core.notify.DefaultNotifyType;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.notify.entity.NotifyConfigEntity;
|
import com.qianwen.smartman.modules.notify.service.INotifyConfigService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Component;
|
|
@Component
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/api/DingTalkApi.class */
|
public class DingTalkApi {
|
@Autowired
|
@Lazy
|
private INotifyConfigService notifyConfigService;
|
|
private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
|
String implMethodName = lambda.getImplMethodName();
|
boolean z = true;
|
switch (implMethodName.hashCode()) {
|
case -75106384:
|
if (implMethodName.equals("getType")) {
|
z = false;
|
break;
|
}
|
break;
|
case 803533544:
|
if (implMethodName.equals("getStatus")) {
|
z = true;
|
break;
|
}
|
break;
|
}
|
switch (z) {
|
case false:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/notify/entity/NotifyConfigEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getType();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getStatus();
|
};
|
}
|
break;
|
}
|
throw new IllegalArgumentException("Invalid lambda deserialization");
|
}
|
|
public String getToken() {
|
DingTalkConfig dingTalkDTO = getDingTalkConfig();
|
try {
|
DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
|
OapiGettokenRequest req = new OapiGettokenRequest();
|
req.setHttpMethod("GET");
|
req.setAppkey(dingTalkDTO.getAppkey());
|
req.setAppsecret(dingTalkDTO.getAppsecret());
|
OapiGettokenResponse rsp = defaultDingTalkClient.execute(req);
|
if (Func.equals(rsp.getErrorCode(), "0")) {
|
return rsp.getAccessToken();
|
}
|
return null;
|
} catch (Exception e) {
|
e.printStackTrace();
|
return null;
|
}
|
}
|
|
public String getUserIdByMobile(String mobile) {
|
try {
|
DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/getbymobile");
|
OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();
|
req.setMobile(mobile);
|
OapiV2UserGetbymobileResponse rsp = defaultDingTalkClient.execute(req, getToken());
|
OapiV2UserGetbymobileResponse.UserGetByMobileResponse result = rsp.getResult();
|
return Func.equals(rsp.getErrorCode(), "0") ? result.getUserid() : "";
|
} catch (Exception e) {
|
e.printStackTrace();
|
return "";
|
}
|
}
|
|
private DingTalkConfig getDingTalkConfig() {
|
NotifyConfigEntity config = (NotifyConfigEntity) this.notifyConfigService.getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getType();
|
}, DefaultNotifyType.dingTalk.name())).eq((v0) -> {
|
return v0.getStatus();
|
}, 1));
|
Map<String, Object> configuration = config.getConfiguration();
|
Object appKey = configuration.get("appKey");
|
Object appSecret = configuration.get("appSecret");
|
DingTalkConfig dingTalkConfig = new DingTalkConfig();
|
dingTalkConfig.setAppkey(String.valueOf(appKey));
|
dingTalkConfig.setAppsecret(String.valueOf(appSecret));
|
return dingTalkConfig;
|
}
|
|
public String getCompanyName() {
|
DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/get");
|
OapiV2DepartmentGetRequest req = new OapiV2DepartmentGetRequest();
|
req.setDeptId(1L);
|
req.setLanguage("zh_CN");
|
try {
|
OapiV2DepartmentGetResponse rsp = defaultDingTalkClient.execute(req, getToken());
|
if (Func.equals(rsp.getErrorCode(), "0")) {
|
OapiV2DepartmentGetResponse.DeptGetResponse result = rsp.getResult();
|
return result.getName();
|
}
|
return "";
|
} catch (ApiException e) {
|
e.printStackTrace();
|
return "";
|
}
|
}
|
}
|