短信验证码服务+中正云通讯+nodejs

NOTE.js HTTP  POST请求方式

var http = require('http');  
   
var qs = require('querystring');  
   
var post_data = {  
    uid:'帐号',
    pwd:'密码',
    tos:'号码',
    msg:'【中正云通信】您的验证码是:610912,3分钟内有效。如非您本人操作,可忽略本消息。',
    otime:' '  
};//这是需要提交的数据  
   
   
var content = qs.stringify(post_data);  
   
var options = {  
    hostname: 'service2.winic.org',  
    port: 8003,  
    path: '/service.asmx/SendMessages',  
    method: 'POST',  
    headers: {  
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'  
    }  
};  
   
var req = http.request(options, function (res) {  
    console.log('STATUS: ' + res.statusCode);  
    console.log('HEADERS: ' + xml.stringify(res.headers));  
    res.setEncoding('utf8');  
    res.on('data', function (chunk) {  
        console.log('BODY: ' + chunk);  
    });  
});  
   
req.on('error', function (e) {  
    console.log('problem with request: ' + e.message);  
});  
   
// write data to request body  
req.write(content);  
   
req.end();


NOTE.js HTTP  GET请求方式



var http = require('http');  
   
var qs = require('querystring');  
   
var data = {  
    uid:'帐号',
    pwd:'密码',
    tos:'号码',
    msg:'【中正云通信】您的验证码是:610912,3分钟内有效。如非您本人操作,可忽略本消息。',
    otime:' '
};//这是需要提交的数据  
   
   
var content = qs.stringify(data);  
   
var options = {  
    hostname: 'service2.winic.org',  
    port: 8003,  
    path: '/service.asmx/SendMessages?' + content,  
    method: 'GET'  
};  
   
var req = http.request(options, function (res) {  
    console.log('STATUS: ' + res.statusCode);  
    console.log('HEADERS: ' + xml.stringify(res.headers));  
    res.setEncoding('utf8');  
    res.on('data', function (chunk) {  
        console.log('BODY: ' + chunk);  
    });  
});  
   
req.on('error', function (e) {  
    console.log('problem with request: ' + e.message);  
});  
   
req.end();

中正云网址:http://www.winic.org/index.asp

短信验证码服务+中正云通讯+nodejs_第1张图片

你可能感兴趣的:(nodejs)