@tmsfe/tms-core 0.0.145 → 0.0.146
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/encrypt.js +4 -4
- package/src/request.js +8 -8
package/package.json
CHANGED
package/src/encrypt.js
CHANGED
|
@@ -58,10 +58,13 @@ function _getEccPublicId() {
|
|
|
58
58
|
}
|
|
59
59
|
// 检查path是否符合下发的路由前缀
|
|
60
60
|
function _checkPathInEnablePrefix(path) {
|
|
61
|
+
if (!_getEccPublicKey()) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
61
64
|
if (wx.$_publicKey && wx.$_publicKey.path === '*') {
|
|
62
65
|
return true;
|
|
63
66
|
}
|
|
64
|
-
const prefixArr = wx.$_publicKey && wx.$_publicKey.path ? wx.$_publicKey.path.split(',').map(item => item.trim()): [];
|
|
67
|
+
const prefixArr = wx.$_publicKey && wx.$_publicKey.path ? wx.$_publicKey.path.split(',').map(item => item.trim()) : [];
|
|
65
68
|
for (let i = 0, len = prefixArr.length; i < len; i++) {
|
|
66
69
|
if (path.indexOf(prefixArr[i]) > -1) {
|
|
67
70
|
return true;
|
|
@@ -247,9 +250,6 @@ const encryptPathRule = {
|
|
|
247
250
|
],
|
|
248
251
|
};
|
|
249
252
|
function needsEncryption(url, params) {
|
|
250
|
-
if (!_getEccPublicKey()) {
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
253
|
// 判断是否属于加密白名单, 如果不符合,直接返回false, 如果符合,则走下面的逻辑
|
|
254
254
|
const enablePathPrefix = _checkPathInEnablePrefix(url);
|
|
255
255
|
if (!enablePathPrefix) {
|
package/src/request.js
CHANGED
|
@@ -349,7 +349,7 @@ export default class Request {
|
|
|
349
349
|
// wx请求封装成promise
|
|
350
350
|
async wxRequest(path, method, header = {}, data, needReport, seqId) {
|
|
351
351
|
if (needReport && path.indexOf('basic/event/upload') < 0) {
|
|
352
|
-
|
|
352
|
+
logger.log(
|
|
353
353
|
'tms-performance-log',
|
|
354
354
|
'request_encrypt_log', 'main', 'send_unencrypt_request', seqId,
|
|
355
355
|
!!wx.$_publicKey, Request.requestEncryptOpen, path,
|
|
@@ -381,7 +381,7 @@ export default class Request {
|
|
|
381
381
|
encryptObj.updateDecryptKey(res.data.resData);
|
|
382
382
|
} catch (e) {
|
|
383
383
|
encryptObj.updateDecryptKey(null);
|
|
384
|
-
|
|
384
|
+
logger.log('tms-performance-log', 'request_encrypt_log', 'main', 'refresh_encrypt_key_false', e);
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
387
|
|
|
@@ -478,7 +478,7 @@ export default class Request {
|
|
|
478
478
|
header: encryptHeader, data: encryptData, aesKey,
|
|
479
479
|
} = encryptObj.reqEncrypt(method, data, header, '');
|
|
480
480
|
// 2. 发送请求
|
|
481
|
-
|
|
481
|
+
logger.log('tms-performance-log', 'request_encrypt_log', 'main', 'send_encrypt_request', seqId, '', '', path);
|
|
482
482
|
const result = await this.wxRequest(finalUrl, method, encryptHeader, encryptData, false, seqId);
|
|
483
483
|
const { header: resHeader, data: resData } = result;
|
|
484
484
|
// 3. 解密响应
|
|
@@ -487,12 +487,12 @@ export default class Request {
|
|
|
487
487
|
reporter.reportPerformance('request_encrypt_log', 'main', 'local_response_decrypt_fail', seqId);
|
|
488
488
|
return this.createRequestTask(path, param, method, header, false);
|
|
489
489
|
}
|
|
490
|
-
|
|
490
|
+
logger.log('tms-performance-log', 'request_encrypt_log', 'main', 'decrypt_response_success', seqId);
|
|
491
491
|
// 4. 处理解密失败的响应
|
|
492
492
|
const errCodeType = encryptObj.getErrcodeType(decryptData.errCode, decryptData.errMsg);
|
|
493
493
|
if (errCodeType === encryptObj.reqErrType.pubKeyInvalid) { // 秘钥失效
|
|
494
|
-
|
|
495
|
-
'request_encrypt_log', 'main', 'remote_response_decrypt_fail',
|
|
494
|
+
logger.log(
|
|
495
|
+
'tms-performance-log', 'request_encrypt_log', 'main', 'remote_response_decrypt_fail',
|
|
496
496
|
seqId, decryptData.errCode, retryTimes,
|
|
497
497
|
);
|
|
498
498
|
const encryptSwitch = await this.dealEncryptionSwitch(resHeader, true);
|
|
@@ -502,8 +502,8 @@ export default class Request {
|
|
|
502
502
|
return this.createRequestTask(path, param, method, header, encryptSwitch, retryTimes + 1);
|
|
503
503
|
}
|
|
504
504
|
if (errCodeType === encryptObj.reqErrType.decryptError) { // 解密失败
|
|
505
|
-
|
|
506
|
-
'request_encrypt_log', 'main', 'remote_response_decrypt_fail',
|
|
505
|
+
logger.log(
|
|
506
|
+
'tms-performance-log', 'request_encrypt_log', 'main', 'remote_response_decrypt_fail',
|
|
507
507
|
seqId, decryptData.errCode, retryTimes,
|
|
508
508
|
);
|
|
509
509
|
return this.createRequestTask(path, param, method, header, false);
|