@zym-test-zerog/apiclient 1.0.3 → 1.0.5
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/dist/index.d.ts +2 -2
- package/dist/index.js +353 -125
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +353 -126
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.mjs
CHANGED
|
@@ -115,6 +115,333 @@ class Logger {
|
|
|
115
115
|
}
|
|
116
116
|
const logger = new Logger();
|
|
117
117
|
|
|
118
|
+
function getDefaultExportFromCjs (x) {
|
|
119
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
var md5$1 = {exports: {}};
|
|
123
|
+
|
|
124
|
+
var crypt = {exports: {}};
|
|
125
|
+
|
|
126
|
+
(function() {
|
|
127
|
+
var base64map
|
|
128
|
+
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
|
129
|
+
|
|
130
|
+
crypt$1 = {
|
|
131
|
+
// Bit-wise rotation left
|
|
132
|
+
rotl: function(n, b) {
|
|
133
|
+
return (n << b) | (n >>> (32 - b));
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
// Bit-wise rotation right
|
|
137
|
+
rotr: function(n, b) {
|
|
138
|
+
return (n << (32 - b)) | (n >>> b);
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
// Swap big-endian to little-endian and vice versa
|
|
142
|
+
endian: function(n) {
|
|
143
|
+
// If number given, swap endian
|
|
144
|
+
if (n.constructor == Number) {
|
|
145
|
+
return crypt$1.rotl(n, 8) & 0x00FF00FF | crypt$1.rotl(n, 24) & 0xFF00FF00;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Else, assume array and swap all items
|
|
149
|
+
for (var i = 0; i < n.length; i++)
|
|
150
|
+
n[i] = crypt$1.endian(n[i]);
|
|
151
|
+
return n;
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
// Generate an array of any length of random bytes
|
|
155
|
+
randomBytes: function(n) {
|
|
156
|
+
for (var bytes = []; n > 0; n--)
|
|
157
|
+
bytes.push(Math.floor(Math.random() * 256));
|
|
158
|
+
return bytes;
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
// Convert a byte array to big-endian 32-bit words
|
|
162
|
+
bytesToWords: function(bytes) {
|
|
163
|
+
for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)
|
|
164
|
+
words[b >>> 5] |= bytes[i] << (24 - b % 32);
|
|
165
|
+
return words;
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
// Convert big-endian 32-bit words to a byte array
|
|
169
|
+
wordsToBytes: function(words) {
|
|
170
|
+
for (var bytes = [], b = 0; b < words.length * 32; b += 8)
|
|
171
|
+
bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);
|
|
172
|
+
return bytes;
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
// Convert a byte array to a hex string
|
|
176
|
+
bytesToHex: function(bytes) {
|
|
177
|
+
for (var hex = [], i = 0; i < bytes.length; i++) {
|
|
178
|
+
hex.push((bytes[i] >>> 4).toString(16));
|
|
179
|
+
hex.push((bytes[i] & 0xF).toString(16));
|
|
180
|
+
}
|
|
181
|
+
return hex.join('');
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
// Convert a hex string to a byte array
|
|
185
|
+
hexToBytes: function(hex) {
|
|
186
|
+
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
|
187
|
+
bytes.push(parseInt(hex.substr(c, 2), 16));
|
|
188
|
+
return bytes;
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
// Convert a byte array to a base-64 string
|
|
192
|
+
bytesToBase64: function(bytes) {
|
|
193
|
+
for (var base64 = [], i = 0; i < bytes.length; i += 3) {
|
|
194
|
+
var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
|
|
195
|
+
for (var j = 0; j < 4; j++)
|
|
196
|
+
if (i * 8 + j * 6 <= bytes.length * 8)
|
|
197
|
+
base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F));
|
|
198
|
+
else
|
|
199
|
+
base64.push('=');
|
|
200
|
+
}
|
|
201
|
+
return base64.join('');
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
// Convert a base-64 string to a byte array
|
|
205
|
+
base64ToBytes: function(base64) {
|
|
206
|
+
// Remove non-base-64 characters
|
|
207
|
+
base64 = base64.replace(/[^A-Z0-9+\/]/ig, '');
|
|
208
|
+
|
|
209
|
+
for (var bytes = [], i = 0, imod4 = 0; i < base64.length;
|
|
210
|
+
imod4 = ++i % 4) {
|
|
211
|
+
if (imod4 == 0) continue;
|
|
212
|
+
bytes.push(((base64map.indexOf(base64.charAt(i - 1))
|
|
213
|
+
& (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2))
|
|
214
|
+
| (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));
|
|
215
|
+
}
|
|
216
|
+
return bytes;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
crypt.exports = crypt$1;
|
|
221
|
+
})();
|
|
222
|
+
|
|
223
|
+
var cryptExports = crypt.exports;
|
|
224
|
+
|
|
225
|
+
var charenc = {
|
|
226
|
+
// UTF-8 encoding
|
|
227
|
+
utf8: {
|
|
228
|
+
// Convert a string to a byte array
|
|
229
|
+
stringToBytes: function(str) {
|
|
230
|
+
return charenc.bin.stringToBytes(unescape(encodeURIComponent(str)));
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
// Convert a byte array to a string
|
|
234
|
+
bytesToString: function(bytes) {
|
|
235
|
+
return decodeURIComponent(escape(charenc.bin.bytesToString(bytes)));
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
// Binary encoding
|
|
240
|
+
bin: {
|
|
241
|
+
// Convert a string to a byte array
|
|
242
|
+
stringToBytes: function(str) {
|
|
243
|
+
for (var bytes = [], i = 0; i < str.length; i++)
|
|
244
|
+
bytes.push(str.charCodeAt(i) & 0xFF);
|
|
245
|
+
return bytes;
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
// Convert a byte array to a string
|
|
249
|
+
bytesToString: function(bytes) {
|
|
250
|
+
for (var str = [], i = 0; i < bytes.length; i++)
|
|
251
|
+
str.push(String.fromCharCode(bytes[i]));
|
|
252
|
+
return str.join('');
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
var charenc_1 = charenc;
|
|
258
|
+
|
|
259
|
+
/*!
|
|
260
|
+
* Determine if an object is a Buffer
|
|
261
|
+
*
|
|
262
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
263
|
+
* @license MIT
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
// The _isBuffer check is for Safari 5-7 support, because it's missing
|
|
267
|
+
// Object.prototype.constructor. Remove this eventually
|
|
268
|
+
var isBuffer_1 = function (obj) {
|
|
269
|
+
return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
function isBuffer (obj) {
|
|
273
|
+
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// For Node v0.10 support. Remove this eventually.
|
|
277
|
+
function isSlowBuffer (obj) {
|
|
278
|
+
return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
(function(){
|
|
282
|
+
var crypt = cryptExports,
|
|
283
|
+
utf8 = charenc_1.utf8,
|
|
284
|
+
isBuffer = isBuffer_1,
|
|
285
|
+
bin = charenc_1.bin,
|
|
286
|
+
|
|
287
|
+
// The core
|
|
288
|
+
md5 = function (message, options) {
|
|
289
|
+
// Convert to byte array
|
|
290
|
+
if (message.constructor == String)
|
|
291
|
+
if (options && options.encoding === 'binary')
|
|
292
|
+
message = bin.stringToBytes(message);
|
|
293
|
+
else
|
|
294
|
+
message = utf8.stringToBytes(message);
|
|
295
|
+
else if (isBuffer(message))
|
|
296
|
+
message = Array.prototype.slice.call(message, 0);
|
|
297
|
+
else if (!Array.isArray(message) && message.constructor !== Uint8Array)
|
|
298
|
+
message = message.toString();
|
|
299
|
+
// else, assume byte array already
|
|
300
|
+
|
|
301
|
+
var m = crypt.bytesToWords(message),
|
|
302
|
+
l = message.length * 8,
|
|
303
|
+
a = 1732584193,
|
|
304
|
+
b = -271733879,
|
|
305
|
+
c = -1732584194,
|
|
306
|
+
d = 271733878;
|
|
307
|
+
|
|
308
|
+
// Swap endian
|
|
309
|
+
for (var i = 0; i < m.length; i++) {
|
|
310
|
+
m[i] = ((m[i] << 8) | (m[i] >>> 24)) & 0x00FF00FF |
|
|
311
|
+
((m[i] << 24) | (m[i] >>> 8)) & 0xFF00FF00;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Padding
|
|
315
|
+
m[l >>> 5] |= 0x80 << (l % 32);
|
|
316
|
+
m[(((l + 64) >>> 9) << 4) + 14] = l;
|
|
317
|
+
|
|
318
|
+
// Method shortcuts
|
|
319
|
+
var FF = md5._ff,
|
|
320
|
+
GG = md5._gg,
|
|
321
|
+
HH = md5._hh,
|
|
322
|
+
II = md5._ii;
|
|
323
|
+
|
|
324
|
+
for (var i = 0; i < m.length; i += 16) {
|
|
325
|
+
|
|
326
|
+
var aa = a,
|
|
327
|
+
bb = b,
|
|
328
|
+
cc = c,
|
|
329
|
+
dd = d;
|
|
330
|
+
|
|
331
|
+
a = FF(a, b, c, d, m[i+ 0], 7, -680876936);
|
|
332
|
+
d = FF(d, a, b, c, m[i+ 1], 12, -389564586);
|
|
333
|
+
c = FF(c, d, a, b, m[i+ 2], 17, 606105819);
|
|
334
|
+
b = FF(b, c, d, a, m[i+ 3], 22, -1044525330);
|
|
335
|
+
a = FF(a, b, c, d, m[i+ 4], 7, -176418897);
|
|
336
|
+
d = FF(d, a, b, c, m[i+ 5], 12, 1200080426);
|
|
337
|
+
c = FF(c, d, a, b, m[i+ 6], 17, -1473231341);
|
|
338
|
+
b = FF(b, c, d, a, m[i+ 7], 22, -45705983);
|
|
339
|
+
a = FF(a, b, c, d, m[i+ 8], 7, 1770035416);
|
|
340
|
+
d = FF(d, a, b, c, m[i+ 9], 12, -1958414417);
|
|
341
|
+
c = FF(c, d, a, b, m[i+10], 17, -42063);
|
|
342
|
+
b = FF(b, c, d, a, m[i+11], 22, -1990404162);
|
|
343
|
+
a = FF(a, b, c, d, m[i+12], 7, 1804603682);
|
|
344
|
+
d = FF(d, a, b, c, m[i+13], 12, -40341101);
|
|
345
|
+
c = FF(c, d, a, b, m[i+14], 17, -1502002290);
|
|
346
|
+
b = FF(b, c, d, a, m[i+15], 22, 1236535329);
|
|
347
|
+
|
|
348
|
+
a = GG(a, b, c, d, m[i+ 1], 5, -165796510);
|
|
349
|
+
d = GG(d, a, b, c, m[i+ 6], 9, -1069501632);
|
|
350
|
+
c = GG(c, d, a, b, m[i+11], 14, 643717713);
|
|
351
|
+
b = GG(b, c, d, a, m[i+ 0], 20, -373897302);
|
|
352
|
+
a = GG(a, b, c, d, m[i+ 5], 5, -701558691);
|
|
353
|
+
d = GG(d, a, b, c, m[i+10], 9, 38016083);
|
|
354
|
+
c = GG(c, d, a, b, m[i+15], 14, -660478335);
|
|
355
|
+
b = GG(b, c, d, a, m[i+ 4], 20, -405537848);
|
|
356
|
+
a = GG(a, b, c, d, m[i+ 9], 5, 568446438);
|
|
357
|
+
d = GG(d, a, b, c, m[i+14], 9, -1019803690);
|
|
358
|
+
c = GG(c, d, a, b, m[i+ 3], 14, -187363961);
|
|
359
|
+
b = GG(b, c, d, a, m[i+ 8], 20, 1163531501);
|
|
360
|
+
a = GG(a, b, c, d, m[i+13], 5, -1444681467);
|
|
361
|
+
d = GG(d, a, b, c, m[i+ 2], 9, -51403784);
|
|
362
|
+
c = GG(c, d, a, b, m[i+ 7], 14, 1735328473);
|
|
363
|
+
b = GG(b, c, d, a, m[i+12], 20, -1926607734);
|
|
364
|
+
|
|
365
|
+
a = HH(a, b, c, d, m[i+ 5], 4, -378558);
|
|
366
|
+
d = HH(d, a, b, c, m[i+ 8], 11, -2022574463);
|
|
367
|
+
c = HH(c, d, a, b, m[i+11], 16, 1839030562);
|
|
368
|
+
b = HH(b, c, d, a, m[i+14], 23, -35309556);
|
|
369
|
+
a = HH(a, b, c, d, m[i+ 1], 4, -1530992060);
|
|
370
|
+
d = HH(d, a, b, c, m[i+ 4], 11, 1272893353);
|
|
371
|
+
c = HH(c, d, a, b, m[i+ 7], 16, -155497632);
|
|
372
|
+
b = HH(b, c, d, a, m[i+10], 23, -1094730640);
|
|
373
|
+
a = HH(a, b, c, d, m[i+13], 4, 681279174);
|
|
374
|
+
d = HH(d, a, b, c, m[i+ 0], 11, -358537222);
|
|
375
|
+
c = HH(c, d, a, b, m[i+ 3], 16, -722521979);
|
|
376
|
+
b = HH(b, c, d, a, m[i+ 6], 23, 76029189);
|
|
377
|
+
a = HH(a, b, c, d, m[i+ 9], 4, -640364487);
|
|
378
|
+
d = HH(d, a, b, c, m[i+12], 11, -421815835);
|
|
379
|
+
c = HH(c, d, a, b, m[i+15], 16, 530742520);
|
|
380
|
+
b = HH(b, c, d, a, m[i+ 2], 23, -995338651);
|
|
381
|
+
|
|
382
|
+
a = II(a, b, c, d, m[i+ 0], 6, -198630844);
|
|
383
|
+
d = II(d, a, b, c, m[i+ 7], 10, 1126891415);
|
|
384
|
+
c = II(c, d, a, b, m[i+14], 15, -1416354905);
|
|
385
|
+
b = II(b, c, d, a, m[i+ 5], 21, -57434055);
|
|
386
|
+
a = II(a, b, c, d, m[i+12], 6, 1700485571);
|
|
387
|
+
d = II(d, a, b, c, m[i+ 3], 10, -1894986606);
|
|
388
|
+
c = II(c, d, a, b, m[i+10], 15, -1051523);
|
|
389
|
+
b = II(b, c, d, a, m[i+ 1], 21, -2054922799);
|
|
390
|
+
a = II(a, b, c, d, m[i+ 8], 6, 1873313359);
|
|
391
|
+
d = II(d, a, b, c, m[i+15], 10, -30611744);
|
|
392
|
+
c = II(c, d, a, b, m[i+ 6], 15, -1560198380);
|
|
393
|
+
b = II(b, c, d, a, m[i+13], 21, 1309151649);
|
|
394
|
+
a = II(a, b, c, d, m[i+ 4], 6, -145523070);
|
|
395
|
+
d = II(d, a, b, c, m[i+11], 10, -1120210379);
|
|
396
|
+
c = II(c, d, a, b, m[i+ 2], 15, 718787259);
|
|
397
|
+
b = II(b, c, d, a, m[i+ 9], 21, -343485551);
|
|
398
|
+
|
|
399
|
+
a = (a + aa) >>> 0;
|
|
400
|
+
b = (b + bb) >>> 0;
|
|
401
|
+
c = (c + cc) >>> 0;
|
|
402
|
+
d = (d + dd) >>> 0;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return crypt.endian([a, b, c, d]);
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
// Auxiliary functions
|
|
409
|
+
md5._ff = function (a, b, c, d, x, s, t) {
|
|
410
|
+
var n = a + (b & c | ~b & d) + (x >>> 0) + t;
|
|
411
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
|
412
|
+
};
|
|
413
|
+
md5._gg = function (a, b, c, d, x, s, t) {
|
|
414
|
+
var n = a + (b & d | c & ~d) + (x >>> 0) + t;
|
|
415
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
|
416
|
+
};
|
|
417
|
+
md5._hh = function (a, b, c, d, x, s, t) {
|
|
418
|
+
var n = a + (b ^ c ^ d) + (x >>> 0) + t;
|
|
419
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
|
420
|
+
};
|
|
421
|
+
md5._ii = function (a, b, c, d, x, s, t) {
|
|
422
|
+
var n = a + (c ^ (b | ~d)) + (x >>> 0) + t;
|
|
423
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
// Package private blocksize
|
|
427
|
+
md5._blocksize = 16;
|
|
428
|
+
md5._digestsize = 16;
|
|
429
|
+
|
|
430
|
+
md5$1.exports = function (message, options) {
|
|
431
|
+
if (message === undefined || message === null)
|
|
432
|
+
throw new Error('Illegal argument ' + message);
|
|
433
|
+
|
|
434
|
+
var digestbytes = crypt.wordsToBytes(md5(message, options));
|
|
435
|
+
return options && options.asBytes ? digestbytes :
|
|
436
|
+
options && options.asString ? bin.bytesToString(digestbytes) :
|
|
437
|
+
crypt.bytesToHex(digestbytes);
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
})();
|
|
441
|
+
|
|
442
|
+
var md5Exports = md5$1.exports;
|
|
443
|
+
var md5 = /*@__PURE__*/getDefaultExportFromCjs(md5Exports);
|
|
444
|
+
|
|
118
445
|
class SignGenerator {
|
|
119
446
|
constructor(config) {
|
|
120
447
|
this.config = {
|
|
@@ -200,129 +527,9 @@ class SignGenerator {
|
|
|
200
527
|
return signString.toLowerCase();
|
|
201
528
|
}
|
|
202
529
|
hash(str) {
|
|
203
|
-
//
|
|
530
|
+
// 使用第三方md5库生成MD5哈希,支持浏览器和Node.js环境
|
|
204
531
|
const input = this.config.salt ? this.config.salt + str : str;
|
|
205
|
-
return
|
|
206
|
-
}
|
|
207
|
-
// 纯JavaScript MD5实现
|
|
208
|
-
md5(message) {
|
|
209
|
-
// MD5常量
|
|
210
|
-
const K = [
|
|
211
|
-
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
|
|
212
|
-
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
|
213
|
-
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
|
214
|
-
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
|
215
|
-
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
|
|
216
|
-
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
|
|
217
|
-
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
|
218
|
-
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
|
219
|
-
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
|
|
220
|
-
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
|
221
|
-
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
|
|
222
|
-
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
|
223
|
-
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
|
|
224
|
-
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
|
225
|
-
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
|
226
|
-
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
|
|
227
|
-
];
|
|
228
|
-
// 左旋转函数
|
|
229
|
-
const leftRotate = (x, c) => {
|
|
230
|
-
return (x << c) | (x >>> (32 - c));
|
|
231
|
-
};
|
|
232
|
-
// 将字符串转换为字节数组
|
|
233
|
-
const utf8Encode = (str) => {
|
|
234
|
-
const bytes = [];
|
|
235
|
-
for (let i = 0; i < str.length; i++) {
|
|
236
|
-
const charCode = str.charCodeAt(i);
|
|
237
|
-
if (charCode < 128) {
|
|
238
|
-
bytes.push(charCode);
|
|
239
|
-
}
|
|
240
|
-
else if (charCode < 2048) {
|
|
241
|
-
bytes.push((charCode >> 6) | 192);
|
|
242
|
-
bytes.push((charCode & 63) | 128);
|
|
243
|
-
}
|
|
244
|
-
else if (charCode < 65536) {
|
|
245
|
-
bytes.push((charCode >> 12) | 224);
|
|
246
|
-
bytes.push(((charCode >> 6) & 63) | 128);
|
|
247
|
-
bytes.push((charCode & 63) | 128);
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
bytes.push((charCode >> 18) | 240);
|
|
251
|
-
bytes.push(((charCode >> 12) & 63) | 128);
|
|
252
|
-
bytes.push(((charCode >> 6) & 63) | 128);
|
|
253
|
-
bytes.push((charCode & 63) | 128);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return bytes;
|
|
257
|
-
};
|
|
258
|
-
// 初始化变量
|
|
259
|
-
let a0 = 0x67452301;
|
|
260
|
-
let b0 = 0xefcdab89;
|
|
261
|
-
let c0 = 0x98badcfe;
|
|
262
|
-
let d0 = 0x10325476;
|
|
263
|
-
// 处理输入
|
|
264
|
-
const bytes = utf8Encode(message);
|
|
265
|
-
const originalLength = bytes.length * 8;
|
|
266
|
-
// 添加填充
|
|
267
|
-
bytes.push(0x80);
|
|
268
|
-
while ((bytes.length * 8) % 512 !== 448) {
|
|
269
|
-
bytes.push(0x00);
|
|
270
|
-
}
|
|
271
|
-
// 添加长度
|
|
272
|
-
for (let i = 0; i < 8; i++) {
|
|
273
|
-
bytes.push((originalLength >>> (i * 8)) & 0xff);
|
|
274
|
-
}
|
|
275
|
-
// 处理512位块
|
|
276
|
-
for (let i = 0; i < bytes.length; i += 64) {
|
|
277
|
-
const w = [];
|
|
278
|
-
for (let j = 0; j < 16; j++) {
|
|
279
|
-
w[j] = ((bytes[i + j * 4] << 24) |
|
|
280
|
-
(bytes[i + j * 4 + 1] << 16) |
|
|
281
|
-
(bytes[i + j * 4 + 2] << 8) |
|
|
282
|
-
bytes[i + j * 4 + 3]);
|
|
283
|
-
}
|
|
284
|
-
let a = a0;
|
|
285
|
-
let b = b0;
|
|
286
|
-
let c = c0;
|
|
287
|
-
let d = d0;
|
|
288
|
-
for (let j = 0; j < 64; j++) {
|
|
289
|
-
let f;
|
|
290
|
-
let g;
|
|
291
|
-
if (j < 16) {
|
|
292
|
-
f = (b & c) | (~b & d);
|
|
293
|
-
g = j;
|
|
294
|
-
}
|
|
295
|
-
else if (j < 32) {
|
|
296
|
-
f = (d & b) | (~d & c);
|
|
297
|
-
g = (5 * j + 1) % 16;
|
|
298
|
-
}
|
|
299
|
-
else if (j < 48) {
|
|
300
|
-
f = b ^ c ^ d;
|
|
301
|
-
g = (3 * j + 5) % 16;
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
f = c ^ (b | ~d);
|
|
305
|
-
g = (7 * j) % 16;
|
|
306
|
-
}
|
|
307
|
-
const temp = d;
|
|
308
|
-
d = c;
|
|
309
|
-
c = b;
|
|
310
|
-
b = b + leftRotate((a + f + K[j] + w[g]), [7, 12, 17, 22][j / 16 | 0]);
|
|
311
|
-
a = temp;
|
|
312
|
-
}
|
|
313
|
-
a0 += a;
|
|
314
|
-
b0 += b;
|
|
315
|
-
c0 += c;
|
|
316
|
-
d0 += d;
|
|
317
|
-
}
|
|
318
|
-
// 将结果转换为十六进制字符串
|
|
319
|
-
const toHex = (n) => {
|
|
320
|
-
return ('00000000' + n.toString(16)).slice(-8);
|
|
321
|
-
};
|
|
322
|
-
return (toHex(a0) +
|
|
323
|
-
toHex(b0) +
|
|
324
|
-
toHex(c0) +
|
|
325
|
-
toHex(d0)).toLowerCase();
|
|
532
|
+
return md5(input);
|
|
326
533
|
}
|
|
327
534
|
getSignHeaderName() {
|
|
328
535
|
return this.config.signHeaderName;
|
|
@@ -352,7 +559,7 @@ class TokenRefreshManager {
|
|
|
352
559
|
if (!updatedConfig.headers) {
|
|
353
560
|
updatedConfig.headers = {};
|
|
354
561
|
}
|
|
355
|
-
updatedConfig.headers.Authorization =
|
|
562
|
+
updatedConfig.headers.Authorization = `${token}`;
|
|
356
563
|
resolve(updatedConfig);
|
|
357
564
|
}
|
|
358
565
|
else {
|
|
@@ -630,7 +837,7 @@ class ApiClient {
|
|
|
630
837
|
if (this.config.tokenRefreshConfig?.getToken) {
|
|
631
838
|
const token = this.config.tokenRefreshConfig.getToken();
|
|
632
839
|
if (token) {
|
|
633
|
-
config.headers.Authorization =
|
|
840
|
+
config.headers.Authorization = `${token}`;
|
|
634
841
|
}
|
|
635
842
|
}
|
|
636
843
|
const requestLog = {
|
|
@@ -668,6 +875,12 @@ class ApiClient {
|
|
|
668
875
|
error instanceof Error && 'response' in error &&
|
|
669
876
|
error.response?.status &&
|
|
670
877
|
this.tokenRefreshManager.isTokenExpired(error.response.status)) {
|
|
878
|
+
// 检查是否是auth相关接口,如果是则跳过token刷新
|
|
879
|
+
const config = error.config;
|
|
880
|
+
const url = config?.url || '';
|
|
881
|
+
if (url.includes('/auth/')) {
|
|
882
|
+
return Promise.reject(errorHandlerManager.handleError(error));
|
|
883
|
+
}
|
|
671
884
|
try {
|
|
672
885
|
const newConfig = await this.tokenRefreshManager.handleTokenExpired(this.axiosInstance, error.config);
|
|
673
886
|
return this.axiosInstance.request(newConfig);
|
|
@@ -761,7 +974,12 @@ class ApiClient {
|
|
|
761
974
|
async function login(params) {
|
|
762
975
|
const client = getApiClient();
|
|
763
976
|
const response = await client.post('/auth/v1/login', params);
|
|
764
|
-
|
|
977
|
+
const loginResult = response.data;
|
|
978
|
+
// 保存token
|
|
979
|
+
if (loginResult.token) {
|
|
980
|
+
saveToken(loginResult.token);
|
|
981
|
+
}
|
|
982
|
+
return loginResult;
|
|
765
983
|
}
|
|
766
984
|
async function refreshToken() {
|
|
767
985
|
const client = getApiClient();
|
|
@@ -1106,6 +1324,15 @@ function getApiClient() {
|
|
|
1106
1324
|
}
|
|
1107
1325
|
return apiClientInstance;
|
|
1108
1326
|
}
|
|
1327
|
+
// 保存token的方法
|
|
1328
|
+
function saveToken(token) {
|
|
1329
|
+
if (!apiClientInstance) {
|
|
1330
|
+
throw new Error('ApiClient has not been initialized. Call init first.');
|
|
1331
|
+
}
|
|
1332
|
+
if (apiClientInstance['config']?.tokenRefreshConfig?.setToken) {
|
|
1333
|
+
apiClientInstance['config'].tokenRefreshConfig.setToken(token);
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1109
1336
|
function destroy() {
|
|
1110
1337
|
if (apiClientInstance) {
|
|
1111
1338
|
apiClientInstance.cancelAllRequests();
|
|
@@ -1113,5 +1340,5 @@ function destroy() {
|
|
|
1113
1340
|
}
|
|
1114
1341
|
}
|
|
1115
1342
|
|
|
1116
|
-
export { ApiClient, ErrorHandlerManager, SignGenerator, TokenRefreshManager, index$1 as apiV1, index as apiV2, destroy, errorHandlerManager, getApiClient, init, logger, updateConfig };
|
|
1343
|
+
export { ApiClient, ErrorHandlerManager, SignGenerator, TokenRefreshManager, index$1 as apiV1, index as apiV2, destroy, errorHandlerManager, getApiClient, init, logger, saveToken, updateConfig };
|
|
1117
1344
|
//# sourceMappingURL=index.mjs.map
|