example_use_tps.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @file 隧道代理使用示例
  3. * 接口鉴权说明:
  4. * 目前支持的鉴权方式有 "token" 和 "hmacsha1" 两种,默认使用 "token"鉴权。
  5. * 所有方法均可添加关键字参数signType修改鉴权方式。
  6. * @author www.kuaidaili.com
  7. */
  8. const Client = require('../kdl/client');
  9. const Auth = require('../kdl/auth');
  10. auth = new Auth('secret_id','secret_key');
  11. client = new Client(auth);
  12. // 获取订单到期时间
  13. client.getOrderExpireTime('hmacsha1').then(
  14. value => {
  15. console.log(value);
  16. }
  17. );
  18. // 获取ip白名单
  19. client.getIpWhitelist('hmacsha1').then(
  20. value => {
  21. //console.log('value的值为:');
  22. console.log(value);
  23. }
  24. );
  25. // 设置白名单 参数为字符串。如下
  26. client.setIpWhitelist("171.113.244.20,171.113.244.41",'hmacsha1').then(value => {});
  27. // 显示当前隧道代理ip
  28. client.tpsCurrentIp('hmacsha1').then(value=>{
  29. console.log(value);
  30. });
  31. // 修改当前隧道代理ip
  32. // client.changeTpsIp('hmacsha1').then(
  33. // value => {
  34. // console.log(value);
  35. // }
  36. // );
  37. // 获取指定订单访问代理IP的鉴权信息。
  38. // 鉴权信息包含用户名密码,用于请求私密代理/独享代理/隧道代理时进行身份验证。
  39. // 参考:https://www.kuaidaili.com/doc/api/getproxyauthorization/
  40. client.getProxyAuthorization(1,'token').then(
  41. value => {
  42. console.log(value);
  43. }
  44. )
  45. // 获取隧道代理ip
  46. // 构造请求参数。具体看
  47. // https://www.kuaidaili.com/doc/api/gettps/
  48. params = {
  49. format:'json',
  50. };
  51. client.getTps(2,'hmacsha1',params).then(
  52. value => {
  53. console.log(value);
  54. }
  55. );