1 2 3 4

发送钉钉消息

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} \n${content}`
            }, 
            at: {
                atMobiles: ding.atMobiles, 
                isAtAll: false
            }
        })

        return result
    }

 

 

posted @ 2019-11-15 11:46  红鲤鱼与LV  阅读(382)  评论(0编辑  收藏  举报