首页 > 其他分享 >Postman/apifox pre-request script

Postman/apifox pre-request script

时间:2023-12-14 16:13:17浏览次数:29  
标签:pre nonce const timestamp request sign params key apifox

Postman/apifox pre-request script

const UUID = require('uuid');
// Helper function to generate the signature
function makeSign(md5Key, params) {
  const preStr = buildSignString(params);
  const text = preStr + md5Key;
  console.log("signString=",text);
  return CryptoJS.MD5(text).toString().toUpperCase();
}

// Helper function to build the sign string
function buildSignString(params) {
  if (!params || Object.keys(params).length === 0) {
    return "";
  }

  const keys = Object.keys(params).filter(key => key !== "sign" && params[key] !== null && params[key] !== "");

  keys.sort();

  let signString = "";

  for (let i = 0; i < keys.length; i++) {
    const key = keys[i];
    const value = typeof(params[key])==='object'?  JSON.stringify(params[key]):params[key].toString();

    if (i === keys.length - 1) {
      signString += `${key}=${value}`;
    } else {
      signString += `${key}=${value}&`;
    }
  }

  return signString;
}

// Parse the JSON object
// const jsonString = `{"creationId":"190017","status":"1","remark":""}`;
const requestBody = pm.request.body;
const jsonString = requestBody.raw;
const params = JSON.parse(jsonString);
// Generate the nonce and timestamp
const nonce = UUID.v4();;
const timestamp = Math.floor(Date.now() / 1000).toString();

// Set the application key
const appKey = "rc8nlpfaqiri8l9g";
params.nonce = nonce;
params.applicationKey = appKey;
params.timestamp = timestamp;

console.log(params)

// Generate the sign
const appSecret = "ncbj91gr5y5w5ux11a0e7kfash";
const sign = makeSign(appSecret, params);

// Set the headers
const headers = {
  "appKey": appKey,
  "sign": sign,
  "timestamp": timestamp,
  "nonce": nonce,
};

pm.environment.set("headers", headers);
pm.environment.set("appKey", appKey);
pm.environment.set("sign", sign);
pm.environment.set("timestamp", timestamp);
pm.environment.set("nonce", nonce);

 

请求时增加参数占位符

curl --location --request POST 'http://127.0.0.1/v1/getMember' \
--header 'Application-Key: {{appKey}}' \
--header 'timestamp: {{timestamp}}' \
--header 'nonce: {{nonce}}' \
--header 'signature: {{sign}}' \
--header 'Content-Type: application/json' \
--data-raw '{
  "mobile": "15815593592"
}'

 

标签:pre,nonce,const,timestamp,request,sign,params,key,apifox
From: https://www.cnblogs.com/zhshlimi/p/17901385.html

相关文章

  • 软件测试/人工智能|解决Selenium中的异常问题:“error sending request for url”
    前言在使用Selenium自动化测试时,有时会遇到“errorsendingrequestforurl”这样的异常。这个问题通常与Chrome浏览器驱动程序和网络请求相关。本文让我们来了解如何解决这个问题。问题原因这个异常通常出现在Selenium与Chrome浏览器交互时,可能由于网络请求或Chrome驱动程序......
  • 界面控件DevExpress .NET MAUI v23.1 - 发布一系列新组件
    DevExpress拥有.NET开发需要的所有平台控件,包含600多个UI控件、报表平台、DevExpressDashboardeXpressApp框架、适用于VisualStudio的CodeRush等一系列辅助工具。屡获大奖的软件开发平台DevExpress今年第一个重要版本v23.1正式发布,该版本拥有众多新产品和数十个具有高影响力......
  • 北航中法工程师学院-英语课Presentation
    Goodmorning,everyone.I'mtoday'spresenter,LiAnguo,andmytopicis"RulebyAlgorithm:WillArtificialIntelligenceControlHumanity?"Firstly,let'srevisitthegistofEpisode6ofthefirstseasonof"SiliconValley.......
  • React-native ios运行报错 No bundle URL present
    新建项目报错如下:需要手动生成ios下的main.jsbundle文件解决方法:1、生成main.jsbundle文件,在终端项目目录下执行:react-nativebundle--entry-fileindex.js--bundle-output./ios/main.jsbundle--platformios--assets-dest./ios--devfalse或在package.json里面添加以下执......
  • [粘贴]关于preparedStatement
    作者:wuxinliulei链接:https://www.zhihu.com/question/37043270/answer/83914933来源:知乎著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。这个问题的答案,可以参看这篇文章:http://www.importnew.com/5006.htmlJDBC为什么要使用PreparedStatement而不是S......
  • simpread-Ubuntu 扩容磁盘、扩容内存_ubuntu 扩容 the file system can not be resize
    原文地址blog.csdn.net参考:Ubuntu磁盘扩容及启动问题整理作者:一只青木呀发布时间:2020-12-0810:42:19网址:https://blog.csdn.net/weixin_45309916/article/details/110850358也可参照正点原子的:Ubuntu磁盘空间不足?一招轻松扩容Ubuntu磁盘扩容(简单亲测有效)Ubuntu......
  • The Devil Is in the Details: Window-based Attention for Image Compression
    目录简介简介基于CNN的模型的一个主要缺点是cNN结构不是为捕捉局部冗余而设计的,尤其是非重复纹理,这严重影响了重建质量。受视觉转换器(ViT)和SwinTransformer最新进展的启发,我们发现将局部感知注意机制与全局相关特征学习相结合可以满足图像压缩的期望。介绍了一种更简单有效......
  • DevExpress WinForms Pivot Grid组件,一个类似Excel的数据透视表控件(二)
    界面控件DevExpressWinForms的PivotGrid组件是一个类似Excel的数据透视表控件,用于多维(OLAP)数据分析和跨选项卡报表。在上文中(点击这里回顾>>)我们介绍了DevExpressWinFormsPivotGrid组件的性能、分析服务、数据塑造能力等,本文将继续介绍该组件的其他功能,欢迎持续关注我们哦~......
  • 深入解析Python网络编程与Web开发:urllib、requests和http模块的功能、用法及在构建现
     网络和Web开发是Python中不可或缺的重要领域,而其核心模块如urllib、requests和http在处理网络请求、HTTP请求和响应以及Web开发中扮演着关键的角色。这些模块为开发者提供了丰富的工具,使其能够灵活处理网络通信、构建Web应用和与远程服务器进行交互。深入了解这些模块的用法和作......
  • nodejs的http.request最大响应体
    nodejs的http.request躺坑记录1、http.request之response.on("data",(chunk:Buffer)=>{})的chunk大小​ 由于nodejs的response.on("data")每次从服务端读取的chunk大小最大是65535Byte,并且查很多网站都找不大这个说明点所以狠狠踩了这个坑。这个65535有什么影响呢。本来编写的......