Skip to content

pengng/alidns-signature

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alidns-signature

阿里云DNS开放API签名生成工具

Usage

npm i alidns-signature -S
const http = require('http')
const querystring = require('querystring')
const Signature = require('alidns-signature')
const sign = new Signature({
    accessKeyId: '',
    accessKeySecret: ''
})

// 获取解析记录API的专有参数
let query = sign.getReqParams({
    Action: 'DescribeDomainRecords',
    DomainName: 'example.com'
})

http.get('http://alidns.aliyuncs.com?' + querystring.stringify(query), function (res) {
    let buf = []
    res.on('data', buf.push.bind(buf)).on('end', function () {
        console.log(Buffer.concat(buf).toString())
    })
})

Method

  • getReqParams(params[, httpMethod])

    传入请求query对象和请求方法(默认为GET),返回包含公共参数的新对象

const sign = new Signature({
    accessKeyId: '',
    accessKeySecret: ''
})

// 获取解析记录API的专有参数
let query = sign.getReqParams({
    Action: 'DescribeDomainRecords',
    DomainName: 'example.com'
})
/*
返回对象包含专有参数在内的全部参数,使用 querystring.stringify 序列化成字符串即可使用
{ Format: 'JSON',
  Version: '2015-01-09',
  AccessKeyId: 'LTAIqGVsYW7HAqEf',
  SignatureMethod: 'HMAC-SHA1',
  Timestamp: '2018-05-19T01:52:21.044Z',
  SignatureVersion: '1.0',
  SignatureNonce: 1526694752445,
  Action: 'DescribeDomainRecords',
  DomainName: 'guoyupeng.me',
  Signature: 'wySsR2XAsYhFRke+ZleO7rn9LFk=' }
*/
  • getSignature(params[, httpMethod])

    传入请求query对象和请求方法(默认为GET),返回签名字符串

const sign = new Signature({
    accessKeyId: '',
    accessKeySecret: ''
})

// 接口公共参数
let pubParams = {
    Format: 'JSON',
    Version: '2015-01-09',
    AccessKeyId: '',
    SignatureMethod: 'HMAC-SHA1',
    Timestamp: new Date().toUTCString(),
    SignatureVersion: '1.0',
    SignatureNonce: Date.now()
}

// 获取解析记录API的专有参数
let apiParams = {
    Action: 'DescribeDomainRecords',
    DomainName: 'example.com'
}

// 混合全部参数
let params = Object.assign({}, pubParams, apiParams);

let sign = sign.getSignature(params)
// return 'wySsR2XAsYhFRke+ZleO7rn9LFk='

About

Generate ali DNS cloud API request signature

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published