@tmsfe/tms-core 0.0.117 → 0.0.119
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/config.js +2 -2
- package/src/index.js +5 -1
- package/src/request.js +14 -6
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
import Request from './request';
|
|
5
5
|
import { getEnvInfo } from './env';
|
|
6
6
|
|
|
7
|
+
const api = new Request();
|
|
7
8
|
const parseAllCfgs = (configPaths, resData, defaultCfgs) => configPaths.map((path, index) => {
|
|
8
9
|
const found = resData.find(cfg => cfg.configPath === path);
|
|
9
10
|
if (found) {
|
|
10
11
|
return JSON.parse(found.configValue);
|
|
11
12
|
}
|
|
12
|
-
if (defaultCfgs
|
|
13
|
+
if (defaultCfgs?.[index]) {
|
|
13
14
|
return defaultCfgs[index];
|
|
14
15
|
}
|
|
15
16
|
return {}; // 没找到配置,返回一个空对象
|
|
@@ -60,7 +61,6 @@ function getConfig(configPath, extendAttr = {}, defaultCfg) {
|
|
|
60
61
|
const configPaths = formatConfigPaths(configPath);
|
|
61
62
|
const defaultCfgs = (defaultCfg && (Array.isArray(defaultCfg) ? defaultCfg : [defaultCfg])) || null;
|
|
62
63
|
const extendAttrs = typeof extendAttr === 'string' ? extendAttr : JSON.stringify(extendAttr);
|
|
63
|
-
const api = new Request();
|
|
64
64
|
return api.post('marketing/config', {
|
|
65
65
|
extendAttrs,
|
|
66
66
|
configPaths,
|
package/src/index.js
CHANGED
|
@@ -98,6 +98,7 @@ const getLocationBaseClass = () => LocationBase;
|
|
|
98
98
|
* @param {Object} options 初始化
|
|
99
99
|
* @param {String} options.appVersion 小程序本次发版的版本号
|
|
100
100
|
* @param {String} options.wxAppId appId
|
|
101
|
+
* @param {String} options.secretKey 密钥
|
|
101
102
|
* @param {String} options.client 小程序名
|
|
102
103
|
* @param {String} options.appEnv 环境名称 production、development、test、predist
|
|
103
104
|
* @param {Array} options.appPagePaths 小程序包含的所有页面路径
|
|
@@ -107,7 +108,9 @@ const getLocationBaseClass = () => LocationBase;
|
|
|
107
108
|
* @returns {void} 无返回值.
|
|
108
109
|
*/
|
|
109
110
|
const init = (options = {}) => {
|
|
110
|
-
const {
|
|
111
|
+
const {
|
|
112
|
+
appVersion, wxAppId, secretKey = '', client, defaultHost, cloudEnvId, appEnv, appPagePaths, homePage,
|
|
113
|
+
} = options;
|
|
111
114
|
const envInfo = {
|
|
112
115
|
wxAppId,
|
|
113
116
|
appVersion,
|
|
@@ -120,6 +123,7 @@ const init = (options = {}) => {
|
|
|
120
123
|
Reporter.init(envInfo);
|
|
121
124
|
AutoReport.init();
|
|
122
125
|
Request.defaultHost = defaultHost;
|
|
126
|
+
Request.defaultSecretKey = secretKey;
|
|
123
127
|
// 初始化云环境
|
|
124
128
|
wx.cloud.init({ env: cloudEnvId });
|
|
125
129
|
};
|
package/src/request.js
CHANGED
|
@@ -34,11 +34,11 @@ const seriesParam = (param) => {
|
|
|
34
34
|
* 用于对request请求对象做签名
|
|
35
35
|
* @private
|
|
36
36
|
* @param {object} param 需要做签名的参数
|
|
37
|
+
* @param {string} secretKey 签名密钥
|
|
37
38
|
* @returns {object} 签名后的参数对象
|
|
38
39
|
*/
|
|
39
|
-
const sign = (param = {}) => {
|
|
40
|
-
const
|
|
41
|
-
const signture = md5(seriesParam(param) + token);
|
|
40
|
+
const sign = (param = {}, secretKey) => {
|
|
41
|
+
const signture = md5(seriesParam(param) + secretKey);
|
|
42
42
|
return { ...param, sign: signture };
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
@@ -122,8 +122,15 @@ export default class Request {
|
|
|
122
122
|
* 具体业务模块 new Request() 使用时,不指定自定义 host ,将使用defaultHost
|
|
123
123
|
*/
|
|
124
124
|
static defaultHost = '';
|
|
125
|
+
/**
|
|
126
|
+
* 默认的request 签名密钥
|
|
127
|
+
* defaultSecretKey 在runtime初始化时进行设置,为当前小程序密钥
|
|
128
|
+
* 具体业务模块 new Request() 使用时,不指定自定义 secretKey ,将使用 defaultSecretKey
|
|
129
|
+
*/
|
|
130
|
+
static defaultSecretKey = '';
|
|
125
131
|
|
|
126
132
|
host = '';
|
|
133
|
+
secretKey = '';
|
|
127
134
|
withAuth = true;
|
|
128
135
|
baseParam = {};
|
|
129
136
|
|
|
@@ -138,6 +145,7 @@ export default class Request {
|
|
|
138
145
|
if (config.host) {
|
|
139
146
|
this.host = config.host;
|
|
140
147
|
}
|
|
148
|
+
this.secretKey = config.secretKey || Request.defaultSecretKey;
|
|
141
149
|
if (typeof config.withAuth !== 'undefined') {
|
|
142
150
|
this.withAuth = !!config.withAuth;
|
|
143
151
|
}
|
|
@@ -248,7 +256,7 @@ export default class Request {
|
|
|
248
256
|
name: 'content',
|
|
249
257
|
url: this.makeUrl(path),
|
|
250
258
|
filePath,
|
|
251
|
-
formData: sign(requestParam),
|
|
259
|
+
formData: sign(requestParam, this.secretKey),
|
|
252
260
|
header,
|
|
253
261
|
success: resolve,
|
|
254
262
|
fail: reject,
|
|
@@ -289,7 +297,7 @@ export default class Request {
|
|
|
289
297
|
async serialize(path, data = {}) {
|
|
290
298
|
let url = this.makeUrl(path);
|
|
291
299
|
const signData = await composeParam(data, this.withAuth, this.baseParam);
|
|
292
|
-
const signature = sign(signData);
|
|
300
|
+
const signature = sign(signData, this.secretKey);
|
|
293
301
|
const params = [];
|
|
294
302
|
Object.keys(signature).forEach((key) => {
|
|
295
303
|
const val = encodeURIComponent(signature[key]);
|
|
@@ -310,7 +318,7 @@ export default class Request {
|
|
|
310
318
|
*/
|
|
311
319
|
async createRequestTask(path, param = {}, method = 'POST', header = {}) {
|
|
312
320
|
const requestParam = await composeParam(param, this.withAuth, this.baseParam);
|
|
313
|
-
const data = sign(requestParam);
|
|
321
|
+
const data = sign(requestParam, this.secretKey);
|
|
314
322
|
return new Promise((resolve, reject) => {
|
|
315
323
|
const requestTime = Date.now();
|
|
316
324
|
const printLog = (isSuccess, res) => {
|