2.0.5 • Published 5 years ago

node-top v2.0.5

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

基于async/await实现的淘宝开放平台sdk

使用方法

var alitop=require('node-top');
var top=new alitop(appkey,appsecret);
var response=await top.Execute(method,args);

设置

  • timeout:指定超时时间,默认30秒,单位ms

  • retry_times:当发生错误时,也可以通过环境变量TOP_MAX_RETRY_TIMES指定,最大重试次数,默认5次

  • retry_code:自定义的可以重试的错误代码,默认:[]。淘宝平台的isp错误都会重试。

  • rest_url:淘宝开放平台接口调用地址,也可以通过环境变量TOP_REST_URL指定,默认值:http://gw.api.taobao.com/router/rest

  • retry_interval:发生可重试错误的间隔时间,也可以通过环境变量TOP_RETRY_INTERVAL指定,单位ms,默认值:5000

  • TOP_PROXY:通过代理服务器访问TOP平台。也可以通过环境变量TOP_PROXY设置代理服务器。

附件上传

对于文件上传,可以直接指定参数为可读流。也可以指定为一个对象

{
    attachment:true,
    value:fs.createReadStream('./1.jpg'),
    options:{
        knownLength:1,
        filename: 'unicycle.jpg',
        contentType: 'image/jpg',
    }
}

日志记录

每一个top实例,都可以侦听completed事件来记录日志。

on方法侦听函数返回两个参数:

  • request:请求top时的数据

  • response:top的响应数据

var alitop=require('node-top');
var top=new alitop(appkey,appsecret).on('completed',function(request,response){});
var response=await top.Execute(method,args);

消息接收

该功能代码复制并修改于ali-topSdk

每一个top实例,可以调用方法Listen来监听服务器的消息。

Listen包含三个参数:

  • group_name:监听的消息分组,默认值:default

  • url:连接到的淘宝消息服务器,也可以通过环境变量TOP_TMC_URL设置,默认值:ws://mc.api.taobao.com/

  • handler:消息处理函数,一个async函数或者Promise对象

var alitop=require('node-top');
var top=new alitop(appkey,appsecret);
top.Listen(async function(message){
    console.log(message);
})

更新日志

  • 2019-03-24 增加通过环境变量设置代理服务器。

  • 2018-03-19 增加通过环境变量设置重试次数和重试间隔

  • 2018-03-19 增加通过环境变量设置接口地址

  • 2017-05-22 修正不能上传附件

  • 2017-05-18 增加消息接收

  • 2017-05-05 修复网络错误不重试。

2.0.5

5 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago