@

获取pmlib

引入依赖bundle.js,有以下两种方式:

  1. 从github下载postman collection ,并导入进你的集合里

  2. 所需js全部复制保存成一个全局变量如:pmlib_code

  3. 把自己的私钥设置成环境变量如:pri_key

使用Pre-request Script对请求进行加签(具体加签字段请看自己项目)

// 使用eval执行js
eval(pm.globals.get('pmlib_code')) // 生成rfctime
let date = new Date()
let y = date.getFullYear()
let m = date.getMonth()+1<10?'0'+(date.getMonth()+1):(date.getMonth()+1)
let d = date.getDate()<10?'0'+date.getDate():date.getDate()
let hh = date.getHours()<10?'0'+date.getHours():date.getHours();
let mm = date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes()
let ss = date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds()
this.rfc_time = y +'-' + m + '-' + d + ' ' + hh + ':' + mm + ':' + ss
this.rfc_time = this.rfc_time.replace(/\s+/g, 'T')+'+08:00'
pm.variables.set('rfctime',this.rfc_time)
// console.log(pm.variables.get('rfctime')) const privkey = pm.environment.get('pri_key').replace(/\\n/g, "\n") // 随机字符串
const uuid = pm.variables.replaceIn('{{$randomUUID}}')
pm.variables.set('nonce_str', uuid) const requestBodyRaw = pm.variables.replaceIn(pm.request.body == undefined ? '' : pm.request.body.raw) const now = pm.variables.replaceIn('{{$timestamp}}')
pm.variables.set('req_time', now)
// 具体加密字段拼接请依据项目情况案例是:method+\n+url+\n+timestamp+\n+nonce_str+\n+body
var dataToSign = pm.request.method + "\n" +
pm.request.url.getPathWithQuery() + "\n" +
now + "\n" +
uuid + "\n" +
requestBodyRaw console.log(dataToSign) const sha256withrsa = new pmlib.rs.KJUR.crypto.Signature({"alg": "SHA256withRSA"});
sha256withrsa.init(privkey); sha256withrsa.updateString(dataToSign); const sign = pmlib.rs.hextob64(sha256withrsa.sign()); // console.log(sign);
pm.variables.set('sign', sign)
// 添加请求头
pm.request.headers.add({
key:"Authorization",
value:"SHA256-RSA nonce_str={{nonce_str}},timestamp={{req_time}},signature={{sign}}"
});

至此SHA256withRSA签名已完成

最新文章

  1. C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 角色成员功能的改进支持公司加入到角色
  2. 交叉编译mips平台上valgrind
  3. The Dragon of Loowater
  4. Java中HashMap的数据结构
  5. iOS开发——动画编程Swift篇&amp;(四)CABasicAnimation动画
  6. 【阿里云产品公测】开放搜索服务 opensearch java jdk 应用体验之 机器人聊天
  7. 【HDOJ】4504 威威猫系列故事——篮球梦
  8. 关于close和shutdown
  9. 春招实习面经分享(已拿到腾讯春招Offer)
  10. Gradle 1.12 翻译——第十二章 使用Gradle 图形用户界面
  11. 检查Json格式工具
  12. SQL server存储过程,触发器,游标相关实例
  13. .NET Core[MVC] 利用特性捕捉异常
  14. JAVA学习笔记 (okHttp3的用法)
  15. PyAutoGUI——让所有GUI都自动化
  16. QT心电图设计
  17. Ping--域名替换重要角色
  18. redis+thinkphp5的注册、登陆、关注基础例子
  19. Qt5 中文乱码问题
  20. VMware虚拟机配置端口转发(端口映射),实现远程访问【转】

热门文章

  1. 对于MySQL远程连接中出现的一个问题总结
  2. 微信小程序--聊天室小程序(云开发)
  3. .ssh/config 常用配置
  4. vue 引入 tcplayer,并且实现视频点播,腾讯点播
  5. IPv6 QoS 多媒体应用:性能分析 (上)
  6. 聚类算法与K-means实现
  7. npm 淘宝镜像与官方源 切换
  8. vue实现拖动div元素
  9. Filter案例之登录验证
  10. vue开发 回到顶部操作