• JAVA----钉钉机器人-订单提醒功能


    钉钉机器人-订单提醒功能

    钉钉机器人在线文档:https://open.dingtalk.com/document/robots/customize-robot-security-settings

    第一步 创建,配置机器人,选择自定义(WebHook)

    在这里插入图片描述

    配置自定义的机器人
    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;
        }
        
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    订单提醒思路

    可以按时间段(周,天,小时…)查询正常订单

    如果有累计功能:发送提醒成功,记录累计数(可以使用缓存,数据库,文件)

    本例使用按天累计(累计数有时效性),订单累计数使用Redis 缓存
    Key:业务识别码 + 项目ID + 时间(年-月-日)
    Key有效时:当天剩余时间秒 + 一个偏移时间(30分钟),可以根据业务需求设置不同偏移值

    效果

    项目数据效果
    在这里插入图片描述

    Emoji 文字
    [鲜花][赞][爱心][红包][烟花][火][火箭][收到][ok][灯笼][感谢][恭喜发财][爆竹]
    在这里插入图片描述

  • 相关阅读:
    STM32F4X I2C LM75
    try-with-resources(TWR)方式关闭流资源
    2022.07.19 随机数字python
    复盘:图像有哪些基本属性?关于图像的知识你知道哪些?图像的参数有哪些
    jvm--执行引擎
    java图形验证码到底是怎么生成的?
    BSVD论文理解:Real-time Streaming Video Denoising with Bidirectional Buffers
    安卓是属于全人类的还是谷歌的私有产品?
    安装maven及查看maven版本号
    C语言和Rust语言的互相调用(2)(Rust调用C)
  • 原文地址:https://blog.csdn.net/damys/article/details/126559685