Node.js短信接口一代码示例
请求
var http = require('http');
var querystring = require('querystring');
var postData = {
uid:'',
pas:'',
mob:'',
con:'【微米】您的验证码是:610912,3分钟内有效。如非您本人操作,可忽略本消息。',
type:'json'
};
var content = querystring.stringify(postData);
var options = {
host:'',
path:'/2/sms/send.html',
method:'POST',
agent:false,
rejectUnauthorized : false,
headers:{
'Content-Type' : 'application/x-www-form-urlencoded',
'Content-Length' :content.length
}
};
var req = http.request(options,function(res){
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log(JSON.parse(chunk));
});
res.on('end',function(){
console.log('over');
});
});
req.write(content);
req.end();
/*
注意:以上参数传入时不包括“<>”符号
*/
返回结果
{ "code":0, "msg":"发送成功" }
请参考