dfws-ve-taro-request 0.0.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dfws-ve-taro-request",
3
- "version": "0.0.2",
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
- "dfws-crypto": "^1.0.2"
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
@@ -54,7 +54,7 @@ App.request = request;
54
54
  | data | 接口参数 | object | {} |
55
55
  | method | 接口请求方式 | string | 'POST|PUT|GET|DELETE' |
56
56
  | headers | 请求公共header参数 | object | null |
57
- | disabled | 是否禁用,默认组件使用 | boolean | null |
57
+ | debug | 是否开启调试模式 | boolean | false |
58
58
 
59
59
 
60
60
 
@@ -2,7 +2,7 @@
2
2
  export const secretkey:string = "dz15z9z2z15z11z8zf";
3
3
 
4
4
  // 图片验证码加密密钥
5
- export const captchaKey = "#DFws082#2312";
5
+ export const captchaKey = "3dz2dz2bzcz8z30z2hz2nz3dz2nz2mz2oz2n";
6
6
 
7
7
  // 项目渠道配置:管理后台-138美业人才-系统设置-渠道管理
8
8
  export const channel:IChannel = { "project": "VE", "origin": "C", "platform": "XCX", "device": "ZJDF", "version": "1.0.0" };
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ import request from "./utils/request";
5
5
  import { decryptByDES, encryptByDES, encryptBySso } from "./utils/instance";
6
6
 
7
7
  export default {
8
- 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) => {
9
9
  /**
10
10
  * 东方网升项目公共 header
11
11
  * @param {object} dfws_params
@@ -20,7 +20,7 @@ export default {
20
20
  version: channel.version,
21
21
  params: JSON.stringify(dfws_header.queryChannels()),
22
22
  ...headers
23
- }, taro)
23
+ }, taro, debug)
24
24
  },
25
25
  // 接口解密
26
26
  decryptByDES,
@@ -6,16 +6,16 @@ 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字符串
@@ -30,9 +30,9 @@ export const objectToQueryString = (obj: object) => {
30
30
  }
31
31
 
32
32
  //短信/邮箱验证码加密
33
- export const encryptBySso = (value:string) => {
33
+ export const encryptBySso = (value: string) => {
34
34
  const key = Date.parse(new Date().toString())
35
- const sign = encryptByDES(`${captchaKey}${value}${key}`)
35
+ const sign = dfwsCrypto.encryptByDES(`${dfwsCrypto.decrypto(captchaKey, 123, 25)}${value}${key}`, secretkey)
36
36
  return {
37
37
  check_sign: sign,
38
38
  check_key: key,
@@ -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) => {