@tmsfe/tms-core 0.0.119 → 0.0.121
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 -4
- package/src/location/index.ts +26 -26
- package/src/md5.js +365 -177
- package/src/mpInfo.js +2 -2
- package/src/request.js +9 -0
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import Request from './request';
|
|
5
5
|
import { getEnvInfo } from './env';
|
|
6
6
|
|
|
7
|
-
const api = new Request();
|
|
8
7
|
const parseAllCfgs = (configPaths, resData, defaultCfgs) => configPaths.map((path, index) => {
|
|
9
8
|
const found = resData.find(cfg => cfg.configPath === path);
|
|
10
9
|
if (found) {
|
|
@@ -61,7 +60,7 @@ function getConfig(configPath, extendAttr = {}, defaultCfg) {
|
|
|
61
60
|
const configPaths = formatConfigPaths(configPath);
|
|
62
61
|
const defaultCfgs = (defaultCfg && (Array.isArray(defaultCfg) ? defaultCfg : [defaultCfg])) || null;
|
|
63
62
|
const extendAttrs = typeof extendAttr === 'string' ? extendAttr : JSON.stringify(extendAttr);
|
|
64
|
-
return
|
|
63
|
+
return Request.getInstance().post('marketing/config', {
|
|
65
64
|
extendAttrs,
|
|
66
65
|
configPaths,
|
|
67
66
|
})
|
|
@@ -104,8 +103,7 @@ function getApolloConfig(configPath, extendAttr = {}, defaultCfg) {
|
|
|
104
103
|
const configPaths = formatConfigPaths(configPath);
|
|
105
104
|
const defaultCfgs = (defaultCfg && (Array.isArray(defaultCfg) ? defaultCfg : [defaultCfg])) || null;
|
|
106
105
|
const { businessKey, moduleKey, ...extendAttrs } = extendAttr;
|
|
107
|
-
|
|
108
|
-
return api.post('marketing/apollo/config', {
|
|
106
|
+
return Request.getInstance().post('marketing/apollo/config', {
|
|
109
107
|
businessKey,
|
|
110
108
|
moduleKey,
|
|
111
109
|
configPaths,
|
package/src/location/index.ts
CHANGED
|
@@ -37,7 +37,6 @@ interface IpLocationType {
|
|
|
37
37
|
},
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const request = new Request();
|
|
41
40
|
const event = new EventDispatcher();
|
|
42
41
|
|
|
43
42
|
const userLocationCache: UserLocationType = {}; // 获取位置缓存
|
|
@@ -104,35 +103,36 @@ class Location extends LocationBase {
|
|
|
104
103
|
return userLocationCache[cacheName];
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
userLocationCache[cacheName] =
|
|
108
|
-
|
|
106
|
+
userLocationCache[cacheName] = Request.getInstance().post('basic/lbs/decode', { lat, lng, getPoi })
|
|
107
|
+
.then((res) => {
|
|
108
|
+
const { errCode, resData = {} } = res;
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
if (errCode === 0) {
|
|
111
|
+
const { result = {} } = resData;
|
|
112
|
+
const { ad_info: adInfo = {} } = result;
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
const loc = {
|
|
115
|
+
nationCode: adInfo.nation_code,
|
|
116
|
+
province: adInfo.province,
|
|
117
|
+
cityName: adInfo.city,
|
|
118
|
+
district: adInfo.district,
|
|
119
|
+
adCode: adInfo.adcode,
|
|
120
|
+
cityCode: formatCityCode(adInfo.city_code, adInfo.nation_code),
|
|
121
|
+
latitude: lat,
|
|
122
|
+
longitude: lng,
|
|
123
|
+
};
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
if (getPoi === 0) {
|
|
126
|
+
return loc;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
loc.adCode = adInfo.adcode;
|
|
130
|
+
(loc as typeof loc & { poi: object }).poi = formatPoi(result);
|
|
126
131
|
return loc;
|
|
127
132
|
}
|
|
128
133
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return loc;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return Promise.reject(res);
|
|
135
|
-
})
|
|
134
|
+
return Promise.reject(res);
|
|
135
|
+
})
|
|
136
136
|
.catch(err => Promise.reject(err));
|
|
137
137
|
|
|
138
138
|
return userLocationCache[cacheName];
|
|
@@ -324,7 +324,7 @@ class Location extends LocationBase {
|
|
|
324
324
|
const { latitude, longitude } = (await this.getMergedLocation() as PostionType);
|
|
325
325
|
from = `${latitude},${longitude}`;
|
|
326
326
|
}
|
|
327
|
-
return
|
|
327
|
+
return Request.getInstance().post('basic/lbs/direction', { from, to, mode });
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
/**
|
|
@@ -336,7 +336,7 @@ class Location extends LocationBase {
|
|
|
336
336
|
getIpLocation(force = false): Promise<IpLocationType> {
|
|
337
337
|
if (ipLocationPromise === null || force) {
|
|
338
338
|
ipLocationPromise = new Promise((resolve, reject) => {
|
|
339
|
-
|
|
339
|
+
Request.getInstance().post('basic/lbs/decodeip')
|
|
340
340
|
.then((res) => {
|
|
341
341
|
if (res.errCode === 0) {
|
|
342
342
|
resolve(res.resData as IpLocationType);
|
package/src/md5.js
CHANGED
|
@@ -1,187 +1,375 @@
|
|
|
1
|
-
|
|
2
|
-
* @author Davis.Lu <davislu@tencent.com>
|
|
3
|
-
* @desc: 基于md5算法对源字符串进行hash,生成hash字符串
|
|
4
|
-
**/
|
|
5
|
-
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
6
2
|
/**
|
|
7
3
|
* @public
|
|
8
4
|
* @description 基于md5算法对源字符串进行hash,生成hash字符串
|
|
9
5
|
* @param {String} str 源字符串
|
|
10
6
|
* @returns {String} 源字符串的md5 hash值
|
|
7
|
+
* MIT https://github.com/blueimp/JavaScript-MD5
|
|
11
8
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Add integers, wrapping at 2^32.
|
|
11
|
+
* This uses 16-bit operations internally to work around bugs in interpreters.
|
|
12
|
+
*
|
|
13
|
+
* @param {number} x First integer
|
|
14
|
+
* @param {number} y Second integer
|
|
15
|
+
* @returns {number} Sum
|
|
16
|
+
*/
|
|
17
|
+
function safeAdd(x, y) {
|
|
18
|
+
const lsw = (x & 0xffff) + (y & 0xffff);
|
|
19
|
+
const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
|
20
|
+
return (msw << 16) | (lsw & 0xffff);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Bitwise rotate a 32-bit number to the left.
|
|
25
|
+
*
|
|
26
|
+
* @param {number} num 32-bit number
|
|
27
|
+
* @param {number} cnt Rotation count
|
|
28
|
+
* @returns {number} Rotated number
|
|
29
|
+
*/
|
|
30
|
+
function bitRotateLeft(num, cnt) {
|
|
31
|
+
return (num << cnt) | (num >>> (32 - cnt));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Basic operation the algorithm uses.
|
|
36
|
+
*
|
|
37
|
+
* @param {number} q q
|
|
38
|
+
* @param {number} a a
|
|
39
|
+
* @param {number} b b
|
|
40
|
+
* @param {number} x x
|
|
41
|
+
* @param {number} s s
|
|
42
|
+
* @param {number} t t
|
|
43
|
+
* @returns {number} Result
|
|
44
|
+
*/
|
|
45
|
+
function md5cmn(q, a, b, x, s, t) {
|
|
46
|
+
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Basic operation the algorithm uses.
|
|
50
|
+
*
|
|
51
|
+
* @param {number} a a
|
|
52
|
+
* @param {number} b b
|
|
53
|
+
* @param {number} c c
|
|
54
|
+
* @param {number} d d
|
|
55
|
+
* @param {number} x x
|
|
56
|
+
* @param {number} s s
|
|
57
|
+
* @param {number} t t
|
|
58
|
+
* @returns {number} Result
|
|
59
|
+
*/
|
|
60
|
+
function md5ff(a, b, c, d, x, s, t) {
|
|
61
|
+
return md5cmn((b & c) | (~b & d), a, b, x, s, t);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Basic operation the algorithm uses.
|
|
65
|
+
*
|
|
66
|
+
* @param {number} a a
|
|
67
|
+
* @param {number} b b
|
|
68
|
+
* @param {number} c c
|
|
69
|
+
* @param {number} d d
|
|
70
|
+
* @param {number} x x
|
|
71
|
+
* @param {number} s s
|
|
72
|
+
* @param {number} t t
|
|
73
|
+
* @returns {number} Result
|
|
74
|
+
*/
|
|
75
|
+
function md5gg(a, b, c, d, x, s, t) {
|
|
76
|
+
return md5cmn((b & d) | (c & ~d), a, b, x, s, t);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Basic operation the algorithm uses.
|
|
80
|
+
*
|
|
81
|
+
* @param {number} a a
|
|
82
|
+
* @param {number} b b
|
|
83
|
+
* @param {number} c c
|
|
84
|
+
* @param {number} d d
|
|
85
|
+
* @param {number} x x
|
|
86
|
+
* @param {number} s s
|
|
87
|
+
* @param {number} t t
|
|
88
|
+
* @returns {number} Result
|
|
89
|
+
*/
|
|
90
|
+
function md5hh(a, b, c, d, x, s, t) {
|
|
91
|
+
return md5cmn(b ^ c ^ d, a, b, x, s, t);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Basic operation the algorithm uses.
|
|
95
|
+
*
|
|
96
|
+
* @param {number} a a
|
|
97
|
+
* @param {number} b b
|
|
98
|
+
* @param {number} c c
|
|
99
|
+
* @param {number} d d
|
|
100
|
+
* @param {number} x x
|
|
101
|
+
* @param {number} s s
|
|
102
|
+
* @param {number} t t
|
|
103
|
+
* @returns {number} Result
|
|
104
|
+
*/
|
|
105
|
+
function md5ii(a, b, c, d, x, s, t) {
|
|
106
|
+
return md5cmn(c ^ (b | ~d), a, b, x, s, t);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Calculate the MD5 of an array of little-endian words, and a bit length.
|
|
111
|
+
*
|
|
112
|
+
* @param {Array} x Array of little-endian words
|
|
113
|
+
* @param {number} len Bit length
|
|
114
|
+
* @returns {Array<number>} MD5 Array
|
|
115
|
+
*/
|
|
116
|
+
function binlMD5(x, len) {
|
|
117
|
+
/* append padding */
|
|
118
|
+
x[len >> 5] |= 0x80 << len % 32;
|
|
119
|
+
x[(((len + 64) >>> 9) << 4) + 14] = len;
|
|
120
|
+
|
|
121
|
+
let i;
|
|
122
|
+
let olda;
|
|
123
|
+
let oldb;
|
|
124
|
+
let oldc;
|
|
125
|
+
let oldd;
|
|
126
|
+
let a = 1732584193;
|
|
127
|
+
let b = -271733879;
|
|
128
|
+
let c = -1732584194;
|
|
129
|
+
let d = 271733878;
|
|
130
|
+
|
|
131
|
+
for (i = 0; i < x.length; i += 16) {
|
|
132
|
+
olda = a;
|
|
133
|
+
oldb = b;
|
|
134
|
+
oldc = c;
|
|
135
|
+
oldd = d;
|
|
136
|
+
|
|
137
|
+
a = md5ff(a, b, c, d, x[i], 7, -680876936);
|
|
138
|
+
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
|
|
139
|
+
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
|
|
140
|
+
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
|
141
|
+
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
|
|
142
|
+
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
|
143
|
+
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
|
144
|
+
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
|
|
145
|
+
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
|
146
|
+
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
|
147
|
+
c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
|
|
148
|
+
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
|
149
|
+
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
|
150
|
+
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
|
|
151
|
+
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
|
152
|
+
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
|
153
|
+
|
|
154
|
+
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
|
|
155
|
+
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
|
156
|
+
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
|
|
157
|
+
b = md5gg(b, c, d, a, x[i], 20, -373897302);
|
|
158
|
+
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
|
|
159
|
+
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
|
|
160
|
+
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
|
|
161
|
+
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
|
|
162
|
+
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
|
|
163
|
+
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
|
164
|
+
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
|
|
165
|
+
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
|
166
|
+
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
|
167
|
+
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
|
|
168
|
+
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
|
169
|
+
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
|
170
|
+
|
|
171
|
+
a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
|
|
172
|
+
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
|
173
|
+
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
|
174
|
+
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
|
|
175
|
+
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
|
176
|
+
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
|
177
|
+
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
|
|
178
|
+
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
|
179
|
+
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
|
|
180
|
+
d = md5hh(d, a, b, c, x[i], 11, -358537222);
|
|
181
|
+
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
|
|
182
|
+
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
|
|
183
|
+
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
|
|
184
|
+
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
|
|
185
|
+
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
|
|
186
|
+
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
|
|
187
|
+
|
|
188
|
+
a = md5ii(a, b, c, d, x[i], 6, -198630844);
|
|
189
|
+
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
|
190
|
+
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
|
191
|
+
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
|
|
192
|
+
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
|
193
|
+
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
|
194
|
+
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
|
|
195
|
+
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
|
196
|
+
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
|
197
|
+
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
|
|
198
|
+
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
|
199
|
+
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
|
200
|
+
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
|
|
201
|
+
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
|
202
|
+
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
|
|
203
|
+
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
|
|
204
|
+
|
|
205
|
+
a = safeAdd(a, olda);
|
|
206
|
+
b = safeAdd(b, oldb);
|
|
207
|
+
c = safeAdd(c, oldc);
|
|
208
|
+
d = safeAdd(d, oldd);
|
|
209
|
+
}
|
|
210
|
+
return [a, b, c, d];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Convert an array of little-endian words to a string
|
|
215
|
+
*
|
|
216
|
+
* @param {Array<number>} input MD5 Array
|
|
217
|
+
* @returns {string} MD5 string
|
|
218
|
+
*/
|
|
219
|
+
function binl2rstr(input) {
|
|
220
|
+
let i;
|
|
221
|
+
let output = '';
|
|
222
|
+
const length32 = input.length * 32;
|
|
223
|
+
for (i = 0; i < length32; i += 8) {
|
|
224
|
+
output += String.fromCharCode((input[i >> 5] >>> i % 32) & 0xff);
|
|
225
|
+
}
|
|
226
|
+
return output;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Convert a raw string to an array of little-endian words
|
|
231
|
+
* Characters >255 have their high-byte silently ignored.
|
|
232
|
+
*
|
|
233
|
+
* @param {string} input Raw input string
|
|
234
|
+
* @returns {Array<number>} Array of little-endian words
|
|
235
|
+
*/
|
|
236
|
+
function rstr2binl(input) {
|
|
237
|
+
let i;
|
|
238
|
+
const output = [];
|
|
239
|
+
output[(input.length >> 2) - 1] = undefined;
|
|
240
|
+
for (i = 0; i < output.length; i += 1) {
|
|
241
|
+
output[i] = 0;
|
|
242
|
+
}
|
|
243
|
+
const length8 = input.length * 8;
|
|
244
|
+
for (i = 0; i < length8; i += 8) {
|
|
245
|
+
output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << i % 32;
|
|
246
|
+
}
|
|
247
|
+
return output;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Calculate the MD5 of a raw string
|
|
252
|
+
*
|
|
253
|
+
* @param {string} s Input string
|
|
254
|
+
* @returns {string} Raw MD5 string
|
|
255
|
+
*/
|
|
256
|
+
function rstrMD5(s) {
|
|
257
|
+
return binl2rstr(binlMD5(rstr2binl(s), s.length * 8));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Calculates the HMAC-MD5 of a key and some data (raw strings)
|
|
262
|
+
*
|
|
263
|
+
* @param {string} key HMAC key
|
|
264
|
+
* @param {string} data Raw input string
|
|
265
|
+
* @returns {string} Raw MD5 string
|
|
266
|
+
*/
|
|
267
|
+
function rstrHMACMD5(key, data) {
|
|
268
|
+
let i;
|
|
269
|
+
let bkey = rstr2binl(key);
|
|
270
|
+
const ipad = [];
|
|
271
|
+
const opad = [];
|
|
272
|
+
ipad[15] = undefined;
|
|
273
|
+
opad[15] = undefined;
|
|
274
|
+
if (bkey.length > 16) {
|
|
275
|
+
bkey = binlMD5(bkey, key.length * 8);
|
|
276
|
+
}
|
|
277
|
+
for (i = 0; i < 16; i += 1) {
|
|
278
|
+
ipad[i] = bkey[i] ^ 0x36363636;
|
|
279
|
+
opad[i] = bkey[i] ^ 0x5c5c5c5c;
|
|
280
|
+
}
|
|
281
|
+
const hash = binlMD5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
|
|
282
|
+
return binl2rstr(binlMD5(opad.concat(hash), 512 + 128));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Convert a raw string to a hex string
|
|
287
|
+
*
|
|
288
|
+
* @param {string} input Raw input string
|
|
289
|
+
* @returns {string} Hex encoded string
|
|
290
|
+
*/
|
|
291
|
+
function rstr2hex(input) {
|
|
292
|
+
const hexTab = '0123456789abcdef';
|
|
293
|
+
let output = '';
|
|
294
|
+
let x;
|
|
295
|
+
let i;
|
|
296
|
+
for (i = 0; i < input.length; i += 1) {
|
|
297
|
+
x = input.charCodeAt(i);
|
|
298
|
+
output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f);
|
|
299
|
+
}
|
|
300
|
+
return output;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Encode a string as UTF-8
|
|
305
|
+
*
|
|
306
|
+
* @param {string} input Input string
|
|
307
|
+
* @returns {string} UTF8 string
|
|
308
|
+
*/
|
|
309
|
+
function str2rstrUTF8(input) {
|
|
310
|
+
return unescape(encodeURIComponent(input));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Encodes input string as raw MD5 string
|
|
315
|
+
*
|
|
316
|
+
* @param {string} s Input string
|
|
317
|
+
* @returns {string} Raw MD5 string
|
|
318
|
+
*/
|
|
319
|
+
function rawMD5(s) {
|
|
320
|
+
return rstrMD5(str2rstrUTF8(s));
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Encodes input string as Hex encoded string
|
|
324
|
+
*
|
|
325
|
+
* @param {string} s Input string
|
|
326
|
+
* @returns {string} Hex encoded string
|
|
327
|
+
*/
|
|
328
|
+
function hexMD5(s) {
|
|
329
|
+
return rstr2hex(rawMD5(s));
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Calculates the raw HMAC-MD5 for the given key and data
|
|
333
|
+
*
|
|
334
|
+
* @param {string} k HMAC key
|
|
335
|
+
* @param {string} d Input string
|
|
336
|
+
* @returns {string} Raw MD5 string
|
|
337
|
+
*/
|
|
338
|
+
function rawHMACMD5(k, d) {
|
|
339
|
+
return rstrHMACMD5(str2rstrUTF8(k), str2rstrUTF8(d));
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Calculates the Hex encoded HMAC-MD5 for the given key and data
|
|
343
|
+
*
|
|
344
|
+
* @param {string} k HMAC key
|
|
345
|
+
* @param {string} d Input string
|
|
346
|
+
* @returns {string} Raw MD5 string
|
|
347
|
+
*/
|
|
348
|
+
function hexHMACMD5(k, d) {
|
|
349
|
+
return rstr2hex(rawHMACMD5(k, d));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Calculates MD5 value for a given string.
|
|
354
|
+
* If a key is provided, calculates the HMAC-MD5 value.
|
|
355
|
+
* Returns a Hex encoded string unless the raw argument is given.
|
|
356
|
+
*
|
|
357
|
+
* @param {string} string Input string
|
|
358
|
+
* @param {string} [key] HMAC key
|
|
359
|
+
* @param {boolean} [raw] Raw output switch
|
|
360
|
+
* @returns {string} MD5 output
|
|
361
|
+
*/
|
|
362
|
+
function md5(string, key, raw) {
|
|
363
|
+
if (!key) {
|
|
364
|
+
if (!raw) {
|
|
365
|
+
return hexMD5(string);
|
|
127
366
|
}
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const kiArr = ('16b05af49e38d27c58be147ad0369cf207e5c3a18f6d4b29').split('').map(n => parseInt(n, 16));
|
|
133
|
-
const hxArr = [
|
|
134
|
-
0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501,
|
|
135
|
-
0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821,
|
|
136
|
-
0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, 0xD62F105D, 0x2441453, 0xD8A1E681, 0xE7D3FBC8,
|
|
137
|
-
0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A,
|
|
138
|
-
0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70,
|
|
139
|
-
0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x4881D05, 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665,
|
|
140
|
-
0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1,
|
|
141
|
-
0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391,
|
|
142
|
-
];
|
|
143
|
-
// eslint-disable-next-line require-jsdoc
|
|
144
|
-
const cyc = (i, r = 0) => (i + r) % 4;
|
|
145
|
-
// 4组处理位操作函数
|
|
146
|
-
// eslint-disable-next-line require-jsdoc
|
|
147
|
-
const md5F = (x, y, z) => (x & y) | ((~x) & z);
|
|
148
|
-
// eslint-disable-next-line require-jsdoc
|
|
149
|
-
const md5G = (x, y, z) => (x & z) | (y & (~z));
|
|
150
|
-
// eslint-disable-next-line require-jsdoc
|
|
151
|
-
const md5H = (x, y, z) => (x ^ y ^ z);
|
|
152
|
-
// eslint-disable-next-line require-jsdoc
|
|
153
|
-
const md5I = (x, y, z) => (y ^ (x | (~z)));
|
|
154
|
-
const string = encodeUtf8(str);
|
|
155
|
-
const x = convertToWordArray(string);
|
|
156
|
-
for (let k = 0; k < x.length; k += 16) {
|
|
157
|
-
const AA = a;
|
|
158
|
-
const BB = b;
|
|
159
|
-
const CC = c;
|
|
160
|
-
const DD = d;
|
|
161
|
-
const arr = [a, d, c, b];
|
|
162
|
-
hxArr.forEach((hx, m) => {
|
|
163
|
-
const i = m % 16;
|
|
164
|
-
const g = m / 16 << 0;
|
|
165
|
-
const ki = m < 16 ? m : kiArr[m - 16];
|
|
166
|
-
const FN = [md5F, md5G, md5H, md5I][g];
|
|
167
|
-
|
|
168
|
-
arr[cyc(i)] = addRecycling({
|
|
169
|
-
FN,
|
|
170
|
-
a: arr[cyc(i)],
|
|
171
|
-
b: arr[cyc(i, 3)],
|
|
172
|
-
c: arr[cyc(i, 2)],
|
|
173
|
-
d: arr[cyc(i, 1)],
|
|
174
|
-
x: x[k + ki],
|
|
175
|
-
s: sArr[g][i % 4],
|
|
176
|
-
ac: hx,
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
a = addUnsigned(arr[0], AA);
|
|
180
|
-
b = addUnsigned(arr[3], BB);
|
|
181
|
-
c = addUnsigned(arr[2], CC);
|
|
182
|
-
d = addUnsigned(arr[1], DD);
|
|
367
|
+
return rawMD5(string);
|
|
368
|
+
}
|
|
369
|
+
if (!raw) {
|
|
370
|
+
return hexHMACMD5(key, string);
|
|
183
371
|
}
|
|
184
|
-
return (
|
|
185
|
-
}
|
|
372
|
+
return rawHMACMD5(key, string);
|
|
373
|
+
}
|
|
186
374
|
|
|
187
375
|
export default md5;
|
package/src/mpInfo.js
CHANGED
|
@@ -16,7 +16,7 @@ import Request from './request';
|
|
|
16
16
|
* tms.getMpOpenId('xxx', '111')
|
|
17
17
|
*/
|
|
18
18
|
async function getMpOpenId(mpId, userId) {
|
|
19
|
-
const { resData } = await
|
|
19
|
+
const { resData } = await Request.getInstance().post('user/mpinfo', { userId, mpId });
|
|
20
20
|
const { openId = '' } = resData || {};
|
|
21
21
|
return openId;
|
|
22
22
|
}
|
|
@@ -33,7 +33,7 @@ async function getMpOpenId(mpId, userId) {
|
|
|
33
33
|
* tms.getMpOpenId('xxx', '111')
|
|
34
34
|
*/
|
|
35
35
|
async function getOuterOpenId(apiKey) {
|
|
36
|
-
const { resData } = await
|
|
36
|
+
const { resData } = await Request.getInstance().post('user/mpinfo', { mpId: apiKey });
|
|
37
37
|
const { openId = '' } = resData || {};
|
|
38
38
|
return openId;
|
|
39
39
|
}
|
package/src/request.js
CHANGED
|
@@ -110,6 +110,8 @@ const modifyAuthParam = async (param, withAuth) => {
|
|
|
110
110
|
return requestParam;
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
+
let reqInstance = null;
|
|
114
|
+
|
|
113
115
|
/**
|
|
114
116
|
* @public
|
|
115
117
|
* @class Request
|
|
@@ -129,6 +131,13 @@ export default class Request {
|
|
|
129
131
|
*/
|
|
130
132
|
static defaultSecretKey = '';
|
|
131
133
|
|
|
134
|
+
static getInstance() {
|
|
135
|
+
if (reqInstance === null) {
|
|
136
|
+
reqInstance = new Request();
|
|
137
|
+
}
|
|
138
|
+
return reqInstance;
|
|
139
|
+
}
|
|
140
|
+
|
|
132
141
|
host = '';
|
|
133
142
|
secretKey = '';
|
|
134
143
|
withAuth = true;
|