基于nodejs的阿里云API签名生成工具
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
README.md
index.js
package.json

README.md

AliToSign

基于nodejs的阿里云API签名生成工具

阿里云签名官方说明

安装方法:

npm install alitosign --save

使用方法:

例子:添加域名

const alitosign = require("alitosign");
const querystring = require("querystring");
const moment = require("moment");
const http =require("http");


//基本上调用�接口都需要的公共参数
let originParams = {
    AccessKeyId: "xxxxxxx", //AccessKeyId 获得方法请参照官方文档
    Format: "JSON",
    Version: "2015-01-09",
    SignatureMethod: "HMAC-SHA1",
    SignatureVersion: "1.0"
}

function AddDomain() {

    //复制一份公共参数
    let params = Object.assign({},originParams); 
    

    //在新的对象上添加你想调用的该接口必要参数,
    //每个接口都不一样,具体请查阅官方文档
    params.Action = "AddDomain";
    params.DomainName = "alili.tech";
    params.GroupId = "2223";

    //添加时间戳
    params.Timestamp = moment.utc().format(); //要用格林威治时间;
    params.SignatureNonce = new Date().getTime();
    
    //生成签名
    let signParams = alitosign(params);

    //将包含签名属性的对象转换成query格式的字符串
    let queryParams = querystring.stringify(signParams);
    
    //拼接url
    let url = `http://alidns.aliyuncs.com/?` + queryParams;

    //调用接口
    http.get(url, (res) => {
        res.on('data', function (data) {

            //序列化之后,就可以拿到你想要的数据了
            let oData = JSON.parse(data);

        });
    })

}