1.钉钉添加机器人
1.1 新建一个群 --> 群设置 --> 机器人
1.2 机器人管理 --> 添加机器人
1.3 机器人--> 自定义-->添加
1.4 配置信息
备注1:密钥复制出来SEC2c689174c4a8ed49c8a7309a490cd98e0e7f7bc788bb7232d53c738eb5f5d008
备注2: 点完成 弹出下图,再复制webhook
https://oapi.dingtalk.com/robot/send?access_token=8659dec91bbf5f4405456926c24c6712c2c5ab98814c37af52f7bf503de9a598
1.5大功告成
2.开始写代码
2.1 新建一个文件 test.js
// 发送消息到钉钉
function sendDingDing(content) {const request = require('request');const crypto = require('crypto');var dingdingUrl = 'https://oapi.dingtalk.com/robot/send?access_token=8659dec91bbf5f4405456926c24c6712c2c5ab98814c37af52f7bf503de9a598';var secret = 'SEC2c689174c4a8ed49c8a7309a490cd98e0e7f7bc788bb7232d53c738eb5f5d008';var timestamp = new Date().getTime();var stringToSign = timestamp + '\n' + secret;var base = crypto.createHmac('sha256',secret).update(stringToSign).digest('base64');var sing = encodeURIComponent(base);var dingdingStr = dingdingUrl + `×tamp=${timestamp}&sign=${sing}`;var data = {json: {"msgtype": "text","text": {"content":content}},encoding: 'utf-8',headers: {'Content-Type': 'application/json'}}request.post(dingdingStr, data, function(error,res,body) {if(!error && res.statusCode == 200) {console.log('body is ',body);}})
}sendDingDing("在奋进中拥抱梦想 成就未来")
备注1:替换 dingdingUrl 替换 secret