nodejs版 阿里云开放api签名算法
阿里云 API 签名
github:https://github.com/liuyinglong/aliyun;
npm :https://www.npmjs.com/package/aliyun-apisign
阿里云已开放的API
https://develop.aliyun.com/tools/openapilist
install
npm install aliyun-apisign --save
use
let AliCloudClient = require("../aliCloudClient");
let aliClient=new AliCloudClient({
AccessKeyId:"your AccessKeyId",
AccessKeySecret:"your AccessKeySecret",
serverUrl:"http://alidns.aliyuncs.com"
});
//获取解析列表
aliClient.get("/",{
Action:"DescribeDomainRecords",
DomainName:"yourDomain.cn"
}).then(function(data){
console.log(data.body)
}).catch(function(err){
console.log(err);
});
小案例-》利用阿里云开放api进行动态域名解析
每分钟获取一次公网 IP,如果检测到公网IP发生了变化,则调用aliyun的开放接口进行更新
let AliCloudClient = require("../aliCloudClient");
let Req = require("../request");
let request = new Req();
let schedule = require("node-schedule");
let aliClient = new AliCloudClient({
AccessKeyId: "your AccessKeyId",
AccessKeySecret: "your AccessKeySecret",
serverUrl: "http://alidns.aliyuncs.com"
});
let domainNameValue = "www";
let recordId, //记录ID
ip;
function getMyIp() {
return request.post("http://ip.taobao.com/service/getIpInfo2.php", {
ip: "myip"
}).then(function (data) {
return data.body.data.ip;
}).catch(function (err) {
return Promise.reject(err);
})
}
function getDomainRecords() {
return aliClient.get("/", {
Action: "DescribeSubDomainRecords",
SubDomain: "www.yourDomain.cn"
}).then(function (data) {
let body = data.body;
let record = body.DomainRecords.Record[0];
recordId = record.RecordId;
return record.Value;
}).catch(function (err) {
return Promise.reject(err);
})
}
function upDateRecords() {
return aliClient.get("/", {
Action: "UpdateDomainRecord",
RecordId: recordId,
RR: domainNameValue,
Type: "A",
Value: ip
}).then(function (data) {
console.log(new Date() + ip + " 修改成功");
}).catch(function (err) {
console.log(err)
})
}
function watchIpChange() {
return getMyIp().then(function (tempIp) {
if (ip === tempIp) {
return;
}
if (!ip) {
return;
}
console.log(new Date()+ ip + "=>"+ tempIp);
ip = tempIp;
upDateRecords();
}).catch(function(err){
console.log(err);
})
}
Promise.all([getMyIp(), getDomainRecords()]).then(function (result) {
ip = result[0];
let domainValue = result[1];
if (ip !== domainValue) {
upDateRecords();
}
});
schedule.scheduleJob("0 * * * * *", function () {
watchIpChange();
});
nodejs版 阿里云开放api签名算法的更多相关文章
- 开个坑, 写个阿里云开放储存服务(OSS)的C++版SDK以及客户端
这应该是继我研究手册QQ协议后的第2个稍微正式一点的网络程序, 不只是Scoket套接字编程, 还涉及到更多的HTTP协议知识! 阿里云开放储存服务OSS官方已经提供了不少SDK, 包括PHP/Pyt ...
- 如何安装NodeJS到阿里云Centos (64位版本V5-7)
如何安装NodeJS到阿里云Centos (64位版本V5-7) (Centos与Red Hat® Enterprise Linux® / RHEL, Fedora属于一类) 1) 安装v0.10版 ...
- 基于PHP实现阿里云开放存储服务
开放存储服务(OpenStorageService,简称OSS),是阿里云对外提供的海量,安全,低成本,高可靠的云存储服务.用户可以通过简单的API(REST方式的接口),在任何时间.任何地点.任何互 ...
- C#调用阿里云CDN API刷新缓存
使用CDN必须要解决CDN缓存的问题,要么在每次更新文件时生成不同的URL,要么在每次更新文件时刷新CDN缓存.我们在一个实际应用场景中用到了后者,所以需要调用阿里云CDN的API进行缓存刷新的操作. ...
- 阿里云Open API自动化脚本—ECS公网IP转化弹性公网IP
1.OpenAPI Explorer 记录一下使用阿里云 Open API 自动化/脚本化 “ECS 公网 IP 转化弹性公网 IP”的实现 全过程.原博客地址:https://www.markedi ...
- 阿里云DNS api接口 shell 更改DNS解析
可定时任务检查域名解析,调用alidns.sh更新DNS解析 #!/bin/bash # alidns.sh #https://www.cnblogs.com/elvi/p/11663910.html ...
- Java版阿里云通信短信发送API接口实例(新)
阿里云通信(原名阿里大于)的短信服务(Short Message Service)是阿里云为用户提供的一种通信服务的能力,支持快速发送短信验证码.短信通知等. 完美支撑双11期间2亿用户,发送6亿短信 ...
- NodeJS 实现阿里云推送。
虽然阿里云推送也有 NodeJS SDK ,只要在项目中引用 aliyun-sdk 就可以使用了.里面的推送功能了. 我在这里就不写怎么使用aliyun-sdk.给出来的DEMO是回调形式的.用起来有 ...
- springmvc学习笔记--支持文件上传和阿里云OSS API简介
前言: Web开发中图片上传的功能很常见, 本篇博客来讲述下springmvc如何实现图片上传的功能. 主要讲述依赖包引入, 配置项, 本地存储和云存储方案(阿里云的OSS服务). 铺垫: 文件上传是 ...
随机推荐
- 剑指offer前6题
二维数组中的查找 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 时间限制:1秒 ...
- Python学习笔记,day5
Python学习笔记,day5 一.time & datetime模块 import本质为将要导入的模块,先解释一遍 #_*_coding:utf-8_*_ __author__ = 'Ale ...
- hdu 1372 BFS
A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the sh ...
- java项目---用java重命名文件(1星)
package Demo; import java.io.File; public class FileRename { public static boolean Rename(String old ...
- node.js跨域
先上解决方法:在函数中添加(不要用xhr请求) // 只需要关心第二个参数res.setHeader('Access-Control-Allow-Origin', 'http://localhost: ...
- vue---- v-bind指令
v-bind指令用于给html标签设置属性. 基本用法 <div id="app"> <div v-bind:id="id1">文字&l ...
- 使用LNMP架构部署动态网站环境(源代码安装)
- R并行计算
# 参考文献: https://cosx.org/2016/09/r-and-parallel-computinghttps://blog.csdn.net/sinat_26917383/articl ...
- chrome添加离线插件
1.首先用户点击谷歌浏览器右上角的自定义及控制按钮,在下拉框中选择工具选项,然后点击扩展程序来启动Chrome浏览器的扩展管理器页面. 2.在打开的谷歌浏览器的扩展管理器中用户可以看到一些已经安装程序 ...
- Linux printf命令详解
Linux printf命令 printf命令模仿了C语言中的printf()函数.主要作用是输出文本,按照我们指定的格式输出文本.还有一个输出文本的命令echo,在输出文本时,echo会换行.pri ...