短信平台API接口demo示例-Node/SMS/Send
DEMO: SMS/Send - 短信发送
【短信平台API接口demo示例-Node/SMS/Send】原文链接
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/send";
//生成加密签名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');
}
//无加密示例request.post({
url: api,
formData: {
appid:appid,
signature:appkey,
content : "【SUBMAIL】您的验证码是123456,请在6月15日内输入。",
to : "155********"
}
}, 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['to'] = "155********";
requestParams['signature'] = BuildSignature(requestParams);
requestParams['content'] = "【SUBMAIL】您的验证码是123456,请在6月15日内输入。";
request.post({
url: api,
formData: requestParams
}, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error(err);
}
console.log(body);
});
});
推荐阅读
- 短信平台API接口demo示例-Node/SMS/XSend
- 如何使用MediaStream API录制音频(分步指南)
- 如何使用Vue 3 Composition API创建可重用组件()
- 测试|学习总结——接口测试中抓包工具的使用
- Android实战之 万能的接口回调
- Android 高版本API方法在低版本系统上的兼容性处理
- 前台主页搭建、后台主页轮播图接口设计、跨域问题详解、前后端互通、后端自定义配置、git软件的初步介绍
- webapi “ObjectContent`1”类型未能序列化内容类型“application/xml; charset=utf-8”的响应正文。
- Spring|Spring Boot统一接口返回及全局异常处理
- Azure|Azure DevOps (十一) 通过Azure Devops部署一个.NET Core WebAPI