接入钉钉工作通知(未完成),调整部分代码

pull/6/head
3y 3 years ago
parent 1ddece43fe
commit d6d10a7580

@ -1,6 +1,6 @@
package com.java3y.austin.common.domain; package com.java3y.austin.common.domain;
import com.java3y.austin.common.dto.ContentModel; import com.java3y.austin.common.dto.model.ContentModel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;

@ -1,4 +1,4 @@
package com.java3y.austin.handler.domain.dingding; package com.java3y.austin.common.dto.account;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

@ -0,0 +1,39 @@
package com.java3y.austin.common.dto.account;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*
* <p>
* AppKeyAppSecretagentId
* <p>
* https://open-dev.dingtalk.com/?spm=ding_open_doc.document.0.0.13b6722fd9ojfy
*
* @author 3y
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DingDingWorkNoticeAccount {
/**
* key
*/
private String appKey;
/**
*
*/
private String appSecret;
/**
* 使AgentID
*/
private String agentId;
}

@ -1,4 +1,4 @@
package com.java3y.austin.handler.domain.sms; package com.java3y.austin.common.dto.account;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@ -17,7 +17,7 @@ import lombok.NoArgsConstructor;
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class TencentSmsParam { public class TencentSmsAccount {
/** /**
* api * api

@ -1,4 +1,4 @@
package com.java3y.austin.handler.domain.wechat; package com.java3y.austin.common.dto.account;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@ -19,7 +19,7 @@ import java.util.Map;
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class OfficialAccountParam { public class WechatOfficialAccount {
/** /**
* openId * openId

@ -1,4 +1,4 @@
package com.java3y.austin.common.dto; package com.java3y.austin.common.dto.model;
/** /**
* *

@ -1,4 +1,4 @@
package com.java3y.austin.common.dto; package com.java3y.austin.common.dto.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@ -7,8 +7,11 @@ import lombok.NoArgsConstructor;
/** /**
* @author 3y * @author 3y
* * +
* <p>
* https://open.dingtalk.com/document/group/custom-robot-access * https://open.dingtalk.com/document/group/custom-robot-access
* <p>
* https://open.dingtalk.com/document/orgapp-server/asynchronous-sending-of-enterprise-session-messages
*/ */
@Data @Data
@Builder @Builder

@ -1,4 +1,4 @@
package com.java3y.austin.common.dto; package com.java3y.austin.common.dto.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;

@ -1,4 +1,4 @@
package com.java3y.austin.common.dto; package com.java3y.austin.common.dto.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;

@ -1,4 +1,4 @@
package com.java3y.austin.common.dto; package com.java3y.austin.common.dto.model;
/** /**
* @author 3y * @author 3y

@ -1,4 +1,4 @@
package com.java3y.austin.common.dto; package com.java3y.austin.common.dto.model;
/** /**
* @author 3y * @author 3y

@ -1,4 +1,4 @@
package com.java3y.austin.common.dto; package com.java3y.austin.common.dto.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;

@ -1,4 +1,4 @@
package com.java3y.austin.common.dto; package com.java3y.austin.common.dto.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;

@ -1,7 +1,7 @@
package com.java3y.austin.common.enums; package com.java3y.austin.common.enums;
import com.java3y.austin.common.dto.*; import com.java3y.austin.common.dto.model.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.ToString; import lombok.ToString;
@ -25,7 +25,7 @@ public enum ChannelType {
MINI_PROGRAM(60, "miniProgram(小程序)", MiniProgramContentModel.class, "mini_program"), MINI_PROGRAM(60, "miniProgram(小程序)", MiniProgramContentModel.class, "mini_program"),
ENTERPRISE_WE_CHAT(70, "EnterpriseWeChat(企业微信)", EnterpriseWeChatContentModel.class, "enterprise_we_chat"), ENTERPRISE_WE_CHAT(70, "EnterpriseWeChat(企业微信)", EnterpriseWeChatContentModel.class, "enterprise_we_chat"),
DING_DING_ROBOT(80, "dingDingRobot(钉钉机器人)", DingDingContentModel.class, "ding_ding_robot"), DING_DING_ROBOT(80, "dingDingRobot(钉钉机器人)", DingDingContentModel.class, "ding_ding_robot"),
DING_DING_WORK_NOTICE(90, "dingDingWorkNotice(钉钉工作通知)", DingDingContentModel.class, "ding_ding_work_notice"),
; ;
/** /**

@ -0,0 +1,80 @@
package com.java3y.austin.cron.handler;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.java3y.austin.common.dto.account.DingDingWorkNoticeAccount;
import com.java3y.austin.support.config.SupportThreadPoolConfig;
import com.java3y.austin.support.utils.AccountUtils;
import com.java3y.austin.support.utils.RedisUtils;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* access_token
* <p>
* https://open.dingtalk.com/document/orgapp-server/obtain-orgapp-token
*
* @author 3y
*/
@Service
@Slf4j
public class RefreshDingDingAccessTokenHandler {
private static final String DING_DING_ROBOT_ACCOUNT_KEY = "dingDingWorkNoticeAccount";
private static final String PREFIX = "ding_ding_work_notice_";
private static final String URL = "https://oapi.dingtalk.com/gettoken";
@Autowired
private RedisUtils redisUtils;
@Autowired
private AccountUtils accountUtils;
/**
* )
*/
@XxlJob("refreshAccessTokenJob")
public void execute() {
log.info("refreshAccessTokenJob#execute!");
SupportThreadPoolConfig.getPendingSingleThreadPool().execute(() -> {
for (int index = 10; index < 1000; index = index + 10) {
DingDingWorkNoticeAccount account = accountUtils.getAccount(10, DING_DING_ROBOT_ACCOUNT_KEY, PREFIX, new DingDingWorkNoticeAccount());
if (account == null) {
break;
}
String accessToken = getAccessToken(account);
}
});
}
/**
* access_token
* @param account
* @return
*/
private String getAccessToken(DingDingWorkNoticeAccount account) {
try {
DingTalkClient client = new DefaultDingTalkClient(URL);
OapiGettokenRequest req = new OapiGettokenRequest();
req.setAppkey(account.getAppKey());
req.setAppsecret(account.getAppSecret());
req.setHttpMethod("GET");
OapiGettokenResponse rsp = client.execute(req);
System.out.println(rsp.getBody());
} catch (Exception e) {
}
return null;
}
}

@ -7,9 +7,9 @@ import com.alibaba.fastjson.JSON;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.constant.AustinConstant;
import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.dto.DingDingContentModel; import com.java3y.austin.common.dto.model.DingDingContentModel;
import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.handler.domain.dingding.DingDingRobotAccount; import com.java3y.austin.common.dto.account.DingDingRobotAccount;
import com.java3y.austin.handler.domain.dingding.DingDingRobotParam; import com.java3y.austin.handler.domain.dingding.DingDingRobotParam;
import com.java3y.austin.handler.domain.dingding.DingDingRobotResult; import com.java3y.austin.handler.domain.dingding.DingDingRobotResult;
import com.java3y.austin.handler.handler.BaseHandler; import com.java3y.austin.handler.handler.BaseHandler;

@ -0,0 +1,44 @@
package com.java3y.austin.handler.handler.impl;
import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.dto.account.DingDingWorkNoticeAccount;
import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.handler.handler.BaseHandler;
import com.java3y.austin.handler.handler.Handler;
import com.java3y.austin.support.utils.AccountUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
*
* <p>
* https://open.dingtalk.com/document/group/custom-robot-access
*
* @author 3y
*/
@Slf4j
@Service
public class DingDingWorkNoticeHandler extends BaseHandler implements Handler {
private static final String DING_DING_ROBOT_ACCOUNT_KEY = "dingDingWorkNoticeAccount";
private static final String PREFIX = "ding_ding_work_notice_";
@Autowired
private AccountUtils accountUtils;
public DingDingWorkNoticeHandler() {
channelCode = ChannelType.DING_DING_WORK_NOTICE.getCode();
}
@Override
public boolean handler(TaskInfo taskInfo) {
DingDingWorkNoticeAccount account = accountUtils.getAccount(taskInfo.getSendAccount(), DING_DING_ROBOT_ACCOUNT_KEY, PREFIX, new DingDingWorkNoticeAccount());
return false;
}
}

@ -5,7 +5,7 @@ import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil; import cn.hutool.extra.mail.MailUtil;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.dto.EmailContentModel; import com.java3y.austin.common.dto.model.EmailContentModel;
import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.handler.handler.BaseHandler; import com.java3y.austin.handler.handler.BaseHandler;
import com.java3y.austin.handler.handler.Handler; import com.java3y.austin.handler.handler.Handler;

@ -5,7 +5,7 @@ import com.alibaba.fastjson.JSON;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.constant.AustinConstant;
import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.dto.EnterpriseWeChatContentModel; import com.java3y.austin.common.dto.model.EnterpriseWeChatContentModel;
import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.handler.handler.BaseHandler; import com.java3y.austin.handler.handler.BaseHandler;
import com.java3y.austin.handler.handler.Handler; import com.java3y.austin.handler.handler.Handler;

@ -3,7 +3,7 @@ package com.java3y.austin.handler.handler.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.dto.OfficialAccountsContentModel; import com.java3y.austin.common.dto.model.OfficialAccountsContentModel;
import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.handler.handler.BaseHandler; import com.java3y.austin.handler.handler.BaseHandler;
import com.java3y.austin.handler.handler.Handler; import com.java3y.austin.handler.handler.Handler;

@ -5,7 +5,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.dto.SmsContentModel; import com.java3y.austin.common.dto.model.SmsContentModel;
import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.handler.domain.sms.SmsParam; import com.java3y.austin.handler.domain.sms.SmsParam;
import com.java3y.austin.handler.handler.BaseHandler; import com.java3y.austin.handler.handler.BaseHandler;

@ -6,7 +6,7 @@ import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.java3y.austin.common.enums.SmsStatus; import com.java3y.austin.common.enums.SmsStatus;
import com.java3y.austin.handler.domain.sms.SmsParam; import com.java3y.austin.handler.domain.sms.SmsParam;
import com.java3y.austin.handler.domain.sms.TencentSmsParam; import com.java3y.austin.common.dto.account.TencentSmsAccount;
import com.java3y.austin.handler.script.SmsScript; import com.java3y.austin.handler.script.SmsScript;
import com.java3y.austin.support.domain.SmsRecord; import com.java3y.austin.support.domain.SmsRecord;
import com.java3y.austin.support.utils.AccountUtils; import com.java3y.austin.support.utils.AccountUtils;
@ -46,15 +46,15 @@ public class TencentSmsScript implements SmsScript {
@Override @Override
public List<SmsRecord> send(SmsParam smsParam) throws Exception { public List<SmsRecord> send(SmsParam smsParam) throws Exception {
TencentSmsParam tencentSmsParam = accountUtils.getAccount(smsParam.getSendAccount(), SMS_ACCOUNT_KEY, PREFIX, TencentSmsParam.builder().build()); TencentSmsAccount tencentSmsAccount = accountUtils.getAccount(smsParam.getSendAccount(), SMS_ACCOUNT_KEY, PREFIX, TencentSmsAccount.builder().build());
SmsClient client = init(tencentSmsParam); SmsClient client = init(tencentSmsAccount);
SendSmsRequest request = assembleReq(smsParam, tencentSmsParam); SendSmsRequest request = assembleReq(smsParam, tencentSmsAccount);
SendSmsResponse response = client.SendSms(request); SendSmsResponse response = client.SendSms(request);
return assembleSmsRecord(smsParam, response, tencentSmsParam); return assembleSmsRecord(smsParam, response, tencentSmsAccount);
} }
private List<SmsRecord> assembleSmsRecord(SmsParam smsParam, SendSmsResponse response, TencentSmsParam tencentSmsParam) { private List<SmsRecord> assembleSmsRecord(SmsParam smsParam, SendSmsResponse response, TencentSmsAccount tencentSmsAccount) {
if (response == null || ArrayUtil.isEmpty(response.getSendStatusSet())) { if (response == null || ArrayUtil.isEmpty(response.getSendStatusSet())) {
return null; return null;
} }
@ -70,8 +70,8 @@ public class TencentSmsScript implements SmsScript {
.sendDate(Integer.valueOf(DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN))) .sendDate(Integer.valueOf(DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN)))
.messageTemplateId(smsParam.getMessageTemplateId()) .messageTemplateId(smsParam.getMessageTemplateId())
.phone(Long.valueOf(phone)) .phone(Long.valueOf(phone))
.supplierId(tencentSmsParam.getSupplierId()) .supplierId(tencentSmsAccount.getSupplierId())
.supplierName(tencentSmsParam.getSupplierName()) .supplierName(tencentSmsAccount.getSupplierName())
.msgContent(smsParam.getContent()) .msgContent(smsParam.getContent())
.seriesId(sendStatus.getSerialNo()) .seriesId(sendStatus.getSerialNo())
.chargingNum(Math.toIntExact(sendStatus.getFee())) .chargingNum(Math.toIntExact(sendStatus.getFee()))
@ -89,7 +89,7 @@ public class TencentSmsScript implements SmsScript {
/** /**
* *
*/ */
private SendSmsRequest assembleReq(SmsParam smsParam, TencentSmsParam account) { private SendSmsRequest assembleReq(SmsParam smsParam, TencentSmsAccount account) {
SendSmsRequest req = new SendSmsRequest(); SendSmsRequest req = new SendSmsRequest();
String[] phoneNumberSet1 = smsParam.getPhones().toArray(new String[smsParam.getPhones().size() - 1]); String[] phoneNumberSet1 = smsParam.getPhones().toArray(new String[smsParam.getPhones().size() - 1]);
req.setPhoneNumberSet(phoneNumberSet1); req.setPhoneNumberSet(phoneNumberSet1);
@ -107,7 +107,7 @@ public class TencentSmsScript implements SmsScript {
* *
* @param account * @param account
*/ */
private SmsClient init(TencentSmsParam account) { private SmsClient init(TencentSmsAccount account) {
Credential cred = new Credential(account.getSecretId(), account.getSecretKey()); Credential cred = new Credential(account.getSecretId(), account.getSecretKey());
HttpProfile httpProfile = new HttpProfile(); HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint(account.getUrl()); httpProfile.setEndpoint(account.getUrl());

@ -7,7 +7,7 @@ import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.constant.AustinConstant;
import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.dto.ContentModel; import com.java3y.austin.common.dto.model.ContentModel;
import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.enums.RespStatusEnum;
import com.java3y.austin.common.vo.BasicResultVO; import com.java3y.austin.common.vo.BasicResultVO;

@ -86,7 +86,7 @@
<dependency> <dependency>
<groupId>com.aliyun</groupId> <groupId>com.aliyun</groupId>
<artifactId>dingtalk</artifactId> <artifactId>alibaba-dingtalk-service-sdk</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>

@ -177,10 +177,9 @@
<!--阿里云 钉钉 SDK--> <!--阿里云 钉钉 SDK-->
<dependency> <dependency>
<groupId>com.aliyun</groupId> <groupId>com.aliyun</groupId>
<artifactId>dingtalk</artifactId> <artifactId>alibaba-dingtalk-service-sdk</artifactId>
<version>1.3.22</version> <version>2.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

Loading…
Cancel
Save