resolveApiName.js
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
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
/**
* ROP method → apiName / axios 配置键 / 签名方式
* 与 src/api/request.js 保持一致,供浏览器与 Node 共用
*/
const API_NAME_MAPPING = {
"dj.smartcarlife": "axios",
"dj": "axios",
"scrm": "axios2",
"merchants": "axios3",
"reportExport": "axios4",
"glsx.accounts.biz.common.pictureUpload": "common",
"clue": "axios5",
"dj.businessSchool": "axios6",
"script": "axios7",
"staff": "axios9",
"riskmanage": "axios10",
"strategy": "axios_strategy",
"supervisor": "axios_supervisor",
"oaapproval": "axios_oaapproval",
"taskcenter": "axiosTaskCenter",
};
const SIGN_WAY = {
"dj.smartcarlife": "sha1",
"dj": "sha1",
"scrm": "sha1",
"glsx": "md5",
"glsx.accounts.biz.common.pictureUpload": "md5",
"clue": "sha1",
"script": "sha1",
"staff": "sha1",
"riskmanage": "sha1",
"oaapproval": "sha1",
"taskcenter": "sha1",
};
/**
* 根据 ROP method 解析 apiName
* @param {string} method
* @returns {string}
*/
function resolveApiName(method = "") {
if (!method) {
return "";
}
if (method.includes("dj.api.smartcarlife.sop.strategy")) {
return "strategy";
}
if (method.includes("dj.api.smartcarlife")) {
return "dj";
}
if (method.includes("dj.api.script")) {
return "script";
}
if (method.includes("dj.staff.api")) {
return "staff";
}
if (method.includes("dj.smartcarlife.stock")) {
return "dj.smartcarlife";
}
if (method.includes("risk.manage.api")) {
return "riskmanage";
}
if (method.includes("dj.api.strategy")) {
return "strategy";
}
if (method.includes("dj.api.supervisor")) {
return "supervisor";
}
if (method.includes("dj.pad.api")) {
return "dj";
}
if (method.includes("dj.api.oaapproval")) {
return "oaapproval";
}
if (method.includes("dj.api.taskcenter")) {
return "taskcenter";
}
if (method.includes("merchants.api.open.createMerchantWithPermissions") || method.includes("merchants.api.oaapproval")) {
return "oaapproval";
}
if (method.includes("dj.api.marketing")) {
return "strategy";
}
return method.split(".api")[0];
}
/**
* apiName → baseConfig 中的 axios 块键名
* @param {string} apiName
* @returns {string|undefined}
*/
function getAxiosConfigKey(apiName) {
return API_NAME_MAPPING[apiName];
}
/**
* apiName → 签名算法
* @param {string} apiName
* @returns {string}
*/
function getSignWay(apiName) {
return SIGN_WAY[apiName] || "sha1";
}
module.exports = {
resolveApiName,
getAxiosConfigKey,
getSignWay,
API_NAME_MAPPING,
SIGN_WAY,
};