让您全面了解并上手亿速云产品
常见入门级使用教程
对外 API 开发文档中心
您历史提交的工单
您的每一条意见,我们都严谨处理
您的每一条建议,我们都认真对待
var https = require("https")
var CryptoJS = require('C:/Users/Administrator/AppData/Roaming/npm/node_modules/crypto-js');
function random(lower, upper) {
return Math.floor(Math.random() * (upper - lower)) + lower;
}
function sortDict(dict){
var dict2={},
keys = Object.keys(dict).sort();
for (var i = 0, n = keys.length, key; i < n; ++i) {
key = keys[i];
dict2[key] = dict[key];
}
return dict2;
}
var accessId = '*****';
var accessSecret = '*****';
var params = {
'accessId': accessId,
'templateCode': 100001,
'timestamp': Math.round(Date.now()/1000),
'nonce': random(10000000, 99999999),
'phone':'13800000000',
'templateVars': JSON.stringify({"code":"123123","min":5})
}
sorted_params = sortDict(params);
var params_str = "";
for(var key in sorted_params) {
params_str += (key + '=' + sorted_params[key] + '&')
}
params_str = params_str.substring(0, params_str.length - 1)
params['signature'] = CryptoJS.HmacSHA1(params_str, accessSecret).toString(CryptoJS.enc.Base64);
let data = require('querystring').stringify(params);
var options = {
host:"api.yisu.com",
port:443,
strictSSL: false,
rejectUnauthorized: false,
path:"/sms/sendSms",
method:"POST",
headers:{
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Content-Length' : data.length,
}
}
var req = https.request(options, function(res){
var responseStr = '';
res.on('data', function (chunk) {
responseStr += chunk;
});
res.on('end', function() {
console.log(responseStr);
});
});
req.write(data);
req.end();
Copyright © Yisu Cloud Ltd. All Rights Reserved. 2018 版权所有
广州亿速云计算有限公司 粤ICP备17096448号-1 粤公网安备 44010402001142号 增值电信业务经营许可证编号:B1-20181529