美文网首页
postman 时间戳和加密

postman 时间戳和加密

作者: Demon_半夏 | 来源:发表于2019-06-25 15:14 被阅读0次
    //发起请求之前获取当前的时间戳放在参数里
    //postman.setGlobalVariable("customerCode","***2345677***");
    //1.设置环境变量 postman.setEnvironmentVariable("key", "value");
    //2.设置全局变量 postman.setGlobalVariable("key", "value");
    //environment.customerCode = "***2345677***";
    customerCode = postman.getGlobalVariable("customerCode");
    //设置当前时间戳毫秒
    postman.setGlobalVariable("timestamp",Math.round(new Date().getTime()));
    //environment.timestamp = Math.round(new Date().getTime());
    //postman.setEnvironmentVariable("unixtime_now","timecode");
    //var jsonData = JSON.parse(request.data.applyJsonStr);
    //postman.setGlobalVariable("ytoken","*********b176a4739bfccb*********");
    //获取全局变量
    //如postman.getGlobalVariable("key");
    customerCode = postman.getGlobalVariable("customerCode");
    timestamp = postman.getGlobalVariable('timestamp');
    ytoken = postman.getGlobalVariable("ytoken");
    var str = customerCode+timestamp+ytoken;
    //postman.setEnvironmentVariable("str",str);
    //environment.str = str;
    postman.setGlobalVariable("str",str);
    //var md5 = CryptoJS.MD5(str).toString().toLowerCase();
    //使用md5加密
    //var strmd5 = CryptoJS.MD5(str).toString();
    var strmd5 = CryptoJS.MD5(str);
    //environment.strmd5 = strmd5;
    postman.setGlobalVariable('md5',strmd5);
    //environment.md5 = md5;
    //timecode=System.currentTimeMillis();
    console.log(str);
    '''
    '''
    if(responseCode.code === 200){
    // 判断是否存在 'success' 值  
    tests["Body matches code"] = responseBody.has("0");
    //获取响应结果result,作为下一个接口的入参
    var jsonData = JSON.parse(responseBody);
    postman.setGlobalVariable("sessionId",jsonData.result);
    tests[`[INFO] Request params: ${JSON.stringify(request.data)}`] = true;
    // tests["have result "]=jsonData.hasOwnProperty("error")!==true;
    tests["have result "]=jsonData.hasOwnProperty("result")===true;
    tests[`[INFO] Response timeout: ${responseTime}`] = responseTime < 6000;
    }else{
    //接口请求失败
    tests["Waring:Request Failed. Please Fix!"] = false;
    }
    

    相关文章

      网友评论

          本文标题:postman 时间戳和加密

          本文链接:https://www.haomeiwen.com/subject/hvgtcctx.html