use of com.dingtalk.api.DingTalkClient in project dynamic-threadpool by acmenlt.
the class DingSendMessageHandler method execute.
private void execute(String secretKey, String title, String text, List<String> mobiles) {
String serverUrl = DingAlarmConstants.DING_ROBOT_SERVER_URL + secretKey;
DingTalkClient dingTalkClient = new DefaultDingTalkClient(serverUrl);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle(title);
markdown.setText(text);
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
at.setAtMobiles(mobiles);
request.setAt(at);
request.setMarkdown(markdown);
try {
dingTalkClient.execute(request);
} catch (ApiException ex) {
log.error("Ding failed to send message", ex);
}
}
use of com.dingtalk.api.DingTalkClient in project MaxKey by dromara.
the class DingtalkAccessTokenService method requestToken.
public String requestToken() throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
OapiGettokenRequest request = new OapiGettokenRequest();
request.setAppkey(appkey);
request.setAppsecret(appsecret);
request.setHttpMethod("GET");
OapiGettokenResponse response = client.execute(request);
_logger.info("response : " + response.getBody());
if (response.getErrcode() == 0) {
return response.getAccessToken();
}
return "";
}
use of com.dingtalk.api.DingTalkClient in project dynamic-threadpool by acmenlt.
the class DingSendMessageHandler method execute.
private void execute(NotifyConfigDTO notifyConfig, String title, String text, List<String> mobiles) {
String serverUrl = DingAlarmConstants.DING_ROBOT_SERVER_URL + notifyConfig.getSecretKey();
String secret = notifyConfig.getSecret();
if (StringUtil.isNotBlank(secret)) {
long timestamp = System.currentTimeMillis();
String stringToSign = timestamp + "\n" + secret;
try {
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), StandardCharsets.UTF_8.name());
serverUrl = serverUrl + "×tamp=" + timestamp + "&sign=" + sign;
} catch (Exception ex) {
log.error("Failed to sign the message sent by nailing.", ex);
}
}
DingTalkClient dingTalkClient = new DefaultDingTalkClient(serverUrl);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle(title);
markdown.setText(text);
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
at.setAtMobiles(mobiles);
request.setAt(at);
request.setMarkdown(markdown);
try {
dingTalkClient.execute(request);
} catch (ApiException ex) {
log.error("Ding failed to send message", ex);
}
}
use of com.dingtalk.api.DingTalkClient in project dingtalk-app-server by nju-softeng.
the class OAApi method getOAOutCome.
public int getOAOutCome(String processInstanceId) {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/get");
OapiProcessinstanceGetRequest req = new OapiProcessinstanceGetRequest();
req.setProcessInstanceId(processInstanceId);
OapiProcessinstanceGetResponse rsp = client.execute(req, getAccessToken());
if (rsp.getProcessInstance().getStatus().equals("COMPLETED")) {
if (rsp.getProcessInstance().getResult().equals("agree"))
return 1;
else
return 0;
} else
return -1;
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
use of com.dingtalk.api.DingTalkClient in project dingtalk-app-server by nju-softeng.
the class OAApi method createAbsentOA.
public String createAbsentOA(AbsentOA absentOA) {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/create");
OapiProcessinstanceCreateRequest request = new OapiProcessinstanceCreateRequest();
request.setAgentId(BaseApi.AGENTID);
// 设置process code
request.setProcessCode(absentOAProcessCode);
request.setOriginatorUserId(userService.getUserid(absentOA.getUser().getId()));
request.setDeptId(-1L);
// 设置表单内容
List<OapiProcessinstanceCreateRequest.FormComponentValueVo> form = new ArrayList<>();
OapiProcessinstanceCreateRequest.FormComponentValueVo type = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
form.add(type);
type.setName("请假类型");
type.setValue(absentOA.getType());
OapiProcessinstanceCreateRequest.FormComponentValueVo start = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
form.add(start);
start.setName("开始时间");
start.setValue(absentOA.getDingTalkSchedule().getStart().toString());
OapiProcessinstanceCreateRequest.FormComponentValueVo end = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
form.add(end);
end.setName("结束时间");
end.setValue(absentOA.getDingTalkSchedule().getEnd().toString());
// OapiProcessinstanceCreateRequest.FormComponentValueVo dayNum = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
// form.add(dayNum);
// dayNum.setName("结束时间");
// dayNum.setValue(absentOA.getDayNum().toString());
OapiProcessinstanceCreateRequest.FormComponentValueVo reason = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
form.add(reason);
reason.setName("请假缘由");
reason.setValue(absentOA.getReason());
request.setFormComponentValues(form);
// 设置审批人
List<OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo> processInstanceApproverVoList = new ArrayList<>();
OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo processInstanceApproverVo = new OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo();
processInstanceApproverVoList.add(processInstanceApproverVo);
request.setApprovers(absentOA.getDingTalkSchedule().getOrganizer().getUserid());
OapiProcessinstanceCreateResponse rsp = client.execute(request, getAccessToken());
return rsp.getProcessInstanceId();
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
Aggregations