POSTMAN使用

POSTMAN使用

解密响应报文

说明

使用test执行脚本,处理数据。并将结果展示在visuilize中,可以显示html,可以做自定义折叠。公共脚本可以放在globals中,在每个collectionTest引用即可

Globals导出json

json 复制代码
{
	"id": "146e52f0-fd32-4814-8e58-8a3c0f4d5eb7",
	"values": [
		{
			"key": "ENV",
			"value": "test",
			"enabled": true
		},
		{
			"key": "decrypt_data",
			"value": "true",
			"enabled": true
		},
		{
			"key": "pretty_data",
			"value": "fold",
			"enabled": true
		},
		{
			"key": "Decrypt",
			"value": "function Decrypt(param){\n\n    let key_str = pm.globals.get(\"ENV\") == \"test\" ? \"xxxxx\" : \"xxxxx\"\n  let iv_str = pm.globals.get(\"ENV\") == \"test\" ? \"xxxxx\" : \"xxxxx\"\n\n    const KEY = CryptoJS.enc.Utf8.parse(key_str);\n    const IV = CryptoJS.enc.Utf8.parse(iv_str);\n    let key = KEY;\n    let iv = IV;\n    const srcs = CryptoJS.enc.Base64.parse(param.replace(/\\s+/g,''));\n    const decryptedWordArray = CryptoJS.TripleDES.decrypt({\"ciphertext\":srcs}, key, {\n        iv: iv,\n        mode: CryptoJS.mode.CBC, // 或者使用 CBC 模式:CryptoJS.mode.CBC\n        padding: CryptoJS.pad.Pkcs7\n    });\n    const decryptedStr = decryptedWordArray.toString(CryptoJS.enc.Utf8)\n    return decryptedStr;\n}",
			"enabled": true
		},
		{
			"key": "Encrypt",
			"value": "function Encrypt(param){\n\n\n    let key_str = pm.globals.get(\"ENV\") == \"test\" ? \"xxxxx\" : \"xxxxx\"\n  let iv_str = pm.globals.get(\"ENV\") == \"test\" ? \"xxxxx\" : \"xxxxx\"\n\nconst KEY = CryptoJS.enc.Utf8.parse(key_str);\nconst IV = CryptoJS.enc.Utf8.parse(iv_str);\n    let key = KEY;\n    let iv = IV;\n\n    const decryptedWordArray = CryptoJS.TripleDES.encrypt(param, key, {\n        iv: iv,\n        mode: CryptoJS.mode.CBC, // 或者使用 CBC 模式:CryptoJS.mode.CBC\n        padding: CryptoJS.pad.Pkcs7\n    });\n\n    const decryptedStr = decryptedWordArray.ciphertext.toString(CryptoJS.enc.Base64)\n    return decryptedStr;\n}",
			"enabled": true
		},
		{
			"key": "prettyJsonVisualizer",
			"value": "function prettyJsonVisualizer(data) {\n    return `\n<!DOCTYPE html>\n<html>\n<head>\n    <meta charset=\"UTF-8\">\n    <style>\n        body {\n            font-family: monospace;\n            font-size: 13px;\n        }\n        details {\n            margin-left: 16px;\n        }\n        summary {\n            cursor: pointer;\n            font-weight: bold;\n            color: #1f2937;\n        }\n        .key {\n            color: #0f766e;\n        }\n        .string {\n            color: #2563eb;\n        }\n        .number {\n            color: #7c3aed;\n        }\n        .boolean {\n            color: #dc2626;\n        }\n        .null {\n            color: #6b7280;\n        }\n    </style>\n</head>\n<body>\n    <div id=\"json\"></div>\n\n<script>\nfunction render(value) {\n    if (value === null) {\n        return '<span class=\"null\">null</span>';\n    }\n\n    if (typeof value === 'string') {\n        return '<span class=\"string\">\"' + value + '\"</span>';\n    }\n\n    if (typeof value === 'number') {\n        return '<span class=\"number\">' + value + '</span>';\n    }\n\n    if (typeof value === 'boolean') {\n        return '<span class=\"boolean\">' + value + '</span>';\n    }\n\n    if (Array.isArray(value)) {\n        return '<details>' +\n            '<summary>Array[' + value.length + ']</summary>' +\n            value.map(v => '<div>' + render(v) + '</div>').join('') +\n        '</details>';\n    }\n\n    if (typeof value === 'object') {\n        const keys = Object.keys(value);\n        return '<details open>' +\n            '<summary>Object{' + keys.length + '}</summary>' +\n            keys.map(k =>\n                '<div><span class=\"key\">' + k + '</span>: ' +\n                render(value[k]) + '</div>'\n            ).join('') +\n        '</details>';\n    }\n\n    return value;\n}\n\ndocument.getElementById('json').innerHTML = render(${JSON.stringify(data)});\n</script>\n</body>\n</html>\n`;\n}\n\nprettyJsonVisualizer;",
			"enabled": true
		},
		{
			"key": "res_handle",
			"value": "function res_handle(res){\neval(pm.globals.get(\"Decrypt\"))\n\nif(res.status == 0 && pm.globals.get(\"decrypt_data\") == 'true'){\n    \nlet raw = Decrypt(res.data);\n\n// 如果 response 本身是 JSON 字符串\nlet json;\ntry {\n    json = typeof raw === 'string' ? JSON.parse(raw) : raw;\n} catch (e) {\n    json = { raw };\n}\nif(pm.globals.get(\"pretty_data\") == 'fold'){\n    eval(pm.globals.get(\"prettyJsonVisualizer\"))\nreturn prettyJsonVisualizer(json)\n}else if(pm.globals.get(\"pretty_data\") == 'json'){\nreturn `<pre>${JSON.stringify(json,null,2)}</pre>`\n}else{\nreturn `<pre>${JSON.stringify(json)}</pre>`\n}\n}\n}",
			"enabled": true
		}
	],
	"name": "My Workspace Globals",
	"_postman_variable_scope": "globals",
	"_postman_exported_at": "2025-12-31T08:03:38.975Z",
	"_postman_exported_using": "Postman/7.17.0"
}
相关推荐
Wpa.wk1 天前
接口自动化 - 解决大量响应数据字段的格式断言 -Json-schema
运维·经验分享·测试工具·自动化·json·接口测试
源代码•宸1 天前
goframe框架签到系统项目开发(实现总积分和积分明细接口、补签日期校验)
后端·golang·postman·web·dao·goframe·补签
Wpa.wk1 天前
接口自动化 - 接口组合业务练习(CRUD组合)-REST-assure(Java版)
java·运维·经验分享·测试工具·自动化·接口自动化
天才测试猿2 天前
Selenium测试框架快速搭建详解
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
Wpa.wk2 天前
接口测试-多层嵌套响应处理-JSONPath使用(Java版)
java·前端·经验分享·python·测试工具·jsonpath
yenggd2 天前
wireshark常规用法
测试工具·wireshark·php
我送炭你添花3 天前
Pelco KBD300A 模拟器:06+3.从教学级到企业级工程化转型(二次迭代)
python·测试工具·运维开发
会打莎士比亚的猴子3 天前
tcpdump移植
网络·测试工具·tcpdump
Yu_iChan3 天前
苍穹外卖Day2 分类管理功能
java·intellij-idea·postman