@tmsfe/tms-core 0.0.112 → 0.0.113
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/package.json +1 -1
- package/src/request.js +50 -41
package/package.json
CHANGED
package/src/request.js
CHANGED
|
@@ -22,7 +22,7 @@ const logger = wx.getLogManager({});
|
|
|
22
22
|
*/
|
|
23
23
|
const seriesParam = (param) => {
|
|
24
24
|
const keys = Object.keys(param)
|
|
25
|
-
|
|
25
|
+
.sort();
|
|
26
26
|
const series = keys.map((key) => {
|
|
27
27
|
const val = param[key];
|
|
28
28
|
return `${key}${typeof val === 'object' ? JSON.stringify(val) : val}`;
|
|
@@ -53,12 +53,12 @@ const composeParam = async (param = {}, withAuth = true, baseParam = {}) => {
|
|
|
53
53
|
const version = '1.0';
|
|
54
54
|
const { appVersion, wxAppId, client } = getEnvInfo();
|
|
55
55
|
const nonce = Math.random()
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
.toString(36)
|
|
57
|
+
.substr(2, 10);
|
|
58
58
|
const timestamp = Date.now();
|
|
59
59
|
const random = Math.random()
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
.toString()
|
|
61
|
+
.slice(2, 7);
|
|
62
62
|
const sourceId = ['', 'sinan', 'mycar'].indexOf(client) + 7; // 6 未知 7 云函数 8 出行 9 我的车
|
|
63
63
|
const seqId = `${timestamp}${sourceId}${random}`;
|
|
64
64
|
const paramsWithAuth = await modifyAuthParam(param, withAuth);
|
|
@@ -76,14 +76,14 @@ const composeParam = async (param = {}, withAuth = true, baseParam = {}) => {
|
|
|
76
76
|
);
|
|
77
77
|
// 清理undefined和NaN的参数
|
|
78
78
|
Object.keys(combinedParam)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
.forEach((key) => {
|
|
80
|
+
if (typeof combinedParam[key] === 'number' && isNaN(combinedParam[key])) {
|
|
81
|
+
delete combinedParam[key];
|
|
82
|
+
}
|
|
83
|
+
if (typeof combinedParam[key] === 'undefined') {
|
|
84
|
+
delete combinedParam[key];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
87
|
return combinedParam;
|
|
88
88
|
};
|
|
89
89
|
|
|
@@ -312,43 +312,52 @@ export default class Request {
|
|
|
312
312
|
const requestParam = await composeParam(param, this.withAuth, this.baseParam);
|
|
313
313
|
const data = sign(requestParam);
|
|
314
314
|
return new Promise((resolve, reject) => {
|
|
315
|
+
|
|
316
|
+
const requestTime = Date.now();
|
|
317
|
+
const printLog = (isSuccess, res) => {
|
|
318
|
+
// 埋点已经单独打日志了,接口请求数据日志太长影响分析
|
|
319
|
+
if (path.indexOf('basic/event/upload') !== -1) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
let result = JSON.stringify(res);
|
|
324
|
+
// 打车日志不截断,方便用于回放
|
|
325
|
+
if (isSuccess && path.indexOf('/takecar/') === -1 && result.length > 500) {
|
|
326
|
+
result = `${result.substring(0, 500)} 内容太长被截断`;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const obj = {
|
|
330
|
+
path,
|
|
331
|
+
method,
|
|
332
|
+
header: JSON.stringify(header),
|
|
333
|
+
params: JSON.stringify(data),
|
|
334
|
+
duration: Date.now() - requestTime,
|
|
335
|
+
};
|
|
336
|
+
if (isSuccess) {
|
|
337
|
+
obj.res = result;
|
|
338
|
+
} else {
|
|
339
|
+
obj.err = result;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const str = JSON.stringify(obj, null, ' ').replace(/\\"/ig, '\'');
|
|
343
|
+
if (isSuccess) {
|
|
344
|
+
logger.log(`接口请求成功:\n${str}`);
|
|
345
|
+
} else {
|
|
346
|
+
logger.warn(`接口请求失败:\n${str}`);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
315
350
|
wx.request({
|
|
316
351
|
url: this.makeUrl(path),
|
|
317
352
|
header,
|
|
318
353
|
method,
|
|
319
354
|
data,
|
|
320
355
|
success: (res) => {
|
|
321
|
-
|
|
322
|
-
if (path.indexOf('basic/event/upload') === -1) {
|
|
323
|
-
let result = JSON.stringify(res?.data);
|
|
324
|
-
// 打车日志不截断,方便用于回放
|
|
325
|
-
if (path.indexOf('/takecar/') === -1 && result.length > 500) {
|
|
326
|
-
result = `${result.substring(0, 500)} 内容太长被截断`;
|
|
327
|
-
}
|
|
328
|
-
const obj = {
|
|
329
|
-
path,
|
|
330
|
-
method,
|
|
331
|
-
header: JSON.stringify(header),
|
|
332
|
-
params: JSON.stringify(data),
|
|
333
|
-
res: result,
|
|
334
|
-
};
|
|
335
|
-
const str = JSON.stringify(obj, null, ' ').replace(/\\"/ig, '\'');
|
|
336
|
-
logger.log(`接口请求成功:\n${str}`);
|
|
337
|
-
}
|
|
338
|
-
|
|
356
|
+
printLog(true, res.data);
|
|
339
357
|
resolve(res);
|
|
340
358
|
},
|
|
341
359
|
fail: (err) => {
|
|
342
|
-
|
|
343
|
-
path,
|
|
344
|
-
method,
|
|
345
|
-
header: JSON.stringify(header),
|
|
346
|
-
params: JSON.stringify(data),
|
|
347
|
-
err: JSON.stringify(err),
|
|
348
|
-
};
|
|
349
|
-
const str = JSON.stringify(obj, null, ' ').replace(/\\"/ig, '\'');
|
|
350
|
-
logger.warn(`接口请求失败:\n${str}`);
|
|
351
|
-
|
|
360
|
+
printLog(false, err);
|
|
352
361
|
reject(err);
|
|
353
362
|
},
|
|
354
363
|
});
|