zoukankan      html  css  js  c++  java
  • 发送钉钉消息

    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
        }
  • 相关阅读:
    第二章例2-9
    第二章例2-8
    第二章例2-7
    第二章例2-6
    第二章例2-5
    第二章例2-4
    第二章例2-3
    第二章例2-2
    第二章例2-1
    第一章例1-2
  • 原文地址:https://www.cnblogs.com/kaiqinzhang/p/11865388.html
Copyright © 2011-2022 走看看