NodeJs发送短信
var request = require('request');
let post = function (url, postdata) {
let options = {
url: url,
formData: postdata
};
return new Promise(function (resolve, reject) {
request.post(options, function (err, response, body) {
if (err) {
reject(err)
} else {
resolve(body);
}
})
})
}
let response = async function (url, postdata) {
let body = await post(url, postdata);
return JSON.parse(body);
}
let url = 'https://api.mysubmail.com/message/xsend';
let messageConfig = {
appid: '',
signature: '', //appkey
project: "", //模板id
to: "phone", // 发送电话号码
vars: JSON.stringify({ code: 123456 })
}
response(url, messageConfig).then(function (result) {
console.log(result);
})