tools-min-ns 1.5.2
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/README.md +85 -0
- package/esm/array/ArrayUtil.d.ts +109 -0
- package/esm/array/ArrayUtil.js +242 -0
- package/esm/array/TreeUtil.d.ts +151 -0
- package/esm/array/TreeUtil.js +412 -0
- package/esm/base/BaseUtil.d.ts +91 -0
- package/esm/base/BaseUtil.js +148 -0
- package/esm/browser/BrowserUtil.d.ts +57 -0
- package/esm/browser/BrowserUtil.js +337 -0
- package/esm/browser/fingerprint.d.ts +120 -0
- package/esm/browser/fingerprint.js +1469 -0
- package/esm/check/CheckUtil.d.ts +110 -0
- package/esm/check/CheckUtil.js +465 -0
- package/esm/common.d.ts +43 -0
- package/esm/common.js +44 -0
- package/esm/config.d.ts +7 -0
- package/esm/config.js +7 -0
- package/esm/cookie/CookieUtil.d.ts +56 -0
- package/esm/cookie/CookieUtil.js +12 -0
- package/esm/cookie/cookie.d.ts +2 -0
- package/esm/cookie/cookie.js +104 -0
- package/esm/date/DateUtil.d.ts +261 -0
- package/esm/date/DateUtil.js +763 -0
- package/esm/env/EnvUtil.d.ts +27 -0
- package/esm/env/EnvUtil.js +29 -0
- package/esm/env/env.d.ts +41 -0
- package/esm/env/env.js +106 -0
- package/esm/func/FunctionUtil.d.ts +77 -0
- package/esm/func/FunctionUtil.js +215 -0
- package/esm/index.d.ts +19 -0
- package/esm/index.js +19 -0
- package/esm/number/NumberUtil.d.ts +96 -0
- package/esm/number/NumberUtil.js +256 -0
- package/esm/object/ObjectUtil.d.ts +41 -0
- package/esm/object/ObjectUtil.js +158 -0
- package/esm/pwd/PasswordUtil.d.ts +33 -0
- package/esm/pwd/PasswordUtil.js +68 -0
- package/esm/pwd/crypto.d.ts +6 -0
- package/esm/pwd/crypto.js +1824 -0
- package/esm/request/RequestUtil.d.ts +52 -0
- package/esm/request/RequestUtil.js +53 -0
- package/esm/request/jsonp.d.ts +18 -0
- package/esm/request/jsonp.js +73 -0
- package/esm/request/mgop/env.d.ts +7 -0
- package/esm/request/mgop/env.js +15 -0
- package/esm/request/mgop/index.d.ts +3 -0
- package/esm/request/mgop/index.js +276 -0
- package/esm/request/mgop/responseCode.d.ts +20 -0
- package/esm/request/mgop/responseCode.js +37 -0
- package/esm/request/mgop/type.d.ts +34 -0
- package/esm/request/mgop/type.js +1 -0
- package/esm/request/uniRquest/index.d.ts +2 -0
- package/esm/request/uniRquest/index.js +66 -0
- package/esm/request/uniRquest/miniapp/index.d.ts +2 -0
- package/esm/request/uniRquest/miniapp/index.js +29 -0
- package/esm/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
- package/esm/request/uniRquest/miniapp-bytedance/index.js +41 -0
- package/esm/request/uniRquest/types.d.ts +65 -0
- package/esm/request/uniRquest/types.js +36 -0
- package/esm/request/uniRquest/utils.d.ts +9 -0
- package/esm/request/uniRquest/utils.js +69 -0
- package/esm/request/uniRquest/web/index.d.ts +2 -0
- package/esm/request/uniRquest/web/index.js +85 -0
- package/esm/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
- package/esm/request/uniRquest/wechat-miniprogram/index.js +41 -0
- package/esm/request/uniRquest/weex/index.d.ts +14 -0
- package/esm/request/uniRquest/weex/index.js +59 -0
- package/esm/storage/StorageUtil.d.ts +19 -0
- package/esm/storage/StorageUtil.js +75 -0
- package/esm/string/StringUtil.d.ts +392 -0
- package/esm/string/StringUtil.js +556 -0
- package/esm/system/SystemUtil.d.ts +46 -0
- package/esm/system/SystemUtil.js +122 -0
- package/esm/transfer/MapTransferUtil.d.ts +54 -0
- package/esm/transfer/MapTransferUtil.js +160 -0
- package/esm/transfer/TransferUtil.d.ts +98 -0
- package/esm/transfer/TransferUtil.js +323 -0
- package/esm/types.d.ts +25 -0
- package/esm/types.js +1 -0
- package/esm/url/UrlUtil.d.ts +30 -0
- package/esm/url/UrlUtil.js +85 -0
- package/lib/array/ArrayUtil.d.ts +109 -0
- package/lib/array/ArrayUtil.js +252 -0
- package/lib/array/TreeUtil.d.ts +151 -0
- package/lib/array/TreeUtil.js +422 -0
- package/lib/base/BaseUtil.d.ts +91 -0
- package/lib/base/BaseUtil.js +153 -0
- package/lib/browser/BrowserUtil.d.ts +57 -0
- package/lib/browser/BrowserUtil.js +347 -0
- package/lib/browser/fingerprint.d.ts +120 -0
- package/lib/browser/fingerprint.js +1500 -0
- package/lib/check/CheckUtil.d.ts +110 -0
- package/lib/check/CheckUtil.js +475 -0
- package/lib/common.d.ts +43 -0
- package/lib/common.js +50 -0
- package/lib/config.d.ts +7 -0
- package/lib/config.js +12 -0
- package/lib/cookie/CookieUtil.d.ts +56 -0
- package/lib/cookie/CookieUtil.js +22 -0
- package/lib/cookie/cookie.d.ts +2 -0
- package/lib/cookie/cookie.js +109 -0
- package/lib/date/DateUtil.d.ts +261 -0
- package/lib/date/DateUtil.js +773 -0
- package/lib/env/EnvUtil.d.ts +27 -0
- package/lib/env/EnvUtil.js +39 -0
- package/lib/env/env.d.ts +41 -0
- package/lib/env/env.js +112 -0
- package/lib/func/FunctionUtil.d.ts +77 -0
- package/lib/func/FunctionUtil.js +225 -0
- package/lib/index.d.ts +19 -0
- package/lib/index.js +144 -0
- package/lib/number/NumberUtil.d.ts +96 -0
- package/lib/number/NumberUtil.js +266 -0
- package/lib/object/ObjectUtil.d.ts +41 -0
- package/lib/object/ObjectUtil.js +168 -0
- package/lib/pwd/PasswordUtil.d.ts +33 -0
- package/lib/pwd/PasswordUtil.js +78 -0
- package/lib/pwd/crypto.d.ts +6 -0
- package/lib/pwd/crypto.js +1829 -0
- package/lib/request/RequestUtil.d.ts +52 -0
- package/lib/request/RequestUtil.js +94 -0
- package/lib/request/jsonp.d.ts +18 -0
- package/lib/request/jsonp.js +80 -0
- package/lib/request/mgop/env.d.ts +7 -0
- package/lib/request/mgop/env.js +21 -0
- package/lib/request/mgop/index.d.ts +3 -0
- package/lib/request/mgop/index.js +289 -0
- package/lib/request/mgop/responseCode.d.ts +20 -0
- package/lib/request/mgop/responseCode.js +42 -0
- package/lib/request/mgop/type.d.ts +34 -0
- package/lib/request/mgop/type.js +5 -0
- package/lib/request/uniRquest/index.d.ts +2 -0
- package/lib/request/uniRquest/index.js +77 -0
- package/lib/request/uniRquest/miniapp/index.d.ts +2 -0
- package/lib/request/uniRquest/miniapp/index.js +35 -0
- package/lib/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
- package/lib/request/uniRquest/miniapp-bytedance/index.js +47 -0
- package/lib/request/uniRquest/types.d.ts +65 -0
- package/lib/request/uniRquest/types.js +42 -0
- package/lib/request/uniRquest/utils.d.ts +9 -0
- package/lib/request/uniRquest/utils.js +83 -0
- package/lib/request/uniRquest/web/index.d.ts +2 -0
- package/lib/request/uniRquest/web/index.js +91 -0
- package/lib/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
- package/lib/request/uniRquest/wechat-miniprogram/index.js +47 -0
- package/lib/request/uniRquest/weex/index.d.ts +14 -0
- package/lib/request/uniRquest/weex/index.js +65 -0
- package/lib/storage/StorageUtil.d.ts +19 -0
- package/lib/storage/StorageUtil.js +85 -0
- package/lib/string/StringUtil.d.ts +392 -0
- package/lib/string/StringUtil.js +566 -0
- package/lib/system/SystemUtil.d.ts +46 -0
- package/lib/system/SystemUtil.js +132 -0
- package/lib/transfer/MapTransferUtil.d.ts +54 -0
- package/lib/transfer/MapTransferUtil.js +165 -0
- package/lib/transfer/TransferUtil.d.ts +98 -0
- package/lib/transfer/TransferUtil.js +333 -0
- package/lib/types.d.ts +25 -0
- package/lib/types.js +5 -0
- package/lib/url/UrlUtil.d.ts +30 -0
- package/lib/url/UrlUtil.js +95 -0
- package/package.json +56 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 请求工具
|
|
3
|
+
* @description
|
|
4
|
+
* @author nanshen
|
|
5
|
+
* @creat 2023-12-15 10:30:30
|
|
6
|
+
*/
|
|
7
|
+
import mgop, { setDefaultHeader } from './mgop';
|
|
8
|
+
import uniRquestFn from './uniRquest';
|
|
9
|
+
import jsonpFn, { jsonpRquest as jsonpRquestFn } from './jsonp';
|
|
10
|
+
declare namespace RequestUtil {
|
|
11
|
+
/** @name 浙里办请求工具设置默认请求头 */
|
|
12
|
+
const mgopSetDefaultHeader: typeof setDefaultHeader;
|
|
13
|
+
/** @name 浙里办请求工具 */
|
|
14
|
+
const mgopRequest: typeof mgop;
|
|
15
|
+
/**
|
|
16
|
+
* @name 简单发起请求
|
|
17
|
+
* @example
|
|
18
|
+
RequestUtil.uniRquest({
|
|
19
|
+
url: 'https://alibaba.github.io/rax/',
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
//'Content-Type': 'application/x-www-form-urlencoded',
|
|
24
|
+
},
|
|
25
|
+
data: {
|
|
26
|
+
from: 'Rax',
|
|
27
|
+
},
|
|
28
|
+
dataType: 'json'
|
|
29
|
+
}).then(response => {}).catch(error => {});
|
|
30
|
+
*/
|
|
31
|
+
const uniRquest: typeof uniRquestFn;
|
|
32
|
+
/**
|
|
33
|
+
* @name jsonp请求工具
|
|
34
|
+
@example
|
|
35
|
+
RequestUtil.jsonp({
|
|
36
|
+
url: 'https:/xxxx.com?key=1&output=jsonp'
|
|
37
|
+
},
|
|
38
|
+
(error, data)=>{
|
|
39
|
+
//...
|
|
40
|
+
});
|
|
41
|
+
*/
|
|
42
|
+
const jsonp: typeof jsonpFn;
|
|
43
|
+
/**
|
|
44
|
+
* @name jsonpRquest请求工具
|
|
45
|
+
@example
|
|
46
|
+
RequestUtil.jsonpRquest({
|
|
47
|
+
url: 'https:/xxxx.com?key=1&output=jsonp'
|
|
48
|
+
}).then(response => {}).catch(error => {});
|
|
49
|
+
*/
|
|
50
|
+
const jsonpRquest: typeof jsonpRquestFn;
|
|
51
|
+
}
|
|
52
|
+
export default RequestUtil;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
value: v
|
|
23
|
+
});
|
|
24
|
+
} : function (o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = this && this.__importStar || function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = this && this.__importDefault || function (mod) {
|
|
35
|
+
return mod && mod.__esModule ? mod : {
|
|
36
|
+
"default": mod
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", {
|
|
40
|
+
value: true
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* 请求工具
|
|
44
|
+
* @description
|
|
45
|
+
* @author nanshen
|
|
46
|
+
* @creat 2023-12-15 10:30:30
|
|
47
|
+
*/
|
|
48
|
+
var mgop_1 = __importStar(require("./mgop"));
|
|
49
|
+
var uniRquest_1 = __importDefault(require("./uniRquest"));
|
|
50
|
+
var jsonp_1 = __importStar(require("./jsonp"));
|
|
51
|
+
var RequestUtil;
|
|
52
|
+
(function (RequestUtil) {
|
|
53
|
+
/** @name 浙里办请求工具设置默认请求头 */
|
|
54
|
+
RequestUtil.mgopSetDefaultHeader = mgop_1.setDefaultHeader;
|
|
55
|
+
/** @name 浙里办请求工具 */
|
|
56
|
+
RequestUtil.mgopRequest = mgop_1.default;
|
|
57
|
+
/**
|
|
58
|
+
* @name 简单发起请求
|
|
59
|
+
* @example
|
|
60
|
+
RequestUtil.uniRquest({
|
|
61
|
+
url: 'https://alibaba.github.io/rax/',
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: {
|
|
64
|
+
'Content-Type': 'application/json',
|
|
65
|
+
//'Content-Type': 'application/x-www-form-urlencoded',
|
|
66
|
+
},
|
|
67
|
+
data: {
|
|
68
|
+
from: 'Rax',
|
|
69
|
+
},
|
|
70
|
+
dataType: 'json'
|
|
71
|
+
}).then(response => {}).catch(error => {});
|
|
72
|
+
*/
|
|
73
|
+
RequestUtil.uniRquest = uniRquest_1.default;
|
|
74
|
+
/**
|
|
75
|
+
* @name jsonp请求工具
|
|
76
|
+
@example
|
|
77
|
+
RequestUtil.jsonp({
|
|
78
|
+
url: 'https:/xxxx.com?key=1&output=jsonp'
|
|
79
|
+
},
|
|
80
|
+
(error, data)=>{
|
|
81
|
+
//...
|
|
82
|
+
});
|
|
83
|
+
*/
|
|
84
|
+
RequestUtil.jsonp = jsonp_1.default;
|
|
85
|
+
/**
|
|
86
|
+
* @name jsonpRquest请求工具
|
|
87
|
+
@example
|
|
88
|
+
RequestUtil.jsonpRquest({
|
|
89
|
+
url: 'https:/xxxx.com?key=1&output=jsonp'
|
|
90
|
+
}).then(response => {}).catch(error => {});
|
|
91
|
+
*/
|
|
92
|
+
RequestUtil.jsonpRquest = jsonp_1.jsonpRquest;
|
|
93
|
+
})(RequestUtil || (RequestUtil = {}));
|
|
94
|
+
exports.default = RequestUtil;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type CancelFn = () => void;
|
|
2
|
+
type RequestCallback<T> = (error: Error | null, data: T) => void;
|
|
3
|
+
type Options = {
|
|
4
|
+
/** @name 存放防缓存字段的键名 */
|
|
5
|
+
param?: string;
|
|
6
|
+
/** @name 防缓存字段值前缀 */
|
|
7
|
+
prefix?: string;
|
|
8
|
+
/** @name 防缓存字段值完整名称 */
|
|
9
|
+
name?: string;
|
|
10
|
+
/** @name 请求超时时间 */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
};
|
|
13
|
+
type Opts = Options & {
|
|
14
|
+
url: string;
|
|
15
|
+
};
|
|
16
|
+
declare function jsonp<T = any>(opts: Opts, fn: RequestCallback<T>): CancelFn;
|
|
17
|
+
export declare function jsonpRquest<T = any>(opts: Opts): Promise<T>;
|
|
18
|
+
export default jsonp;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
4
|
+
var t = {};
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", {
|
|
12
|
+
value: true
|
|
13
|
+
});
|
|
14
|
+
exports.jsonpRquest = void 0;
|
|
15
|
+
var count = 0;
|
|
16
|
+
function noop() {}
|
|
17
|
+
var jsonpFn = function jsonpFn(url, opts, fn) {
|
|
18
|
+
var _a;
|
|
19
|
+
if ('function' == typeof opts) {
|
|
20
|
+
fn = opts;
|
|
21
|
+
opts = {};
|
|
22
|
+
}
|
|
23
|
+
if (!opts) opts = {};
|
|
24
|
+
var prefix = opts.prefix || '__jp';
|
|
25
|
+
// use the callback name that was passed if one was provided.
|
|
26
|
+
// otherwise generate a unique name by incrementing our counter.
|
|
27
|
+
var id = opts.name || prefix + count++;
|
|
28
|
+
var param = opts.param || 'callback';
|
|
29
|
+
var timeout = null != opts.timeout ? opts.timeout : 60000;
|
|
30
|
+
var enc = encodeURIComponent;
|
|
31
|
+
var target = document.getElementsByTagName('script')[0] || document.head;
|
|
32
|
+
var script;
|
|
33
|
+
var timer;
|
|
34
|
+
if (timeout) {
|
|
35
|
+
timer = setTimeout(function () {
|
|
36
|
+
cleanup();
|
|
37
|
+
if (fn) fn(new Error('Timeout'), undefined);
|
|
38
|
+
}, timeout);
|
|
39
|
+
}
|
|
40
|
+
function cleanup() {
|
|
41
|
+
if (script.parentNode) script.parentNode.removeChild(script);
|
|
42
|
+
window[id] = noop;
|
|
43
|
+
if (timer) clearTimeout(timer);
|
|
44
|
+
}
|
|
45
|
+
function cancel() {
|
|
46
|
+
if (window[id]) {
|
|
47
|
+
cleanup();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
window[id] = function (data) {
|
|
51
|
+
cleanup();
|
|
52
|
+
if (fn) fn(null, data);
|
|
53
|
+
};
|
|
54
|
+
// add qs component
|
|
55
|
+
url += (~url.indexOf('?') ? '&' : '?') + param + '=' + enc(id);
|
|
56
|
+
url = url.replace('?&', '?');
|
|
57
|
+
// create script
|
|
58
|
+
script = document.createElement('script');
|
|
59
|
+
script.src = url;
|
|
60
|
+
(_a = target.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(script, target);
|
|
61
|
+
return cancel;
|
|
62
|
+
};
|
|
63
|
+
function jsonp(opts, fn) {
|
|
64
|
+
var url = opts.url,
|
|
65
|
+
o = __rest(opts, ["url"]);
|
|
66
|
+
return jsonpFn(url, o, fn);
|
|
67
|
+
}
|
|
68
|
+
function jsonpRquest(opts) {
|
|
69
|
+
return new Promise(function (resolve, reject) {
|
|
70
|
+
jsonp(opts, function (err, response) {
|
|
71
|
+
if (err) {
|
|
72
|
+
reject(err);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
resolve(response);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
exports.jsonpRquest = jsonpRquest;
|
|
80
|
+
exports.default = jsonp;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ENV = void 0;
|
|
7
|
+
exports.ENV = {
|
|
8
|
+
online: "https://mapi.zjzwfw.gov.cn",
|
|
9
|
+
pre: "//pre-mapi.zjzwfw.gov.cn",
|
|
10
|
+
daily: "//47.96.150.251:8068"
|
|
11
|
+
};
|
|
12
|
+
var getHostByEnv = function getHostByEnv(env, host) {
|
|
13
|
+
if (host) {
|
|
14
|
+
if (/\/$/.test(host)) {
|
|
15
|
+
host = host.slice(0, -1);
|
|
16
|
+
}
|
|
17
|
+
return host;
|
|
18
|
+
}
|
|
19
|
+
return exports.ENV[env] || exports.ENV.online;
|
|
20
|
+
};
|
|
21
|
+
exports.default = getHostByEnv;
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __importDefault = this && this.__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule ? mod : {
|
|
5
|
+
"default": mod
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
exports.setDefaultHeader = void 0;
|
|
12
|
+
var PasswordUtil_1 = __importDefault(require("../../pwd/PasswordUtil"));
|
|
13
|
+
var CookieUtil_1 = __importDefault(require("../../cookie/CookieUtil"));
|
|
14
|
+
var env_1 = __importDefault(require("./env"));
|
|
15
|
+
var responseCode_1 = __importDefault(require("./responseCode"));
|
|
16
|
+
var env_2 = __importDefault(require("../../env/env"));
|
|
17
|
+
var uniRquest_1 = __importDefault(require("../uniRquest"));
|
|
18
|
+
var isWeb = env_2.default.isWeb;
|
|
19
|
+
var globalInstance = env_2.default.getGlobal();
|
|
20
|
+
var debug = console.debug,
|
|
21
|
+
warning = console.warn;
|
|
22
|
+
var CONST_VARIABLE = {
|
|
23
|
+
TOKEN_KEY: '_mgw_tk',
|
|
24
|
+
APPKEY: 'jl9vupjh+200100201+nytcfro',
|
|
25
|
+
MAX_RETRY_TIMES: 2
|
|
26
|
+
};
|
|
27
|
+
var _NAME_ = 'mgop';
|
|
28
|
+
var RET_MESSAGE = '1000::调用成功';
|
|
29
|
+
var METHOD = 'POST';
|
|
30
|
+
var defaultHeader = {};
|
|
31
|
+
var Mgop = /*#__PURE__*/function () {
|
|
32
|
+
function Mgop(props) {
|
|
33
|
+
this.times = 0;
|
|
34
|
+
this.config = Object.assign({}, {
|
|
35
|
+
env: 'online',
|
|
36
|
+
header: {},
|
|
37
|
+
onSuccess: function onSuccess() {},
|
|
38
|
+
onFail: function onFail() {}
|
|
39
|
+
}, props);
|
|
40
|
+
debug(_NAME_, '@aligov/jssdk-mgop@4.0.1');
|
|
41
|
+
}
|
|
42
|
+
/* 丘比特容器 */
|
|
43
|
+
var _proto = Mgop.prototype;
|
|
44
|
+
_proto.isJupiterJSBridge = function isJupiterJSBridge() {
|
|
45
|
+
var sUserAgent = globalInstance.navigator.userAgent.toLowerCase();
|
|
46
|
+
var bIsJupiter = sUserAgent.indexOf('jupiter') > -1;
|
|
47
|
+
var JupiterJSBridge = globalInstance.JupiterJSBridge;
|
|
48
|
+
if (JupiterJSBridge && bIsJupiter) {
|
|
49
|
+
return true;
|
|
50
|
+
} else {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
_proto.createParam = function createParam(data, ret) {
|
|
55
|
+
if (data === void 0) {
|
|
56
|
+
data = {};
|
|
57
|
+
}
|
|
58
|
+
var _this$config$api = this.config.api,
|
|
59
|
+
api = _this$config$api === void 0 ? '' : _this$config$api;
|
|
60
|
+
return {
|
|
61
|
+
api: api,
|
|
62
|
+
data: data,
|
|
63
|
+
ret: typeof ret === 'string' ? [ret] : ret
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
_proto.createSuccessCb = function createSuccessCb(data) {
|
|
67
|
+
return this.createParam(data, RET_MESSAGE);
|
|
68
|
+
};
|
|
69
|
+
_proto.createFailCb = function createFailCb(ret) {
|
|
70
|
+
return this.createParam({}, ret);
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* 签名处理
|
|
74
|
+
* @param timestamp
|
|
75
|
+
*/
|
|
76
|
+
_proto.processToken = function processToken(timestamp) {
|
|
77
|
+
/* 网关会在第一次http请求时set-cookie,所以第一次请求肯定是失败的 */
|
|
78
|
+
var token = getTokenFromCookie(CONST_VARIABLE.TOKEN_KEY);
|
|
79
|
+
var appkey = this.config.appKey || CONST_VARIABLE.APPKEY;
|
|
80
|
+
var api = this.config.api || '';
|
|
81
|
+
var param = {
|
|
82
|
+
token: token || '',
|
|
83
|
+
ak: appkey,
|
|
84
|
+
api: api,
|
|
85
|
+
ts: timestamp,
|
|
86
|
+
/** 固定传null,遗留git请求逻辑 */
|
|
87
|
+
data: this.config.disableNull ? '' : null
|
|
88
|
+
};
|
|
89
|
+
var stringifyParams = stringifyQS(param, false);
|
|
90
|
+
return PasswordUtil_1.default.str2MD5(stringifyParams, '');
|
|
91
|
+
};
|
|
92
|
+
_proto.processRequestUrl = function processRequestUrl() {
|
|
93
|
+
/* 获取官网的 host */
|
|
94
|
+
var host = (0, env_1.default)(this.config.env, this.config.host);
|
|
95
|
+
var timestamp = getTimeStamp();
|
|
96
|
+
var sign = this.processToken(timestamp);
|
|
97
|
+
var param = {
|
|
98
|
+
ak: this.config.appKey || CONST_VARIABLE.APPKEY,
|
|
99
|
+
api: this.config.api,
|
|
100
|
+
ts: timestamp,
|
|
101
|
+
sign: sign,
|
|
102
|
+
/** 固定传null,遗留git请求逻辑 */
|
|
103
|
+
data: this.config.disableNull ? '' : null
|
|
104
|
+
};
|
|
105
|
+
var query = '' + stringifyQS(param);
|
|
106
|
+
return {
|
|
107
|
+
url: host + '/h5/mgop?' + query,
|
|
108
|
+
query: query
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* 判断是成功还是失败
|
|
113
|
+
* 成功,调用createSuccessCb
|
|
114
|
+
* 失败,调用createFailCb
|
|
115
|
+
*/
|
|
116
|
+
_proto.processResponseResult = function processResponseResult(response) {
|
|
117
|
+
if (response === void 0) {
|
|
118
|
+
response = {};
|
|
119
|
+
}
|
|
120
|
+
var formatCode = Number(response.rs);
|
|
121
|
+
switch (formatCode) {
|
|
122
|
+
case responseCode_1.default.ResultSuccess:
|
|
123
|
+
return this.createSuccessCb(response.data || {});
|
|
124
|
+
case responseCode_1.default.FAIL_SYS_TOKEN_EMPTY:
|
|
125
|
+
debug(_NAME_, responseCode_1.default.FAIL_SYS_TOKEN_EMPTY, '令牌为空,重试');
|
|
126
|
+
if (this.times < CONST_VARIABLE.MAX_RETRY_TIMES) {
|
|
127
|
+
this.times++;
|
|
128
|
+
return this.processRequest();
|
|
129
|
+
}
|
|
130
|
+
debug(_NAME_, responseCode_1.default.FAIL_SYS_TOKEN_EMPTY, '令牌为空,且超过最大重试次数');
|
|
131
|
+
return '';
|
|
132
|
+
default:
|
|
133
|
+
warning(_NAME_, 'response fail', formatCode);
|
|
134
|
+
throw this.createFailCb(response.ret);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
_proto.processRequest = function processRequest() {
|
|
138
|
+
var _this = this;
|
|
139
|
+
var _this$processRequestU = this.processRequestUrl(),
|
|
140
|
+
url = _this$processRequestU.url,
|
|
141
|
+
query = _this$processRequestU.query;
|
|
142
|
+
/* 合并 defaultHeader 和 传入的header */
|
|
143
|
+
var headers = defaultHeader;
|
|
144
|
+
Object.assign(headers, this.config.header, {
|
|
145
|
+
'Content-Type': 'application/json'
|
|
146
|
+
});
|
|
147
|
+
var _this$config$data = this.config.data,
|
|
148
|
+
data = _this$config$data === void 0 ? {} : _this$config$data;
|
|
149
|
+
/* 判断h5是否在小程序容器内,且AlipayMiniAppCall已经存在 */
|
|
150
|
+
var AlipayMiniAppCall = globalInstance.AlipayMiniAppCall;
|
|
151
|
+
if (isWeb && isAlipayMini() && AlipayMiniAppCall) {
|
|
152
|
+
var host = (0, env_1.default)(this.config.env, this.config.host);
|
|
153
|
+
return AlipayMiniAppCall('mgop', {
|
|
154
|
+
host: host + '/h5/mgop',
|
|
155
|
+
method: METHOD,
|
|
156
|
+
query: query,
|
|
157
|
+
headers: headers,
|
|
158
|
+
data: data
|
|
159
|
+
}).then(function (resp) {
|
|
160
|
+
return _this.processResponse(resp);
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
/** 其余case:小程序、非丘比特容器h5 */
|
|
164
|
+
return (0, uniRquest_1.default)({
|
|
165
|
+
method: METHOD,
|
|
166
|
+
url: url,
|
|
167
|
+
headers: headers,
|
|
168
|
+
data: data
|
|
169
|
+
}).then(function (resp) {
|
|
170
|
+
return _this.processResponse(resp);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
/** 处理响应体 */
|
|
175
|
+
_proto.processResponse = function processResponse(resp) {
|
|
176
|
+
var response = resp ? resp.data : null; // 错误处理卡口
|
|
177
|
+
if (!response) {
|
|
178
|
+
throw new Error('返回为空');
|
|
179
|
+
} // 特殊原因,比如ISV修改了xhr的行为,导致response返回为text,则需要转化为json格式
|
|
180
|
+
if (typeof response === 'string') {
|
|
181
|
+
response = JSON.parse(response);
|
|
182
|
+
}
|
|
183
|
+
return this.processResponseResult(response);
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* 1. H5在浏览器中,会通过Ajax方式发起请求。
|
|
187
|
+
* 2. H5在浙里办客户端、警察叔叔中,会通过客户端原生接口发起请求(MgopPlugin)。
|
|
188
|
+
* 3. H5在小程序容器中,会通过管道函数发起请求。
|
|
189
|
+
* 4. 在小程序中,会调用小程序request发起请求。
|
|
190
|
+
*/
|
|
191
|
+
_proto.request = function request() {
|
|
192
|
+
var _this$config = this.config,
|
|
193
|
+
onFail = _this$config.onFail,
|
|
194
|
+
onSuccess = _this$config.onSuccess,
|
|
195
|
+
api = _this$config.api;
|
|
196
|
+
this.processRequest().then(function (e) {
|
|
197
|
+
debug(_NAME_, 'mgop call success', api, e);
|
|
198
|
+
onSuccess(e);
|
|
199
|
+
}).catch(function (e) {
|
|
200
|
+
warning(_NAME_, 'mgop call fail', api, e);
|
|
201
|
+
onFail(e);
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
/** 丘比特容器 egop */
|
|
205
|
+
_proto.egop = function egop() {
|
|
206
|
+
var JupiterJSBridge = globalInstance.JupiterJSBridge;
|
|
207
|
+
var _this$config2 = this.config,
|
|
208
|
+
api = _this$config2.api,
|
|
209
|
+
data = _this$config2.data,
|
|
210
|
+
appKey = _this$config2.appKey,
|
|
211
|
+
onSuccess = _this$config2.onSuccess,
|
|
212
|
+
onFail = _this$config2.onFail,
|
|
213
|
+
_this$config2$header = _this$config2.header,
|
|
214
|
+
header = _this$config2$header === void 0 ? {} : _this$config2$header;
|
|
215
|
+
debug(_NAME_, 'call jupiter with param', api);
|
|
216
|
+
JupiterJSBridge.call('eGovernmentApi', {
|
|
217
|
+
apiName: 'egop',
|
|
218
|
+
params: {
|
|
219
|
+
method: METHOD,
|
|
220
|
+
param: data,
|
|
221
|
+
api: api,
|
|
222
|
+
header: Object.assign(Object.assign(Object.assign({}, defaultHeader), {
|
|
223
|
+
'extra-ak': appKey
|
|
224
|
+
}), header)
|
|
225
|
+
}
|
|
226
|
+
}, function (result) {
|
|
227
|
+
if (typeof result === 'string') {
|
|
228
|
+
result = JSON.parse(result);
|
|
229
|
+
}
|
|
230
|
+
var errorCode = result['errorCode'];
|
|
231
|
+
if (errorCode === '0' || errorCode === 0) {
|
|
232
|
+
onSuccess({
|
|
233
|
+
api: api,
|
|
234
|
+
data: result.data || result.result || {},
|
|
235
|
+
ret: [RET_MESSAGE]
|
|
236
|
+
});
|
|
237
|
+
} else {
|
|
238
|
+
onFail(result);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
return Mgop;
|
|
243
|
+
}();
|
|
244
|
+
function setDefaultHeader(header) {
|
|
245
|
+
defaultHeader = header;
|
|
246
|
+
}
|
|
247
|
+
exports.setDefaultHeader = setDefaultHeader;
|
|
248
|
+
function default_1(params) {
|
|
249
|
+
debug(_NAME_, 'call mgop with param', params);
|
|
250
|
+
var _mgop = new Mgop(params);
|
|
251
|
+
if (isWeb && _mgop.isJupiterJSBridge() && !params.disableEgop) {
|
|
252
|
+
return _mgop.egop();
|
|
253
|
+
}
|
|
254
|
+
return _mgop.request();
|
|
255
|
+
}
|
|
256
|
+
exports.default = default_1;
|
|
257
|
+
function getTimeStamp() {
|
|
258
|
+
return new Date().getTime();
|
|
259
|
+
}
|
|
260
|
+
function getTokenFromCookie(name) {
|
|
261
|
+
var temp = '';
|
|
262
|
+
var tokenKey = CookieUtil_1.default.get(name) || '';
|
|
263
|
+
if (tokenKey) {
|
|
264
|
+
temp = tokenKey.split('_')[0] || '';
|
|
265
|
+
}
|
|
266
|
+
return temp;
|
|
267
|
+
}
|
|
268
|
+
function stringifyQS(qs, isEncode) {
|
|
269
|
+
if (isEncode === void 0) {
|
|
270
|
+
isEncode = true;
|
|
271
|
+
}
|
|
272
|
+
var str = [];
|
|
273
|
+
for (var key in qs) {
|
|
274
|
+
if (isEncode) {
|
|
275
|
+
str.push(key + '=' + encodeURIComponent(qs[key]));
|
|
276
|
+
} else {
|
|
277
|
+
str.push(key + '=' + qs[key]);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return str.join('&');
|
|
281
|
+
}
|
|
282
|
+
function isAlipayMini() {
|
|
283
|
+
var sUserAgent = env_2.default.getInstance().navigator.userAgent.toLowerCase();
|
|
284
|
+
return (sUserAgent.indexOf('miniprogram') > -1 ||
|
|
285
|
+
// 小程序标识
|
|
286
|
+
sUserAgent.indexOf('alipayide') > -1) &&
|
|
287
|
+
// 小程序调试工具标识
|
|
288
|
+
sUserAgent.indexOf('alipay') > -1;
|
|
289
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export default HTTP_RESPONSE_CODE_MAP;
|
|
2
|
+
declare namespace HTTP_RESPONSE_CODE_MAP {
|
|
3
|
+
const ResultSuccess: number;
|
|
4
|
+
const PermissionDeny: number;
|
|
5
|
+
const InvokeExceedLimit: number;
|
|
6
|
+
const OperationTypeMissed: number;
|
|
7
|
+
const RequestDataMissed: number;
|
|
8
|
+
const ValueInvalid: number;
|
|
9
|
+
const RequestParamMissed: number;
|
|
10
|
+
const AppNotExist: number;
|
|
11
|
+
const SubscribeNotExist: number;
|
|
12
|
+
const RequestTimeOut: number;
|
|
13
|
+
const RemoteAccessException: number;
|
|
14
|
+
const CallHsfTimeout: number;
|
|
15
|
+
const UnknowError: number;
|
|
16
|
+
const CorsOptions: number;
|
|
17
|
+
const FAIL_SYS_TOKEN_EMPTY: number;
|
|
18
|
+
const FAIL_SYS_TOKEN_ILLEGAL: number;
|
|
19
|
+
const FAIL_SYS_TOKEN_EXOIRED: number;
|
|
20
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var HTTP_RESPONSE_CODE_MAP = {
|
|
7
|
+
/** success */
|
|
8
|
+
ResultSuccess: 1000,
|
|
9
|
+
// 1001-1999 permission error
|
|
10
|
+
/** reject invoke */
|
|
11
|
+
PermissionDeny: 1001,
|
|
12
|
+
/** invoke exceed limit */
|
|
13
|
+
InvokeExceedLimit: 1002,
|
|
14
|
+
/** 缺少操作类型或者此操作类型不支持 */
|
|
15
|
+
OperationTypeMissed: 3000,
|
|
16
|
+
/** 请求数据为空 */
|
|
17
|
+
RequestDataMissed: 3001,
|
|
18
|
+
/** 数据格式有误 */
|
|
19
|
+
ValueInvalid: 3002,
|
|
20
|
+
/** 请求数据为空 */
|
|
21
|
+
RequestParamMissed: 3004,
|
|
22
|
+
/** App不存在 */
|
|
23
|
+
AppNotExist: 3005,
|
|
24
|
+
/** 订阅关系不存在 */
|
|
25
|
+
SubscribeNotExist: 3006,
|
|
26
|
+
/** 服务请求超时 */
|
|
27
|
+
RequestTimeOut: 4001,
|
|
28
|
+
/** 远程调用业务系统异常 */
|
|
29
|
+
RemoteAccessException: 4002,
|
|
30
|
+
CallHsfTimeout: 4005,
|
|
31
|
+
/** 未知错误 */
|
|
32
|
+
UnknowError: 5000,
|
|
33
|
+
/** cors:跨域预检请求 */
|
|
34
|
+
CorsOptions: 8002,
|
|
35
|
+
/** 空令牌 */
|
|
36
|
+
FAIL_SYS_TOKEN_EMPTY: 9001,
|
|
37
|
+
/** 非法令牌:令牌被篡改,或格式错误 */
|
|
38
|
+
FAIL_SYS_TOKEN_ILLEGAL: 9002,
|
|
39
|
+
/** 令牌过期 */
|
|
40
|
+
FAIL_SYS_TOKEN_EXOIRED: 9003
|
|
41
|
+
};
|
|
42
|
+
exports.default = HTTP_RESPONSE_CODE_MAP;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface IMgopRequestConfig extends IMgopParams {
|
|
2
|
+
}
|
|
3
|
+
export interface IMgopResponseConfig {
|
|
4
|
+
api: string;
|
|
5
|
+
data: any;
|
|
6
|
+
ret: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface IToken {
|
|
9
|
+
appkey: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
token: string;
|
|
12
|
+
data: any;
|
|
13
|
+
}
|
|
14
|
+
export interface ICommonData {
|
|
15
|
+
onSuccess?: (e: any) => void;
|
|
16
|
+
onFail?: (e: any) => void;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}
|
|
19
|
+
export interface IMgopRequestUrlConfig {
|
|
20
|
+
url: string;
|
|
21
|
+
query: any;
|
|
22
|
+
}
|
|
23
|
+
export interface IMgopParams {
|
|
24
|
+
api: string;
|
|
25
|
+
onSuccess?: (e: any) => void;
|
|
26
|
+
onFail?: (e: any) => void;
|
|
27
|
+
data?: any;
|
|
28
|
+
header?: any;
|
|
29
|
+
appKey: string;
|
|
30
|
+
env?: "online" | "pre" | "daily";
|
|
31
|
+
disableEgop?: boolean;
|
|
32
|
+
disableNull?: boolean;
|
|
33
|
+
host?: string;
|
|
34
|
+
}
|