讓您全面了解并上手億速云產品
常見入門級使用教程
對外 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