发送钉钉消息

Posted kaiqinzhang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了发送钉钉消息相关的知识,希望对你有一定的参考价值。

router.js

router.get(/test/ding, controller.test.ding); // 发钉钉消息

controller文件

/**
         * 发钉钉
         */
        async ding() {
            const { ctx, app } = this;
            const { user, query: { content }, helper } = ctx;
            const { config } = app;
            let { ctxBody, code } = config
            let bodyInst = JSON.parse(JSON.stringify(ctxBody));

            // 获取值
            let res = await this.service.ding.send(content);

            bodyInst.data = res

            this.ctx.body = bodyInst;
        }

service文件

async send(content) {
        const { app, ctx, service } = this
        const { config: { env, ding } } = app
        
        let result = await ctx.helper.curl(ding.url+ding.token, {
            msgtype: "text", 
            text: {
                content: `【${env.text}】${ding.keywords} 
${content}`
            }, 
            at: {
                atMobiles: ding.atMobiles, 
                isAtAll: false
            }
        })

        return result
    }

 

 

以上是关于发送钉钉消息的主要内容,如果未能解决你的问题,请参考以下文章

springboot使用RestTemplate以post方式发送json字符串参数(以向钉钉机器人发送消息为例)

发送钉钉消息

钉钉消息监控

发送钉钉消息

钉钉发送工作通知消息

TFS发布计划发送到钉钉消息群