短信平台API接口demo示例-Node/SMS/MultiXSend
DEMO: SMS/MultiXSend - 短信模板一对多发送
【短信平台API接口demo示例-Node/SMS/MultiXSend】原文链接
var request = require('request');
var crypto = require('crypto');
var appid = "input your appid";
var appkey = "input your appkey";
var api = "https://api-v4.mysubmail.com/sms/multixsend";
//生成加密签名function BuildSignature(params){
var sorted = [];
for(var key in params) {
sorted[sorted.length] = key;
}
sorted.sort();
var tempDict = {};
for(var i = 0;
i < sorted.length;
i++) {
tempDict[sorted[i]] = params[sorted[i]];
}
var signStr = "";
for(var key in tempDict) {
signStr += key + '=' + tempDict[key] + '&
';
}
signStr = signStr.substring(0, signStr.length-1);
signStr = appid + appkey + signStr + appid + appkey;
var md5sum = crypto.createHash('md5');
md5sum.update(signStr);
return md5sum.digest('hex');
}
//multi参数示例var multi = [{
to :"152********",
vars : {
code : "123456",
time : "6月15日"
}
},{
to :"153********",
vars : {
code : "123456",
time : "6月15日"
}
},{
to :"155********",
vars : {
code : "123456",
time : "6月15日"
}
}]
//无加密示例request.post({
url: api,
formData: {
appid:appid,
signature:appkey,
project : "9vFM31",
multi : JSON.stringify(multi)
}
}, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error(err);
}
console.log(body);
});
//加密示例request({
uri: "https://api-v4.mysubmail.com/service/timestamp",
method: 'GET'
}, function(error, response, body) {
var result = JSON.parse(body);
var requestParams = {}
requestParams['timestamp'] = result["timestamp"];
requestParams['sign_type'] = "md5";
requestParams['appid'] = appid;
requestParams['sign_version'] = "2";
requestParams['project'] = "9vFM31";
requestParams['signature'] = BuildSignature(requestParams);
requestParams['multi'] = JSON.stringify(multi);
request.post({
url: api,
formData: requestParams
}, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error(err);
}
console.log(body);
});
});
推荐阅读
- 短信平台API接口demo示例-Node/SMS/MultiSend
- 显示器模拟接口与数字接口有何区别?
- 打印机接口分类
- AppcanapicloudHBuilder 不同之处解析
- MapReduce API介绍和用法
- SSM框架搭建 数据库创建和MyBatis生成器自动生成实体类DAO接口和Mapping映射文件
- Android API Guides –System Permissions
- Android中Parcelable接口使用方法
- api-gateway实践(14)新服务网关 - 业务场景验证api-gateway-engine携带有效token访问SvcApp (未完!!!!!!!!!!)
- api-gateway实践(10)新服务网关-新需求验证api-gateway-engine携带有效token访问SvcApp