• postman自动化,测试脚本


    //获取当前时间的时间戳
    function getTimestamp(len=10) {
    //  如果需要自动获取则将此处代码放开
    //  var tmp = Date.parse( new Date() ).toString();
     // tmp = tmp.substr(0,len);
      //return tmp;
         return '1546571642'
    }
    //时间戳换算时间
    function timestampToTime(timestamp) {
    	//时间戳为10位需*1000,时间戳为13位的话不需乘1000
       let date = new Date(timestamp * 1000);
       let Y = date.getFullYear() + '-';
       let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
       let D = date.getDate() > 10 ? date.getDate():'0'+date.getDate();
       return Y+M+D;
    }
    
    // 秘钥ID
    let SecretId = 'XXXXXXXXXXX';
    // 秘钥key
    let SecretKey = 'XXXXXXXXXXXXX';
    // 服务器地址
    let host = 'timatrix.tencentcloudapi.com';
    // 产品名
    let service = 'timatrix';
    // 时间戳
    let RequestTimestamp = getTimestamp(10);
    //提交方式
    let HTTPRequestMethod = request.method;
    // Content-Type数据类型
    let contentType = 'multipart/form-data'
    let CanonicalURI = '/';
    let CanonicalQueryString = '';
    let CanonicalHeaders ;
    if(HTTPRequestMethod == "POST" || HTTPRequestMethod == "post"){
    //   contentType = 'multipart/form-data'
    //   CanonicalHeaders = 'content-type:multipart/form-data
    host:'+host+'
    ';
    //   上面是文件
      contentType = 'application/json'
      CanonicalHeaders = 'content-type:application/json
    host:'+host+'
    ';
    } else if (HTTPRequestMethod == "GET" || HTTPRequestMethod == "get"){
      contentType = 'application/x-www-form-urlencoded'
      CanonicalHeaders = 'content-type:application/x-www-form-urlencoded
    host:'+host+'
    ';
    } else {
      contentType = 'application/json'
      CanonicalHeaders = 'content-type:application/json
    host:'+host+'
    ';
    }
    let SignedHeaders = 'content-type;host';
    let RequestPayload = '';
    let HashedRequestPayload = CryptoJS.SHA256(encodeURIComponent(RequestPayload));
    let CanonicalRequest =
      HTTPRequestMethod + '
    ' +
      CanonicalURI + '
    ' +
      CanonicalQueryString + '
    ' +
      CanonicalHeaders + '
    ' +
      SignedHeaders + '
    ' +
      HashedRequestPayload;
    let Algorithm = 'TC3-HMAC-SHA256';
    
    let CredentialScope = timestampToTime(RequestTimestamp)+'/'+service+'/tc3_request';
    let HashedCanonicalRequest = CryptoJS.SHA256(CanonicalRequest);
    let StringToSign =
      Algorithm + '
    ' +
      RequestTimestamp + '
    ' +
      CredentialScope + '
    ' +
      HashedCanonicalRequest;
    let SecretDate = CryptoJS.HmacSHA256(timestampToTime(RequestTimestamp),"TC3" + SecretKey);
    let SecretService = CryptoJS.HmacSHA256(service,SecretDate);
    let SecretSigning = CryptoJS.HmacSHA256("tc3_request",SecretService);
    let Signature = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA256(StringToSign,SecretSigning));
    Signature = Signature.toLowerCase()
    let Authorization =
      Algorithm + ' ' +
      'Credential=' + SecretId + '/' + CredentialScope + ', ' +
      'SignedHeaders=' + SignedHeaders + ', '+
      'Signature=' + Signature
    postman.setEnvironmentVariable('host', host);
    postman.setEnvironmentVariable('contentType', contentType);
    postman.setEnvironmentVariable('RequestTimestamp', RequestTimestamp);
    postman.setEnvironmentVariable('Authorization', Authorization);
    

      

  • 相关阅读:
    sql 2012中获取表的信息,包含字段的描述
    C#如何创建泛型类T的实例
    C# 之 DataReader 和 DataSet 的区别
    C#进阶系列——WebApi 接口参数不再困惑:传参详解
    IIS事件查看器_WebServer事件查看器_帮助查看IIS-Web服务器事件执行日志
    SQL分页查询的几种方式
    freeRTOS中文实用教程3--中断管理之延迟中断处理
    freeRTOS中文实用教程2--队列
    freeRTOS中文实用教程1--任务
    UML和模式应用5:细化阶段(5)---系统顺序图
  • 原文地址:https://www.cnblogs.com/ChineseLiao/p/10257088.html
Copyright © 2020-2023  润新知