大致代码:
var https = require("https")
var url = require('url')
var querystring = require('querystring')
var postUrl="https://oapi.dingtalk.com/robot/send?access_token=xxxxx"
var post_option = url.parse(postUrl);
post_option.method = 'POST';
var contentstr = "测试"
//var post_data = querystring.stringify({ //解析的时候会丢失对象
var post_data = JSON.stringify({
"msgtype": "text",
"text": {
"content": contentstr
},
"at": {
"isAtAll": true
}
})
post_option.headers = {
'Content-Type': 'application/json',
'Content-Length': post_data.length
}
var post_req = https.request(post_option, function(res) {
res.setEncoding('utf8');
res.on('data', function(chunk) {
console.log(chunk)
})
})
post_req.write(post_data);
post_req.end();
------------
返回结果是{"errcode":-1,"errmsg":"系统繁忙"}
官方文档都没的查,郁闷呢。
下面这种方式就没问题
curl '
https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxx' \
-H 'Content-Type: application/json' \
-d '
{"msgtype": "text",
"text": {
"content": " 我就是我, 是不一样的烟火"
}
}'
请大神们开智!感谢!