dfws-ve-taro-request 0.0.1 → 0.0.3
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.esm.js +33 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +33 -11
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +33 -11
- package/dist/index.umd.js.map +1 -1
- package/package.json +5 -5
- package/readme.md +1 -1
- package/src/config/index.ts +3 -0
- package/src/index.ts +10 -3
- package/src/utils/instance.ts +17 -6
- package/src/utils/request.ts +5 -5
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "dfws-ve-taro-request",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.3",
|
4
4
|
"description": "东方网升最佳东方小程序Taro公共请求方法",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"browser": "dist/index.umd.js",
|
@@ -43,15 +43,15 @@
|
|
43
43
|
"jest": "^27.4.7",
|
44
44
|
"rollup": "2.63.0",
|
45
45
|
"rollup-plugin-babel": "^4.4.0",
|
46
|
+
"rollup-plugin-copy": "^3.3.0",
|
46
47
|
"rollup-plugin-replace": "^2.2.0",
|
47
48
|
"rollup-plugin-terser": "^7.0.2",
|
48
|
-
"rollup-plugin-copy": "^3.3.0",
|
49
49
|
"rollup-plugin-typescript2": "^0.27.1"
|
50
50
|
},
|
51
51
|
"dependencies": {
|
52
|
-
"js-cookie": "^3.0.5",
|
53
|
-
"typescript": "^5.6.3",
|
54
52
|
"dfws-channel": "0.0.8",
|
55
|
-
|
53
|
+
"dfws-crypto": "^1.0.2",
|
54
|
+
"js-cookie": "^3.0.5",
|
55
|
+
"typescript": "^5.6.3"
|
56
56
|
}
|
57
57
|
}
|
package/readme.md
CHANGED
package/src/config/index.ts
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
// 接口加密密钥
|
2
2
|
export const secretkey:string = "dz15z9z2z15z11z8zf";
|
3
3
|
|
4
|
+
// 图片验证码加密密钥
|
5
|
+
export const captchaKey = "3dz2dz2bzcz8z30z2hz2nz3dz2nz2mz2oz2n";
|
6
|
+
|
4
7
|
// 项目渠道配置:管理后台-138美业人才-系统设置-渠道管理
|
5
8
|
export const channel:IChannel = { "project": "VE", "origin": "C", "platform": "XCX", "device": "ZJDF", "version": "1.0.0" };
|
package/src/index.ts
CHANGED
@@ -2,9 +2,10 @@
|
|
2
2
|
import getPublicChannel from "dfws-channel/dist/taro"
|
3
3
|
import { channel } from './config'
|
4
4
|
import request from "./utils/request";
|
5
|
+
import { decryptByDES, encryptByDES, encryptBySso } from "./utils/instance";
|
5
6
|
|
6
7
|
export default {
|
7
|
-
request: (taro: any, projectChannel: IChannel = {}, url: string, data: any, method: string, headers: any = {}) => {
|
8
|
+
request: (taro: any, projectChannel: IChannel = {}, url: string, data: any, method: string, headers: any = {}, debug: boolean = false) => {
|
8
9
|
/**
|
9
10
|
* 东方网升项目公共 header
|
10
11
|
* @param {object} dfws_params
|
@@ -19,6 +20,12 @@ export default {
|
|
19
20
|
version: channel.version,
|
20
21
|
params: JSON.stringify(dfws_header.queryChannels()),
|
21
22
|
...headers
|
22
|
-
}, taro)
|
23
|
-
}
|
23
|
+
}, taro, debug)
|
24
|
+
},
|
25
|
+
// 接口解密
|
26
|
+
decryptByDES,
|
27
|
+
// 接口加密
|
28
|
+
encryptByDES,
|
29
|
+
// 验证码加密
|
30
|
+
encryptBySso
|
24
31
|
}
|
package/src/utils/instance.ts
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
import dfwsCrypto from "dfws-crypto";
|
2
|
-
import { secretkey } from "../config";
|
2
|
+
import { secretkey, captchaKey } from "../config";
|
3
3
|
|
4
4
|
// 是否进行接口解密
|
5
5
|
export const isEncoding = (url = '') => {
|
6
6
|
return url.includes('/sso/v1/') || url.includes('/resume/v1/');
|
7
7
|
};
|
8
8
|
// 加密
|
9
|
-
export const encryptByDES = (params: object | string) => {
|
10
|
-
console.log(`请求参数:`, params)
|
9
|
+
export const encryptByDES = (params: object | string, debug: boolean = false) => {
|
10
|
+
debug && console.log(`请求参数:`, params)
|
11
11
|
return encodeURIComponent(
|
12
12
|
dfwsCrypto.encryptByDES(JSON.stringify(params), secretkey)
|
13
13
|
);
|
14
14
|
};
|
15
15
|
//解密
|
16
|
-
export const decryptByDES = (params: string) => {
|
16
|
+
export const decryptByDES = (params: string, debug: boolean = false) => {
|
17
17
|
const data = JSON.parse(dfwsCrypto.decryptByDES(params, secretkey));
|
18
|
-
console.log(`获取内容:`, data)
|
18
|
+
debug && console.log(`获取内容:`, data)
|
19
19
|
return data
|
20
20
|
};
|
21
|
-
|
21
|
+
// 对象转URL字符串
|
22
22
|
export const objectToQueryString = (obj: object) => {
|
23
23
|
return Object.keys(obj)
|
24
24
|
.map(key => {
|
@@ -29,9 +29,20 @@ export const objectToQueryString = (obj: object) => {
|
|
29
29
|
.join('&');
|
30
30
|
}
|
31
31
|
|
32
|
+
//短信/邮箱验证码加密
|
33
|
+
export const encryptBySso = (value: string) => {
|
34
|
+
const key = Date.parse(new Date().toString())
|
35
|
+
const sign = dfwsCrypto.encryptByDES(`${dfwsCrypto.decrypto(captchaKey, 123, 25)}${value}${key}`, secretkey)
|
36
|
+
return {
|
37
|
+
check_sign: sign,
|
38
|
+
check_key: key,
|
39
|
+
}
|
40
|
+
};
|
41
|
+
|
32
42
|
export default {
|
33
43
|
isEncoding,
|
34
44
|
encryptByDES,
|
35
45
|
decryptByDES,
|
46
|
+
encryptBySso,
|
36
47
|
objectToQueryString
|
37
48
|
};
|
package/src/utils/request.ts
CHANGED
@@ -85,16 +85,16 @@ const checkStatus = (response: IResponse, options: IOptions, Taro: any) => {
|
|
85
85
|
}
|
86
86
|
};
|
87
87
|
|
88
|
-
export default (url: string, data: object, method: any = 'get', header: IHeaders, Taro: any) => {
|
89
|
-
|
88
|
+
export default (url: string, data: object, method: any = 'get', header: IHeaders, Taro: any, debug: boolean = false) => {
|
89
|
+
|
90
90
|
const isEncode = isEncoding(url) // 判断是否加密
|
91
91
|
const isMethod = method.toLocaleLowerCase() === 'get' && Object.keys(data).length // 请求方式get而且加密处理
|
92
92
|
if (isMethod) {
|
93
|
-
url = "".concat(url, "?").concat(isEncode ? encryptByDES(objectToQueryString(data)) : objectToQueryString(data));
|
93
|
+
url = "".concat(url, "?").concat(isEncode ? encryptByDES(objectToQueryString(data), debug) : objectToQueryString(data));
|
94
94
|
}
|
95
95
|
return Taro.request({
|
96
96
|
url: url,
|
97
|
-
data: isEncode ? encryptByDES(data) : data,
|
97
|
+
data: isEncode ? encryptByDES(data, debug) : data,
|
98
98
|
method,
|
99
99
|
timeout: 15000,
|
100
100
|
header: {
|
@@ -107,7 +107,7 @@ export default (url: string, data: object, method: any = 'get', header: IHeaders
|
|
107
107
|
}).then((res: any) => {
|
108
108
|
const response: any = isEncode ? {
|
109
109
|
...res,
|
110
|
-
data: decryptByDES(unescape(res.data))
|
110
|
+
data: decryptByDES(unescape(res.data), debug)
|
111
111
|
} : res;
|
112
112
|
return checkStatus(response, { url, data, method }, Taro);
|
113
113
|
}).catch((err: object) => {
|