runner-runtime 1.0.85 → 1.0.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/events/api.js +6 -5
- package/index.js +34 -2
- package/libs/utils.js +2 -1
- package/package.json +3 -3
- package/tmp/request.js +738 -38
package/events/api.js
CHANGED
|
@@ -50,6 +50,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
50
50
|
const queryAddEqual = _.toInteger(
|
|
51
51
|
_.get(request, "request.query.query_add_equal") || -1
|
|
52
52
|
);
|
|
53
|
+
|
|
53
54
|
_.forEach(_.get(request, "request.query.parameter"), (item) => {
|
|
54
55
|
if (_.isObject(item) && item?.is_checked > 0) {
|
|
55
56
|
let { key, value, schema } = item;
|
|
@@ -57,7 +58,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
57
58
|
value = String(autoReplaceMockVar(value));
|
|
58
59
|
|
|
59
60
|
if (value == '' && _.isObject(schema)) {
|
|
60
|
-
const tmpValue = jsfGenerate(schema, [], option?.lang);
|
|
61
|
+
const tmpValue = jsfGenerate(schema, [], option?.lang, option?.custom_functions || {});
|
|
61
62
|
|
|
62
63
|
if (!_.isUndefined(tmpValue)) {
|
|
63
64
|
value = tmpValue;
|
|
@@ -100,7 +101,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
100
101
|
value = autoReplaceMockVar(value);
|
|
101
102
|
|
|
102
103
|
if (value == '' && _.isObject(schema)) {
|
|
103
|
-
const tmpValue = jsfGenerate(schema, [], option?.lang);
|
|
104
|
+
const tmpValue = jsfGenerate(schema, [], option?.lang, option?.custom_functions || {});
|
|
104
105
|
|
|
105
106
|
if (!_.isUndefined(tmpValue)) {
|
|
106
107
|
value = tmpValue;
|
|
@@ -287,7 +288,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
287
288
|
value = autoReplaceMockVar(value);
|
|
288
289
|
|
|
289
290
|
if (value == '' && _.isObject(schema)) {
|
|
290
|
-
const tmpValue = jsfGenerate(schema, [], option?.lang);
|
|
291
|
+
const tmpValue = jsfGenerate(schema, [], option?.lang, option?.custom_functions || {});
|
|
291
292
|
|
|
292
293
|
if (!_.isUndefined(tmpValue)) {
|
|
293
294
|
value = tmpValue;
|
|
@@ -377,7 +378,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
377
378
|
let value = autoReplaceMockVar(item.value);
|
|
378
379
|
|
|
379
380
|
if (value == '' && _.isObject(item?.schema)) {
|
|
380
|
-
const tmpValue = jsfGenerate(item?.schema, [], option?.lang);
|
|
381
|
+
const tmpValue = jsfGenerate(item?.schema, [], option?.lang, option?.custom_functions || {});
|
|
381
382
|
|
|
382
383
|
if (!_.isUndefined(tmpValue)) {
|
|
383
384
|
value = tmpValue;
|
|
@@ -473,7 +474,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
473
474
|
value = autoReplaceMockVar(value);
|
|
474
475
|
|
|
475
476
|
if (value == '' && _.isObject(schema)) {
|
|
476
|
-
const tmpValue = jsfGenerate(schema, [], option?.lang);
|
|
477
|
+
const tmpValue = jsfGenerate(schema, [], option?.lang, option?.custom_functions || {});
|
|
477
478
|
|
|
478
479
|
if (!_.isUndefined(tmpValue)) {
|
|
479
480
|
value = tmpValue;
|
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const { repeatArrayToLength, formatAutotestReport, formatAutotestReportList } = require('./libs/utils');
|
|
1
|
+
const { repeatArrayToLength, formatAutotestReport, formatAutotestReportList, getInsideVariables } = require('./libs/utils');
|
|
2
2
|
const _ = require('lodash');
|
|
3
|
+
const { mockExp } = require('exp-mock');
|
|
3
4
|
const aTools = require("apipost-tools");
|
|
4
5
|
const { executeEvent, iterationEvent } = require('./events');
|
|
5
6
|
const ABORT_RECURSION_ERROR = ['systemError']; //需要跳出递归的错误
|
|
@@ -13,7 +14,7 @@ const run = async (events, option, callback) => {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const tempEvents = _.cloneDeep(_.flatten(new Array(scene == 'auto_test' ? _.max([_.toInteger(iterationCount), 1]) : 1).fill(events))) || [];
|
|
16
|
-
const
|
|
17
|
+
const iterationDataArrTemp = _.flatMap(repeatArrayToLength(_.cloneDeep(iterationData), _.max([_.toInteger(iterationCount), 1])), (element) => _.times(_.size(events), () => element));
|
|
17
18
|
const eventOptions = _.pick(option, ["scene", "lang", "project", "env", "globals", "cookies", "system_configs", "custom_functions", "collection", "database_configs", "enable_sandbox", "sleep", "name", "testing_id"]);
|
|
18
19
|
|
|
19
20
|
// 初始化变量
|
|
@@ -28,6 +29,37 @@ const run = async (events, option, callback) => {
|
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
|
|
32
|
+
const iterationDataArr = [];
|
|
33
|
+
if (scene != 'http_request') {
|
|
34
|
+
// 解析测试数据
|
|
35
|
+
const regex = /{{([^}]+)}}/g;
|
|
36
|
+
_.forEach(iterationDataArrTemp, (obj, index) => {
|
|
37
|
+
const cloneObj = _.cloneDeep(obj);
|
|
38
|
+
if (_.isObject(obj) && !_.isEmpty(obj)) {
|
|
39
|
+
_.forEach(obj, (val, key) => {
|
|
40
|
+
if (_.trim(val) != '' && _.isString(val)) {
|
|
41
|
+
const matches = val.match(regex);
|
|
42
|
+
|
|
43
|
+
if (!_.isEmpty(matches)) {
|
|
44
|
+
_.forEach(matches, (match) => {
|
|
45
|
+
try {
|
|
46
|
+
const tmpVal = mockExp(match, getInsideVariables(), option?.lang, option?.custom_functions || {});
|
|
47
|
+
|
|
48
|
+
if (tmpVal != match && !_.isUndefined(tmpVal)) {
|
|
49
|
+
_.set(cloneObj, [key], _.replace(val, match, tmpVal));
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
} catch (e) { }
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
iterationDataArr.push(cloneObj)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
31
63
|
const tempVars = { environment: _.get(option, 'env.environment', {}), globals: _.get(option, 'globals', {}), iterationDataArr };
|
|
32
64
|
|
|
33
65
|
['environment', 'globals', 'iterationDataArr'].forEach((type) => {
|
package/libs/utils.js
CHANGED
|
@@ -484,13 +484,14 @@ const encodeURIComponentUnique = (str) => {
|
|
|
484
484
|
}
|
|
485
485
|
}
|
|
486
486
|
|
|
487
|
-
const jsfGenerate = (schema, mockRules = [], lang) => {
|
|
487
|
+
const jsfGenerate = (schema, mockRules = [], lang, customFunctions = {}) => {
|
|
488
488
|
jsf.option({
|
|
489
489
|
alwaysFakeOptionals: true,
|
|
490
490
|
useExamplesValue: true,
|
|
491
491
|
fillProperties: false,
|
|
492
492
|
useDefaultValue: true,
|
|
493
493
|
mockRules,
|
|
494
|
+
customFunctions,
|
|
494
495
|
lang: 'zh-cn',
|
|
495
496
|
});
|
|
496
497
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "runner-runtime",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.87",
|
|
4
4
|
"description": "runner-runtime.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"mime": "^3.0.0",
|
|
38
38
|
"minimatch": "^9.0.4",
|
|
39
39
|
"mockjs5-pro": "^1.0.6",
|
|
40
|
-
"json-schema-faker-pro": "^0.5.
|
|
41
|
-
"exp-mock": "^2.0.
|
|
40
|
+
"json-schema-faker-pro": "^0.5.33",
|
|
41
|
+
"exp-mock": "^2.0.19",
|
|
42
42
|
"msgpack5": "^6.0.2",
|
|
43
43
|
"net": "^1.0.2",
|
|
44
44
|
"postman-collection": "^5.0.2",
|
package/tmp/request.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
module.exports ={
|
|
1
|
+
module.exports = {
|
|
2
2
|
"option": {
|
|
3
|
-
"scene": "
|
|
3
|
+
"scene": "auto_test",
|
|
4
4
|
"globals": {},
|
|
5
5
|
"project": {
|
|
6
6
|
"request": {
|
|
@@ -61,30 +61,63 @@ module.exports ={
|
|
|
61
61
|
"server_id": "1",
|
|
62
62
|
"name": "默认服务",
|
|
63
63
|
"sort": 1000,
|
|
64
|
-
"uri": "
|
|
64
|
+
"uri": ""
|
|
65
65
|
},
|
|
66
66
|
"default": {
|
|
67
67
|
"server_id": "1",
|
|
68
68
|
"name": "默认服务",
|
|
69
69
|
"sort": 1000,
|
|
70
|
-
"uri": "http://127.0.0.1:3000"
|
|
71
|
-
},
|
|
72
|
-
"47aad9ec6895000": {
|
|
73
|
-
"server_id": "47aad9ec6895000",
|
|
74
|
-
"name": "无前置URL",
|
|
75
|
-
"sort": 2000,
|
|
76
70
|
"uri": ""
|
|
77
71
|
}
|
|
78
72
|
},
|
|
79
73
|
"environment": {
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"password": "HC3eIdX298vgUkm"
|
|
74
|
+
"oooo": "gzip, deflate, br",
|
|
75
|
+
"var1": "undefined"
|
|
83
76
|
}
|
|
84
77
|
},
|
|
85
78
|
"cookies": {
|
|
86
|
-
"switch":
|
|
87
|
-
"data": [
|
|
79
|
+
"switch": 1,
|
|
80
|
+
"data": [
|
|
81
|
+
{
|
|
82
|
+
"key": "aliyungf_tc",
|
|
83
|
+
"value": "85bd313c10390304cae7a78e4abd631e8390c0eea16ce61202c2bea63ae72a2e",
|
|
84
|
+
"path": "/",
|
|
85
|
+
"httpOnly": true,
|
|
86
|
+
"creation": "2025-05-27T12:48:16.342Z",
|
|
87
|
+
"name": "aliyungf_tc",
|
|
88
|
+
"cookie_id": "3899fe6bfff00b",
|
|
89
|
+
"domain": "v.juhe.cn",
|
|
90
|
+
"project_id": "478597272401000"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"key": "liveCookie",
|
|
94
|
+
"value": "gin",
|
|
95
|
+
"maxAge": 120,
|
|
96
|
+
"domain": "go.apipost.cn",
|
|
97
|
+
"path": "/",
|
|
98
|
+
"secure": true,
|
|
99
|
+
"httpOnly": true,
|
|
100
|
+
"creation": "2025-06-05T11:29:01.800Z",
|
|
101
|
+
"name": "liveCookie",
|
|
102
|
+
"cookie_id": "2f43d903d001b",
|
|
103
|
+
"expires": "Thu, 05 Jun 2025 11:31:02 GMT",
|
|
104
|
+
"project_id": "478597272401000"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"key": "loseCookie",
|
|
108
|
+
"value": "gin",
|
|
109
|
+
"maxAge": 0,
|
|
110
|
+
"domain": "go.apipost.cn",
|
|
111
|
+
"path": "/",
|
|
112
|
+
"secure": true,
|
|
113
|
+
"httpOnly": true,
|
|
114
|
+
"creation": "2025-06-05T11:29:01.800Z",
|
|
115
|
+
"name": "loseCookie",
|
|
116
|
+
"cookie_id": "2f43d903d001c",
|
|
117
|
+
"expires": "Thu, 05 Jun 2025 11:29:02 GMT",
|
|
118
|
+
"project_id": "478597272401000"
|
|
119
|
+
}
|
|
120
|
+
]
|
|
88
121
|
},
|
|
89
122
|
"system_configs": {
|
|
90
123
|
"send_timeout": 0,
|
|
@@ -96,79 +129,746 @@ module.exports ={
|
|
|
96
129
|
"type": 2,
|
|
97
130
|
"envfirst": 1,
|
|
98
131
|
"bypass": [],
|
|
99
|
-
"protocols": [
|
|
132
|
+
"protocols": [
|
|
133
|
+
"http",
|
|
134
|
+
"https"
|
|
135
|
+
],
|
|
100
136
|
"auth": {
|
|
101
|
-
"authenticate":
|
|
102
|
-
"host": "",
|
|
103
|
-
"username": "",
|
|
104
|
-
"password": ""
|
|
137
|
+
"authenticate": 1,
|
|
138
|
+
"host": "127.0.0.1:7890",
|
|
139
|
+
"username": "Username",
|
|
140
|
+
"password": "Password"
|
|
105
141
|
}
|
|
106
142
|
},
|
|
107
143
|
"ca_cert": {
|
|
108
144
|
"open": -1,
|
|
109
|
-
"path": ""
|
|
145
|
+
"path": "",
|
|
146
|
+
"base64": ""
|
|
110
147
|
},
|
|
111
148
|
"client_cert": {}
|
|
112
149
|
},
|
|
113
150
|
"custom_functions": {
|
|
114
|
-
"
|
|
151
|
+
"fn_hello": "\n// This function is generated by Apipost AI.\ntry {\n return new Date().getTime();\n} catch (error) {\n return text;\n}"
|
|
115
152
|
},
|
|
116
153
|
"collection": [
|
|
117
154
|
{
|
|
118
|
-
"target_id": "
|
|
155
|
+
"target_id": "38629c6b72a0d7",
|
|
119
156
|
"target_type": "api",
|
|
120
157
|
"parent_id": "0",
|
|
121
|
-
"name": "
|
|
158
|
+
"name": "注册接口",
|
|
122
159
|
"request": {
|
|
123
160
|
"auth": {
|
|
124
161
|
"type": "inherit"
|
|
125
162
|
},
|
|
126
163
|
"body": {
|
|
127
|
-
"mode": "
|
|
164
|
+
"mode": "json",
|
|
128
165
|
"parameter": [],
|
|
129
|
-
"raw": "",
|
|
166
|
+
"raw": "{\n \"username\": \"\",\n \"password\": \"\",\n \"lastLoginAt\":\"\"\n}",
|
|
130
167
|
"raw_parameter": [],
|
|
131
168
|
"raw_schema": {
|
|
132
169
|
"type": "object"
|
|
133
170
|
},
|
|
134
171
|
"binary": null
|
|
135
172
|
},
|
|
136
|
-
"pre_tasks": [
|
|
137
|
-
|
|
173
|
+
"pre_tasks": [
|
|
174
|
+
{
|
|
175
|
+
"type": "customScript",
|
|
176
|
+
"enabled": 1,
|
|
177
|
+
"data": "",
|
|
178
|
+
"name": "自定义脚本",
|
|
179
|
+
"id": "3a1e79dbbff009"
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
"post_tasks": [
|
|
183
|
+
{
|
|
184
|
+
"type": "customScript",
|
|
185
|
+
"enabled": 1,
|
|
186
|
+
"data": "",
|
|
187
|
+
"name": "自定义脚本",
|
|
188
|
+
"id": "3a30e2247ff013"
|
|
189
|
+
}
|
|
190
|
+
],
|
|
138
191
|
"header": {
|
|
139
192
|
"parameter": []
|
|
140
193
|
},
|
|
141
194
|
"query": {
|
|
142
|
-
"
|
|
143
|
-
"
|
|
195
|
+
"query_add_equal": 1,
|
|
196
|
+
"parameter": []
|
|
144
197
|
},
|
|
145
198
|
"cookie": {
|
|
146
|
-
"
|
|
147
|
-
"
|
|
199
|
+
"cookie_encode": 1,
|
|
200
|
+
"parameter": []
|
|
148
201
|
},
|
|
149
202
|
"restful": {
|
|
150
203
|
"parameter": []
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
"parents": [],
|
|
207
|
+
"method": "POST",
|
|
208
|
+
"protocol": "http/1.1",
|
|
209
|
+
"url": "/api/register",
|
|
210
|
+
"pre_url": ""
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"target_id": "3866f5e8f2a152",
|
|
214
|
+
"target_type": "api",
|
|
215
|
+
"parent_id": "0",
|
|
216
|
+
"name": "手机实名校验",
|
|
217
|
+
"request": {
|
|
218
|
+
"auth": {
|
|
219
|
+
"type": "inherit"
|
|
220
|
+
},
|
|
221
|
+
"body": {
|
|
222
|
+
"mode": "json",
|
|
223
|
+
"parameter": [
|
|
224
|
+
{
|
|
225
|
+
"param_id": "3867147772a16f",
|
|
226
|
+
"description": "在个人中心->我的数据,接口名称上方查看",
|
|
227
|
+
"field_type": "string",
|
|
228
|
+
"is_checked": 1,
|
|
229
|
+
"key": "key",
|
|
230
|
+
"not_null": 1,
|
|
231
|
+
"value": "",
|
|
232
|
+
"content_type": "",
|
|
233
|
+
"file_name": "",
|
|
234
|
+
"file_base64": "",
|
|
235
|
+
"schema": {
|
|
236
|
+
"type": "string"
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
"param_id": "386715acf2a171",
|
|
241
|
+
"description": "姓名",
|
|
242
|
+
"field_type": "string",
|
|
243
|
+
"is_checked": 1,
|
|
244
|
+
"key": "realname",
|
|
245
|
+
"not_null": 1,
|
|
246
|
+
"value": "",
|
|
247
|
+
"content_type": "",
|
|
248
|
+
"file_name": "",
|
|
249
|
+
"file_base64": "",
|
|
250
|
+
"schema": {
|
|
251
|
+
"type": "string"
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"param_id": "386716dbb2a174",
|
|
256
|
+
"description": "身份证号码",
|
|
257
|
+
"field_type": "string",
|
|
258
|
+
"is_checked": 1,
|
|
259
|
+
"key": "idcard",
|
|
260
|
+
"not_null": 1,
|
|
261
|
+
"value": "",
|
|
262
|
+
"content_type": "",
|
|
263
|
+
"file_name": "",
|
|
264
|
+
"file_base64": "",
|
|
265
|
+
"schema": {
|
|
266
|
+
"type": "string"
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"param_id": "38671813b2a176",
|
|
271
|
+
"description": "手机号码",
|
|
272
|
+
"field_type": "string",
|
|
273
|
+
"is_checked": 1,
|
|
274
|
+
"key": "mobile",
|
|
275
|
+
"not_null": 1,
|
|
276
|
+
"value": "",
|
|
277
|
+
"content_type": "",
|
|
278
|
+
"file_name": "",
|
|
279
|
+
"file_base64": "",
|
|
280
|
+
"schema": {
|
|
281
|
+
"type": "string",
|
|
282
|
+
"default": ""
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
"param_id": "386719b1f2a178",
|
|
287
|
+
"description": "是否显示手机运营商,1:显示,0:不显示(默认)",
|
|
288
|
+
"field_type": "integer",
|
|
289
|
+
"is_checked": 1,
|
|
290
|
+
"key": "type",
|
|
291
|
+
"not_null": -1,
|
|
292
|
+
"value": "",
|
|
293
|
+
"content_type": "",
|
|
294
|
+
"file_name": "",
|
|
295
|
+
"file_base64": "",
|
|
296
|
+
"schema": {
|
|
297
|
+
"type": "integer"
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
"param_id": "38671b23b2a17a",
|
|
302
|
+
"description": "是否显示聚合订单号,1:显示,0:不显示(默认)",
|
|
303
|
+
"field_type": "integer",
|
|
304
|
+
"is_checked": 1,
|
|
305
|
+
"key": "showid",
|
|
306
|
+
"not_null": -1,
|
|
307
|
+
"value": "",
|
|
308
|
+
"content_type": "",
|
|
309
|
+
"file_name": "",
|
|
310
|
+
"file_base64": "",
|
|
311
|
+
"schema": {
|
|
312
|
+
"type": "integer"
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
"param_id": "38671cc572a17c",
|
|
317
|
+
"description": "是否显示手机号归属地,1:显示,0:不显示(默认)",
|
|
318
|
+
"field_type": "integer",
|
|
319
|
+
"is_checked": 1,
|
|
320
|
+
"key": "province",
|
|
321
|
+
"not_null": -1,
|
|
322
|
+
"value": "",
|
|
323
|
+
"content_type": "",
|
|
324
|
+
"file_name": "",
|
|
325
|
+
"file_base64": "",
|
|
326
|
+
"schema": {
|
|
327
|
+
"type": "integer"
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
"param_id": "38671e0572a17e",
|
|
332
|
+
"description": "是否显示匹配详情码,1:显示,0:不显示(默认)",
|
|
333
|
+
"field_type": "integer",
|
|
334
|
+
"is_checked": 1,
|
|
335
|
+
"key": "detail",
|
|
336
|
+
"not_null": -1,
|
|
337
|
+
"value": "",
|
|
338
|
+
"content_type": "",
|
|
339
|
+
"file_name": "",
|
|
340
|
+
"file_base64": "",
|
|
341
|
+
"schema": {
|
|
342
|
+
"type": "integer"
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
],
|
|
346
|
+
"raw": "{\n \"lastLoginAt\":1\n}",
|
|
347
|
+
"raw_parameter": [],
|
|
348
|
+
"raw_schema": {
|
|
349
|
+
"type": "object",
|
|
350
|
+
"required": [
|
|
351
|
+
"id"
|
|
352
|
+
],
|
|
353
|
+
"properties": {
|
|
354
|
+
"id": {
|
|
355
|
+
"type": "integer",
|
|
356
|
+
"example": 1
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
"x-schema-orders": [
|
|
360
|
+
"id"
|
|
361
|
+
]
|
|
362
|
+
},
|
|
363
|
+
"binary": null
|
|
151
364
|
},
|
|
152
|
-
"
|
|
365
|
+
"pre_tasks": [
|
|
366
|
+
{
|
|
367
|
+
"type": "customScript",
|
|
368
|
+
"enabled": 1,
|
|
369
|
+
"data": "// This code is generated by [Apipost] AI.\nfunction encryptRequestParamsWithAES() {\n try {\n // 获取请求参数\n let requestParams = request.request_bodys;\n if (_.isString(requestParams)) {\n try {\n requestParams = JSON5.parse(requestParams);\n } catch (e) {\n console.warn('请求参数解析为JSON失败');\n return;\n }\n }\n // 将请求参数转换为字符串\n const paramsStr = JSON5.stringify(requestParams);\n // 使用CryptoJS进行AES加密,这里假设密钥为固定值,实际应用中应妥善处理密钥\n const encrypted = CryptoJS.AES.encrypt(paramsStr, 'Secret Passphrase');\n // 设置加密后的参数为请求体\n pm.setRequestBody(encrypted.toString());\n } catch (error) {\n console.error('加密请求参数时出错:', error);\n }\n}",
|
|
370
|
+
"name": "自定义脚本",
|
|
371
|
+
"id": "3a0094827ff006"
|
|
372
|
+
}
|
|
373
|
+
],
|
|
374
|
+
"post_tasks": [
|
|
375
|
+
{
|
|
376
|
+
"type": "customScript",
|
|
377
|
+
"enabled": 1,
|
|
378
|
+
"data": "// This code is generated by [Apipost] AI.\nfunction generateVisualizerScript() {\n try {\n const objData = pm.response.json();\n const template = `\n <style>\n .table { background-color: #FFFFFF; border-radius: 8px; }\n .table th { background-color: #F0F0F0; padding: 10px; border-bottom: 1px solid #DDDDDD; }\n .table td { padding: 10px; border-bottom: 1px solid #DDDDDD; }\n </style>\n <table class=\"table\">\n <thead>\n <tr>\n <th>字段</th>\n <th>值</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>resultcode</td>\n <td>{{resultcode}}</td>\n </tr>\n <tr>\n <td>reason</td>\n <td>{{reason}}</td>\n </tr>\n <tr>\n <td>result</td>\n <td>{{result}}</td>\n </tr>\n <tr>\n <td>error_code</td>\n <td>{{error_code}}</td>\n </tr>\n </tbody>\n </table>\n `;\n pm.visualizer.set(template, objData);\n } catch (e) {\n console.error('生成可视化脚本时出错:', e);\n }\n}\ngenerateVisualizerScript();",
|
|
379
|
+
"name": "自定义脚本",
|
|
380
|
+
"id": "39e9dc0dfff010"
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
"type": "customScript",
|
|
384
|
+
"enabled": 1,
|
|
385
|
+
"data": "// 断言响应状态码是否为200\npm.test(\"响应状态码为200\", function () {\n pm.response.to.have.status(200);\n});\n// 断言响应时间是否小于300毫秒(行业推荐平均响应时间)\npm.test(\"响应时间小于300毫秒\", function () {\n pm.expect(pm.response.responseTime).to.be.below(300);\n});\n// 断言响应体中resultcode字段是否为101\npm.test(\"响应体中resultcode字段为101\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.resultcode).to.eql(\"101\");\n});\n// 断言响应体中reason字段是否为错误的请求KEY\npm.test(\"响应体中reason字段为错误的请求KEY\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.reason).to.eql(\"错误的请求KEY\");\n});\n// 断言响应体中error_code字段是否为10001\npm.test(\"响应体中error_code字段为10001\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.error_code).to.eql(10001);\n});\n// 断言响应体是否为有效的JSON格式\npm.test(\"响应体必须是json\", function () {\n pm.response.to.be.json;\n});",
|
|
386
|
+
"name": "AI断言",
|
|
387
|
+
"id": "3a01bc577ff018"
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
"type": "customScript",
|
|
391
|
+
"enabled": 1,
|
|
392
|
+
"data": "// 断言响应状态码是否为200\npm.test(\"响应状态码为200\", function () {\n pm.response.to.have.status(200);\n});\n// 断言响应时间是否小于300毫秒(行业推荐平均响应时间)\npm.test(\"响应时间小于300毫秒\", function () {\n pm.expect(pm.response.responseTime).to.be.below(300);\n});\n// 断言响应体中的resultcode是否为101\npm.test(\"响应体中的resultcode为101\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.resultcode).to.eql(\"101\");\n});\n// 断言响应体中的reason是否为错误的请求KEY\npm.test(\"响应体中的reason为错误的请求KEY\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.reason).to.eql(\"错误的请求KEY\");\n});\n// 断言响应体中的error_code是否为10001\npm.test(\"响应体中的error_code为10001\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.error_code).to.eql(10001);\n});",
|
|
393
|
+
"name": "AI Assertion",
|
|
394
|
+
"id": "3a025d25fff008"
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
"type": "customScript",
|
|
398
|
+
"enabled": 1,
|
|
399
|
+
"data": "// 断言响应状态码是否为200,通常200表示请求成功\npm.test(\"响应状态码为200\", function () {\n pm.response.to.have.status(200);\n});\n// 断言响应时间是否小于300毫秒,300毫秒是行业推荐的平均响应时间\npm.test(\"响应时间小于300毫秒\", function () {\n pm.expect(pm.response.responseTime).to.be.below(300);\n});\n// 断言响应体中的resultcode字段是否为101\npm.test(\"响应体中的resultcode为101\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.resultcode).to.eql(\"101\");\n});\n// 断言响应体中的reason字段是否为'错误的请求KEY'\npm.test(\"响应体中的reason为错误的请求KEY\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.reason).to.eql(\"错误的请求KEY\");\n});\n// 断言响应体中的error_code字段是否为10001\npm.test(\"响应体中的error_code为10001\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.error_code).to.eql(10001);\n});",
|
|
400
|
+
"name": "AI断言",
|
|
401
|
+
"id": "3a1eabf07ff00c"
|
|
402
|
+
}
|
|
403
|
+
],
|
|
404
|
+
"header": {
|
|
405
|
+
"parameter": [
|
|
406
|
+
{
|
|
407
|
+
"param_id": "38670379f2a15a",
|
|
408
|
+
"description": "请求内容类型",
|
|
409
|
+
"field_type": "string",
|
|
410
|
+
"is_checked": 1,
|
|
411
|
+
"key": "Content-Type",
|
|
412
|
+
"not_null": 1,
|
|
413
|
+
"value": "application/x-www-form-urlencoded",
|
|
414
|
+
"schema": {
|
|
415
|
+
"type": "string"
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
]
|
|
419
|
+
},
|
|
420
|
+
"query": {
|
|
421
|
+
"query_add_equal": 1,
|
|
422
|
+
"parameter": [
|
|
423
|
+
{
|
|
424
|
+
"param_id": "3867057a72a15c",
|
|
425
|
+
"description": "在个人中心->我的数据,接口名称上方查看",
|
|
426
|
+
"field_type": "string",
|
|
427
|
+
"is_checked": 1,
|
|
428
|
+
"key": "key",
|
|
429
|
+
"not_null": 1,
|
|
430
|
+
"value": "",
|
|
431
|
+
"schema": {
|
|
432
|
+
"type": "string"
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
"param_id": "386706cf72a15e",
|
|
437
|
+
"description": "姓名",
|
|
438
|
+
"field_type": "string",
|
|
439
|
+
"is_checked": 1,
|
|
440
|
+
"key": "realname",
|
|
441
|
+
"not_null": 1,
|
|
442
|
+
"value": "",
|
|
443
|
+
"schema": {
|
|
444
|
+
"type": "string"
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
"param_id": "38670830b2a160",
|
|
449
|
+
"description": "身份证号码",
|
|
450
|
+
"field_type": "string",
|
|
451
|
+
"is_checked": 1,
|
|
452
|
+
"key": "idcard",
|
|
453
|
+
"not_null": 1,
|
|
454
|
+
"value": "",
|
|
455
|
+
"schema": {
|
|
456
|
+
"type": "string"
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
"param_id": "38670975f2a162",
|
|
461
|
+
"description": "手机号码",
|
|
462
|
+
"field_type": "string",
|
|
463
|
+
"is_checked": 1,
|
|
464
|
+
"key": "mobile",
|
|
465
|
+
"not_null": 1,
|
|
466
|
+
"value": "",
|
|
467
|
+
"schema": {
|
|
468
|
+
"type": "string"
|
|
469
|
+
}
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
"param_id": "38670b59f2a164",
|
|
473
|
+
"description": "是否显示手机运营商,1:显示,0:不显示(默认)",
|
|
474
|
+
"field_type": "integer",
|
|
475
|
+
"is_checked": 1,
|
|
476
|
+
"key": "type",
|
|
477
|
+
"not_null": -1,
|
|
478
|
+
"value": "",
|
|
479
|
+
"schema": {
|
|
480
|
+
"type": "integer"
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
"param_id": "38670cfa32a166",
|
|
485
|
+
"description": "是否显示聚合订单号,1:显示,0:不显示(默认)",
|
|
486
|
+
"field_type": "integer",
|
|
487
|
+
"is_checked": 1,
|
|
488
|
+
"key": "showid",
|
|
489
|
+
"not_null": -1,
|
|
490
|
+
"value": "",
|
|
491
|
+
"schema": {
|
|
492
|
+
"type": "integer"
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
"param_id": "38670ecd72a168",
|
|
497
|
+
"description": "是否显示手机号归属地,1:显示,0:不显示(默认)",
|
|
498
|
+
"field_type": "integer",
|
|
499
|
+
"is_checked": 1,
|
|
500
|
+
"key": "province",
|
|
501
|
+
"not_null": -1,
|
|
502
|
+
"value": "",
|
|
503
|
+
"schema": {
|
|
504
|
+
"type": "integer"
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
"param_id": "38671070b2a16a",
|
|
509
|
+
"description": "是否显示匹配详情码,1:显示,0:不显示(默认)",
|
|
510
|
+
"field_type": "integer",
|
|
511
|
+
"is_checked": 1,
|
|
512
|
+
"key": "detail",
|
|
513
|
+
"not_null": -1,
|
|
514
|
+
"value": "",
|
|
515
|
+
"schema": {
|
|
516
|
+
"type": "integer"
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
]
|
|
520
|
+
},
|
|
521
|
+
"cookie": {
|
|
522
|
+
"cookie_encode": 1,
|
|
523
|
+
"parameter": []
|
|
524
|
+
},
|
|
525
|
+
"restful": {
|
|
526
|
+
"parameter": []
|
|
527
|
+
}
|
|
153
528
|
},
|
|
154
529
|
"parents": [],
|
|
155
|
-
"server_id": "47aad9ec6895000",
|
|
156
530
|
"method": "GET",
|
|
157
531
|
"protocol": "http/1.1",
|
|
158
|
-
"url": "
|
|
532
|
+
"url": "https://v.juhe.cn/telecom/query?key=&realname=&idcard=&mobile=&type=&showid=&province=&detail=",
|
|
159
533
|
"pre_url": ""
|
|
160
534
|
}
|
|
161
535
|
],
|
|
162
|
-
"database_configs": {}
|
|
536
|
+
"database_configs": {},
|
|
537
|
+
"name": "未命名测试用例",
|
|
538
|
+
"ignore_error": -1,
|
|
539
|
+
"enable_sandbox": -1,
|
|
540
|
+
"iterationCount": 2,
|
|
541
|
+
"sleep": 0,
|
|
542
|
+
"testing_id": "2f372b7bd0007",
|
|
543
|
+
"iterates_data_id": "41d7d5dfd0007",
|
|
544
|
+
"iterationData": [
|
|
545
|
+
{
|
|
546
|
+
"v1": "",
|
|
547
|
+
"a": "{{$function.fn_hello()}}",
|
|
548
|
+
"b": "{{$mockjs.idcard()}}",
|
|
549
|
+
"c": "lucy"
|
|
550
|
+
}
|
|
551
|
+
]
|
|
163
552
|
},
|
|
164
553
|
"test_events": [
|
|
165
554
|
{
|
|
166
555
|
"type": "api",
|
|
556
|
+
"auto_sync": false,
|
|
557
|
+
"test_id": "2f372b7bd0007",
|
|
558
|
+
"event_id": "41dd2b8bd0020",
|
|
559
|
+
"enabled": 1,
|
|
560
|
+
"data": {
|
|
561
|
+
"target_id": "38629c6b72a0d7",
|
|
562
|
+
"project_id": "478597272401000",
|
|
563
|
+
"parent_id": "0",
|
|
564
|
+
"target_type": "api",
|
|
565
|
+
"apiData": {
|
|
566
|
+
"name": "注册接口",
|
|
567
|
+
"method": "POST",
|
|
568
|
+
"protocol": "http/1.1",
|
|
569
|
+
"url": "https://go.apipost.cn/?a={{a}}",
|
|
570
|
+
"request": {
|
|
571
|
+
"auth": {
|
|
572
|
+
"type": "inherit"
|
|
573
|
+
},
|
|
574
|
+
"body": {
|
|
575
|
+
"mode": "json",
|
|
576
|
+
"parameter": [],
|
|
577
|
+
"raw": "{\n \"username\": \"\",\n \"password\": \"\",\n \"lastLoginAt\":\"\"\n}",
|
|
578
|
+
"raw_parameter": [],
|
|
579
|
+
"raw_schema": {
|
|
580
|
+
"type": "object"
|
|
581
|
+
},
|
|
582
|
+
"binary": null
|
|
583
|
+
},
|
|
584
|
+
"pre_tasks": [
|
|
585
|
+
{
|
|
586
|
+
"type": "customScript",
|
|
587
|
+
"enabled": 1,
|
|
588
|
+
"data": "",
|
|
589
|
+
"name": "自定义脚本",
|
|
590
|
+
"id": "3a1e79dbbff009"
|
|
591
|
+
}
|
|
592
|
+
],
|
|
593
|
+
"post_tasks": [
|
|
594
|
+
{
|
|
595
|
+
"type": "customScript",
|
|
596
|
+
"enabled": 1,
|
|
597
|
+
"data": "",
|
|
598
|
+
"name": "自定义脚本",
|
|
599
|
+
"id": "3a30e2247ff013"
|
|
600
|
+
}
|
|
601
|
+
],
|
|
602
|
+
"header": {
|
|
603
|
+
"parameter": []
|
|
604
|
+
},
|
|
605
|
+
"query": {
|
|
606
|
+
"query_add_equal": 1,
|
|
607
|
+
"parameter": [
|
|
608
|
+
{
|
|
609
|
+
"param_id": "41de01afd004b",
|
|
610
|
+
"field_type": "String",
|
|
611
|
+
"is_checked": 1,
|
|
612
|
+
"key": "a",
|
|
613
|
+
"not_null": 1,
|
|
614
|
+
"value": "{{a}}",
|
|
615
|
+
"description": ""
|
|
616
|
+
}
|
|
617
|
+
]
|
|
618
|
+
},
|
|
619
|
+
"cookie": {
|
|
620
|
+
"cookie_encode": 1,
|
|
621
|
+
"parameter": []
|
|
622
|
+
},
|
|
623
|
+
"restful": {
|
|
624
|
+
"parameter": []
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
"type": "api",
|
|
632
|
+
"auto_sync": false,
|
|
633
|
+
"test_id": "2f372b7bd0007",
|
|
634
|
+
"event_id": "41e136d7d006b",
|
|
635
|
+
"enabled": 1,
|
|
167
636
|
"data": {
|
|
168
|
-
"target_id": "
|
|
169
|
-
"project_id": "
|
|
637
|
+
"target_id": "3866f5e8f2a152",
|
|
638
|
+
"project_id": "478597272401000",
|
|
170
639
|
"parent_id": "0",
|
|
171
|
-
"target_type": "api"
|
|
640
|
+
"target_type": "api",
|
|
641
|
+
"apiData": {
|
|
642
|
+
"name": "手机实名校验",
|
|
643
|
+
"method": "GET",
|
|
644
|
+
"protocol": "http/1.1",
|
|
645
|
+
"url": "https://v.juhe.cn/telecom/query?a={{a}}",
|
|
646
|
+
"request": {
|
|
647
|
+
"auth": {
|
|
648
|
+
"type": "inherit"
|
|
649
|
+
},
|
|
650
|
+
"body": {
|
|
651
|
+
"mode": "json",
|
|
652
|
+
"parameter": [
|
|
653
|
+
{
|
|
654
|
+
"param_id": "3867147772a16f",
|
|
655
|
+
"description": "在个人中心->我的数据,接口名称上方查看",
|
|
656
|
+
"field_type": "string",
|
|
657
|
+
"is_checked": 1,
|
|
658
|
+
"key": "key",
|
|
659
|
+
"not_null": 1,
|
|
660
|
+
"value": "",
|
|
661
|
+
"content_type": "",
|
|
662
|
+
"file_name": "",
|
|
663
|
+
"file_base64": "",
|
|
664
|
+
"schema": {
|
|
665
|
+
"type": "string"
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
"param_id": "386715acf2a171",
|
|
670
|
+
"description": "姓名",
|
|
671
|
+
"field_type": "string",
|
|
672
|
+
"is_checked": 1,
|
|
673
|
+
"key": "realname",
|
|
674
|
+
"not_null": 1,
|
|
675
|
+
"value": "",
|
|
676
|
+
"content_type": "",
|
|
677
|
+
"file_name": "",
|
|
678
|
+
"file_base64": "",
|
|
679
|
+
"schema": {
|
|
680
|
+
"type": "string"
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
"param_id": "386716dbb2a174",
|
|
685
|
+
"description": "身份证号码",
|
|
686
|
+
"field_type": "string",
|
|
687
|
+
"is_checked": 1,
|
|
688
|
+
"key": "idcard",
|
|
689
|
+
"not_null": 1,
|
|
690
|
+
"value": "",
|
|
691
|
+
"content_type": "",
|
|
692
|
+
"file_name": "",
|
|
693
|
+
"file_base64": "",
|
|
694
|
+
"schema": {
|
|
695
|
+
"type": "string"
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
"param_id": "38671813b2a176",
|
|
700
|
+
"description": "手机号码",
|
|
701
|
+
"field_type": "string",
|
|
702
|
+
"is_checked": 1,
|
|
703
|
+
"key": "mobile",
|
|
704
|
+
"not_null": 1,
|
|
705
|
+
"value": "",
|
|
706
|
+
"content_type": "",
|
|
707
|
+
"file_name": "",
|
|
708
|
+
"file_base64": "",
|
|
709
|
+
"schema": {
|
|
710
|
+
"type": "string",
|
|
711
|
+
"default": ""
|
|
712
|
+
}
|
|
713
|
+
},
|
|
714
|
+
{
|
|
715
|
+
"param_id": "386719b1f2a178",
|
|
716
|
+
"description": "是否显示手机运营商,1:显示,0:不显示(默认)",
|
|
717
|
+
"field_type": "integer",
|
|
718
|
+
"is_checked": 1,
|
|
719
|
+
"key": "type",
|
|
720
|
+
"not_null": -1,
|
|
721
|
+
"value": "",
|
|
722
|
+
"content_type": "",
|
|
723
|
+
"file_name": "",
|
|
724
|
+
"file_base64": "",
|
|
725
|
+
"schema": {
|
|
726
|
+
"type": "integer"
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
"param_id": "38671b23b2a17a",
|
|
731
|
+
"description": "是否显示聚合订单号,1:显示,0:不显示(默认)",
|
|
732
|
+
"field_type": "integer",
|
|
733
|
+
"is_checked": 1,
|
|
734
|
+
"key": "showid",
|
|
735
|
+
"not_null": -1,
|
|
736
|
+
"value": "",
|
|
737
|
+
"content_type": "",
|
|
738
|
+
"file_name": "",
|
|
739
|
+
"file_base64": "",
|
|
740
|
+
"schema": {
|
|
741
|
+
"type": "integer"
|
|
742
|
+
}
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
"param_id": "38671cc572a17c",
|
|
746
|
+
"description": "是否显示手机号归属地,1:显示,0:不显示(默认)",
|
|
747
|
+
"field_type": "integer",
|
|
748
|
+
"is_checked": 1,
|
|
749
|
+
"key": "province",
|
|
750
|
+
"not_null": -1,
|
|
751
|
+
"value": "",
|
|
752
|
+
"content_type": "",
|
|
753
|
+
"file_name": "",
|
|
754
|
+
"file_base64": "",
|
|
755
|
+
"schema": {
|
|
756
|
+
"type": "integer"
|
|
757
|
+
}
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
"param_id": "38671e0572a17e",
|
|
761
|
+
"description": "是否显示匹配详情码,1:显示,0:不显示(默认)",
|
|
762
|
+
"field_type": "integer",
|
|
763
|
+
"is_checked": 1,
|
|
764
|
+
"key": "detail",
|
|
765
|
+
"not_null": -1,
|
|
766
|
+
"value": "",
|
|
767
|
+
"content_type": "",
|
|
768
|
+
"file_name": "",
|
|
769
|
+
"file_base64": "",
|
|
770
|
+
"schema": {
|
|
771
|
+
"type": "integer"
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
],
|
|
775
|
+
"raw": "{\n \"lastLoginAt\":1\n}",
|
|
776
|
+
"raw_parameter": [],
|
|
777
|
+
"raw_schema": {
|
|
778
|
+
"type": "object",
|
|
779
|
+
"required": [
|
|
780
|
+
"id"
|
|
781
|
+
],
|
|
782
|
+
"properties": {
|
|
783
|
+
"id": {
|
|
784
|
+
"type": "integer",
|
|
785
|
+
"example": 1
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
"x-schema-orders": [
|
|
789
|
+
"id"
|
|
790
|
+
]
|
|
791
|
+
},
|
|
792
|
+
"binary": null
|
|
793
|
+
},
|
|
794
|
+
"pre_tasks": [
|
|
795
|
+
{
|
|
796
|
+
"type": "customScript",
|
|
797
|
+
"enabled": 1,
|
|
798
|
+
"data": "// This code is generated by [Apipost] AI.\nfunction encryptRequestParamsWithAES() {\n try {\n // 获取请求参数\n let requestParams = request.request_bodys;\n if (_.isString(requestParams)) {\n try {\n requestParams = JSON5.parse(requestParams);\n } catch (e) {\n console.warn('请求参数解析为JSON失败');\n return;\n }\n }\n // 将请求参数转换为字符串\n const paramsStr = JSON5.stringify(requestParams);\n // 使用CryptoJS进行AES加密,这里假设密钥为固定值,实际应用中应妥善处理密钥\n const encrypted = CryptoJS.AES.encrypt(paramsStr, 'Secret Passphrase');\n // 设置加密后的参数为请求体\n pm.setRequestBody(encrypted.toString());\n } catch (error) {\n console.error('加密请求参数时出错:', error);\n }\n}",
|
|
799
|
+
"name": "自定义脚本",
|
|
800
|
+
"id": "3a0094827ff006"
|
|
801
|
+
}
|
|
802
|
+
],
|
|
803
|
+
"post_tasks": [
|
|
804
|
+
{
|
|
805
|
+
"type": "customScript",
|
|
806
|
+
"enabled": 1,
|
|
807
|
+
"data": "// This code is generated by [Apipost] AI.\nfunction generateVisualizerScript() {\n try {\n const objData = pm.response.json();\n const template = `\n <style>\n .table { background-color: #FFFFFF; border-radius: 8px; }\n .table th { background-color: #F0F0F0; padding: 10px; border-bottom: 1px solid #DDDDDD; }\n .table td { padding: 10px; border-bottom: 1px solid #DDDDDD; }\n </style>\n <table class=\"table\">\n <thead>\n <tr>\n <th>字段</th>\n <th>值</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>resultcode</td>\n <td>{{resultcode}}</td>\n </tr>\n <tr>\n <td>reason</td>\n <td>{{reason}}</td>\n </tr>\n <tr>\n <td>result</td>\n <td>{{result}}</td>\n </tr>\n <tr>\n <td>error_code</td>\n <td>{{error_code}}</td>\n </tr>\n </tbody>\n </table>\n `;\n pm.visualizer.set(template, objData);\n } catch (e) {\n console.error('生成可视化脚本时出错:', e);\n }\n}\ngenerateVisualizerScript();",
|
|
808
|
+
"name": "自定义脚本",
|
|
809
|
+
"id": "39e9dc0dfff010"
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
"type": "customScript",
|
|
813
|
+
"enabled": 1,
|
|
814
|
+
"data": "// 断言响应状态码是否为200\npm.test(\"响应状态码为200\", function () {\n pm.response.to.have.status(200);\n});\n// 断言响应时间是否小于300毫秒(行业推荐平均响应时间)\npm.test(\"响应时间小于300毫秒\", function () {\n pm.expect(pm.response.responseTime).to.be.below(300);\n});\n// 断言响应体中resultcode字段是否为101\npm.test(\"响应体中resultcode字段为101\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.resultcode).to.eql(\"101\");\n});\n// 断言响应体中reason字段是否为错误的请求KEY\npm.test(\"响应体中reason字段为错误的请求KEY\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.reason).to.eql(\"错误的请求KEY\");\n});\n// 断言响应体中error_code字段是否为10001\npm.test(\"响应体中error_code字段为10001\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.error_code).to.eql(10001);\n});\n// 断言响应体是否为有效的JSON格式\npm.test(\"响应体必须是json\", function () {\n pm.response.to.be.json;\n});",
|
|
815
|
+
"name": "AI断言",
|
|
816
|
+
"id": "3a01bc577ff018"
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
"type": "customScript",
|
|
820
|
+
"enabled": 1,
|
|
821
|
+
"data": "// 断言响应状态码是否为200\npm.test(\"响应状态码为200\", function () {\n pm.response.to.have.status(200);\n});\n// 断言响应时间是否小于300毫秒(行业推荐平均响应时间)\npm.test(\"响应时间小于300毫秒\", function () {\n pm.expect(pm.response.responseTime).to.be.below(300);\n});\n// 断言响应体中的resultcode是否为101\npm.test(\"响应体中的resultcode为101\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.resultcode).to.eql(\"101\");\n});\n// 断言响应体中的reason是否为错误的请求KEY\npm.test(\"响应体中的reason为错误的请求KEY\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.reason).to.eql(\"错误的请求KEY\");\n});\n// 断言响应体中的error_code是否为10001\npm.test(\"响应体中的error_code为10001\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.error_code).to.eql(10001);\n});",
|
|
822
|
+
"name": "AI Assertion",
|
|
823
|
+
"id": "3a025d25fff008"
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
"type": "customScript",
|
|
827
|
+
"enabled": 1,
|
|
828
|
+
"data": "// 断言响应状态码是否为200,通常200表示请求成功\npm.test(\"响应状态码为200\", function () {\n pm.response.to.have.status(200);\n});\n// 断言响应时间是否小于300毫秒,300毫秒是行业推荐的平均响应时间\npm.test(\"响应时间小于300毫秒\", function () {\n pm.expect(pm.response.responseTime).to.be.below(300);\n});\n// 断言响应体中的resultcode字段是否为101\npm.test(\"响应体中的resultcode为101\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.resultcode).to.eql(\"101\");\n});\n// 断言响应体中的reason字段是否为'错误的请求KEY'\npm.test(\"响应体中的reason为错误的请求KEY\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.reason).to.eql(\"错误的请求KEY\");\n});\n// 断言响应体中的error_code字段是否为10001\npm.test(\"响应体中的error_code为10001\", function () {\n var jsonData = pm.response.json();\n pm.expect(jsonData.error_code).to.eql(10001);\n});",
|
|
829
|
+
"name": "AI断言",
|
|
830
|
+
"id": "3a1eabf07ff00c"
|
|
831
|
+
}
|
|
832
|
+
],
|
|
833
|
+
"header": {
|
|
834
|
+
"parameter": [
|
|
835
|
+
{
|
|
836
|
+
"param_id": "38670379f2a15a",
|
|
837
|
+
"description": "请求内容类型",
|
|
838
|
+
"field_type": "string",
|
|
839
|
+
"is_checked": 1,
|
|
840
|
+
"key": "Content-Type",
|
|
841
|
+
"not_null": 1,
|
|
842
|
+
"value": "application/x-www-form-urlencoded",
|
|
843
|
+
"schema": {
|
|
844
|
+
"type": "string"
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
]
|
|
848
|
+
},
|
|
849
|
+
"query": {
|
|
850
|
+
"query_add_equal": 1,
|
|
851
|
+
"parameter": [
|
|
852
|
+
{
|
|
853
|
+
"param_id": "3867057a72a15c",
|
|
854
|
+
"field_type": "string",
|
|
855
|
+
"is_checked": 1,
|
|
856
|
+
"key": "a",
|
|
857
|
+
"not_null": 1,
|
|
858
|
+
"value": "{{a}}",
|
|
859
|
+
"description": "在个人中心->我的数据,接口名称上方查看"
|
|
860
|
+
}
|
|
861
|
+
]
|
|
862
|
+
},
|
|
863
|
+
"cookie": {
|
|
864
|
+
"cookie_encode": 1,
|
|
865
|
+
"parameter": []
|
|
866
|
+
},
|
|
867
|
+
"restful": {
|
|
868
|
+
"parameter": []
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
172
872
|
}
|
|
173
873
|
}
|
|
174
874
|
]
|