package com.qianwen.smartman.modules.notify.api;
|
|
import java.util.Map;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Component;
|
|
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.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 com.taobao.api.ApiException;
|
|
@Component
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/api/DingTalkApi.class */
|
public class DingTalkApi {
|
@Autowired
|
@Lazy
|
private INotifyConfigService notifyConfigService;
|
|
|
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 = this.notifyConfigService.getOne(Wrappers.<NotifyConfigEntity>lambdaQuery()
|
.eq(NotifyConfigEntity::getType, DefaultNotifyType.dingTalk.name())
|
.eq(NotifyConfigEntity::getStatus, 1));
|
/*
|
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 "";
|
}
|
}
|
}
|