钉钉机器人在线文档:https://open.dingtalk.com/document/robots/customize-robot-security-settings
配置自定义的机器人
webook 记录这个地址,地址组成:网址 + token 参数
可以通过接口的方式,按数据类型,格式提交数据
本例是通过钉钉SDK 开发
安全设置,根据需求
本例选择IP 段
一个工具类, 以text 消息类型为例,其它消息类型类似
见文档:https://open.dingtalk.com/document/robots/custom-robot-access
说明 :
@多个人时,如果有一个不在群里,或不存在,@会失效
可以直接@ 所有人
@Slf4j
public class DingTalkRobotMsg {
public static OapiRobotSendResponse sendText(String token, String content){
return sendText(token, content, null);
}
public static OapiRobotSendResponse sendText(String token, String content, OapiRobotSendRequest.At at) {
if (StringUtils.isEmpty(token) && StringUtils.isEmpty(content)) {
return null;
}
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("text");
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
text.setContent(content);
request.setText(text);
if (StringUtils.isNotNull(at)) {
boolean sendAt = false;
if (StringUtils.isNotNull(at.getAtMobiles()) && at.getAtMobiles().size() != BaseConstant.ZERO) {
sendAt = true;
}
if (StringUtils.isNotNull(at.getAtUserIds()) && at.getAtUserIds().size() != BaseConstant.ZERO) {
sendAt = true;
}
if (StringUtils.isNotNull(at.getIsAtAll()) && at.getIsAtAll()) {
sendAt = true;
}
if (sendAt) {
request.setAt(at);
}
}
try {
return new DefaultDingTalkClient(DingTalkConstant.ROBOT_URL + token).execute(request);
} catch (ApiException e) {
e.printStackTrace();
log.error("[DingTalk Robot] 发送Text 信息失败, {}", e.getErrMsg());
}
return null;
}
}
可以按时间段(周,天,小时…)查询正常订单
如果有累计功能:发送提醒成功,记录累计数(可以使用缓存,数据库,文件)
本例使用按天累计(累计数有时效性),订单累计数使用Redis 缓存
Key:业务识别码 + 项目ID + 时间(年-月-日)
Key有效时:当天剩余时间秒 + 一个偏移时间(30分钟),可以根据业务需求设置不同偏移值
项目数据效果
Emoji 文字
[鲜花][赞][爱心][红包][烟花][火][火箭][收到][ok][灯笼][感谢][恭喜发财][爆竹]