egova-admin-jssdk 0.0.6 → 0.0.7

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.
@@ -16,3 +16,15 @@ export declare function getUnitTree(params: UnitParams): Promise<import("axios")
16
16
  * @returns
17
17
  */
18
18
  export declare function countUnitHuman(params: CountParams): Promise<import("axios").AxiosResponse<any, any>> | undefined;
19
+ /**
20
+ * 获取加密方式和公钥
21
+ * @returns
22
+ */
23
+ export declare function getPublicKey(): Promise<import("axios").AxiosResponse<any, any>> | undefined;
24
+ /**
25
+ * 修改用户密码,sdk中会自动进行密码加密,外部无需对密码进行加密
26
+ * @param oldPwd 旧密码
27
+ * @param newPwd 新密码
28
+ * @returns
29
+ */
30
+ export declare function changeUserCryptogram(oldPwd: string, newPwd: string): Promise<import("axios").AxiosResponse<any, any> | undefined>;
@@ -1,5 +1,7 @@
1
1
  import { adminAxios } from "../util/axios-util";
2
2
  import { isNil } from "lodash-es";
3
+ import { saltData } from "../util/global";
4
+ import { crypto } from "@/util/crypto";
3
5
  /**
4
6
  * 获取部门人员
5
7
  * @param params
@@ -38,3 +40,38 @@ export function countUnitHuman(params) {
38
40
  const result = paramsList.length ? `${url}?${paramsList.join("&")}` : url;
39
41
  return adminAxios.getAxiosInstance()?.post(result, params.ids);
40
42
  }
43
+ /**
44
+ * 获取加密方式和公钥
45
+ * @returns
46
+ */
47
+ export function getPublicKey() {
48
+ return adminAxios.getAxiosInstance()?.get("/free/oauth/getalgandpublickey");
49
+ }
50
+ /**
51
+ * 修改用户密码,sdk中会自动进行密码加密,外部无需对密码进行加密
52
+ * @param oldPwd 旧密码
53
+ * @param newPwd 新密码
54
+ * @returns
55
+ */
56
+ export async function changeUserCryptogram(oldPwd, newPwd) {
57
+ if (!saltData.publicKey) {
58
+ const publicKeyRes = await getPublicKey();
59
+ if (publicKeyRes && !publicKeyRes.hasError) {
60
+ let data = publicKeyRes.result?.data || [];
61
+ if (data && data.length === 2) {
62
+ saltData.type = data[0];
63
+ saltData.publicKey = data[1];
64
+ }
65
+ }
66
+ }
67
+ let oldPwdEncrypt = oldPwd;
68
+ let newPwdEncrypt = newPwd;
69
+ if (saltData.publicKey) {
70
+ oldPwdEncrypt = await crypto.sm2Encrypt(oldPwd, saltData.publicKey);
71
+ newPwdEncrypt = await crypto.sm2Encrypt(newPwd, saltData.publicKey);
72
+ }
73
+ return adminAxios.getAxiosInstance()?.post("/unity/org/human/changeuserowncryptogram", {
74
+ cryptogram: newPwdEncrypt,
75
+ cryptogramOld: oldPwdEncrypt
76
+ });
77
+ }
@@ -0,0 +1,35 @@
1
+ import type { SM4ModeBase, SM4Mode_StringOutput, UTF8String } from "sm-crypto";
2
+ /**
3
+ * Crypto 加密
4
+ * @public
5
+ */
6
+ export declare class Crypto {
7
+ constructor(key: string);
8
+ private key;
9
+ /**
10
+ * 加密数据
11
+ * @param inArray - 加密数据
12
+ * @param mode - 加密模式
13
+ * @returns 加密结果
14
+ */
15
+ encrypt(inArray: number[] | UTF8String, mode?: SM4ModeBase | SM4Mode_StringOutput): string;
16
+ /**
17
+ * 解密数据
18
+ * @param inArray - 解密数据
19
+ * @param mode - 解密模式
20
+ * @returns 解密结果
21
+ */
22
+ decrypt(inArray: number[] | UTF8String, mode?: SM4ModeBase | SM4Mode_StringOutput): string;
23
+ /**
24
+ * sm2 加密数据 (登录时对密码的加密)
25
+ * @param msg
26
+ * @param publicKey
27
+ * @returns
28
+ */
29
+ sm2Encrypt(msg: string, publicKey?: string): Promise<string>;
30
+ }
31
+ /**
32
+ * Crypto 加密实例
33
+ * @public
34
+ */
35
+ export declare const crypto: Crypto;
@@ -0,0 +1,54 @@
1
+ /* eslint-disable camelcase */
2
+ import { sm2, sm4 } from "sm-crypto";
3
+ const key = "0123456789abcdeffedcba9876543210";
4
+ /**
5
+ * Crypto 加密
6
+ * @public
7
+ */
8
+ export class Crypto {
9
+ constructor(key) {
10
+ this.key = key;
11
+ }
12
+ key;
13
+ /**
14
+ * 加密数据
15
+ * @param inArray - 加密数据
16
+ * @param mode - 加密模式
17
+ * @returns 加密结果
18
+ */
19
+ encrypt(inArray, mode) {
20
+ return sm4.encrypt(inArray, this.key, mode);
21
+ }
22
+ /**
23
+ * 解密数据
24
+ * @param inArray - 解密数据
25
+ * @param mode - 解密模式
26
+ * @returns 解密结果
27
+ */
28
+ decrypt(inArray, mode) {
29
+ return sm4.decrypt(inArray, this.key, mode);
30
+ }
31
+ /**
32
+ * sm2 加密数据 (登录时对密码的加密)
33
+ * @param msg
34
+ * @param publicKey
35
+ * @returns
36
+ */
37
+ async sm2Encrypt(msg, publicKey) {
38
+ try {
39
+ if (!publicKey) {
40
+ return Promise.reject(new Error("无法获取加密密钥"));
41
+ }
42
+ const encryptData = sm2.doEncrypt(msg, publicKey, 1);
43
+ return Promise.resolve(encryptData);
44
+ }
45
+ catch (error) {
46
+ return Promise.reject(error);
47
+ }
48
+ }
49
+ }
50
+ /**
51
+ * Crypto 加密实例
52
+ * @public
53
+ */
54
+ export const crypto = new Crypto(key);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 定义的加密方式和密钥
3
+ */
4
+ export declare const saltData: {
5
+ type: string;
6
+ publicKey: string;
7
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 定义的加密方式和密钥
3
+ */
4
+ export const saltData = {
5
+ type: "sm2WithSalt",
6
+ publicKey: ""
7
+ };
@@ -1,16 +1,17 @@
1
- var j = Object.defineProperty;
2
- var B = (r, t, e) => t in r ? j(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var p = (r, t, e) => B(r, typeof t != "symbol" ? t + "" : t, e);
4
- import E from "axios";
5
- import { random as I, merge as u, isNil as d } from "lodash-es";
6
- import U from "crypto-js";
7
- import b from "qs";
8
- import { toRaw as A } from "vue";
9
- /*! egova-admin-jssdk v0.0.6 */
10
- function g(r) {
1
+ var B = Object.defineProperty;
2
+ var K = (r, t, e) => t in r ? B(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var p = (r, t, e) => K(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import L from "axios";
5
+ import { random as U, merge as u, isNil as h } from "lodash-es";
6
+ import A from "crypto-js";
7
+ import I from "qs";
8
+ import { toRaw as C } from "vue";
9
+ import { sm4 as E, sm2 as V } from "sm-crypto";
10
+ /*! egova-admin-jssdk v0.0.7 */
11
+ function f(r) {
11
12
  return r instanceof Element ? "element" : Object.prototype.toString.call(r).replace(/\[object\s(.+)\]/, "$1").toLowerCase();
12
13
  }
13
- class v {
14
+ class N {
14
15
  /**
15
16
  * 等价于Math.random()
16
17
  * @returns
@@ -48,15 +49,15 @@ class v {
48
49
  a += this.getRandomChar(e), a += this.getRandomChar(n), a += this.getRandomChar(o), a += this.getRandomChar(s);
49
50
  for (let c = a.length; c < t; c++)
50
51
  a += this.getRandomChar(i);
51
- return a = a.split("").sort(() => I(!0) - 0.5).join(""), a;
52
+ return a = a.split("").sort(() => U(!0) - 0.5).join(""), a;
52
53
  }
53
54
  getRandomChar(t) {
54
- const e = Math.floor(I(!0) * t.length);
55
+ const e = Math.floor(U(!0) * t.length);
55
56
  return t[e];
56
57
  }
57
58
  }
58
- const L = new v();
59
- class V {
59
+ const k = new N();
60
+ class H {
60
61
  /**
61
62
  * 清除 url 中重复的斜杠
62
63
  * @param url 链接地址
@@ -67,8 +68,8 @@ class V {
67
68
  return t.replace(/([^:]|^)\/{2,}/g, "$1/");
68
69
  }
69
70
  }
70
- const C = new V();
71
- class N {
71
+ const P = new H();
72
+ class D {
72
73
  constructor(t) {
73
74
  /**
74
75
  * 应用标识
@@ -85,7 +86,7 @@ class N {
85
86
  * @returns
86
87
  */
87
88
  generateRandomString() {
88
- return L.randomStr(8);
89
+ return k.randomStr(8);
89
90
  }
90
91
  /**
91
92
  * 生成签名参数
@@ -109,10 +110,10 @@ class N {
109
110
  * @returns
110
111
  */
111
112
  removeNilValue(t) {
112
- if (g(t) === "object") {
113
+ if (f(t) === "object") {
113
114
  for (const e in t)
114
115
  if (Object.prototype.hasOwnProperty.call(t, e)) {
115
- const n = t[e], o = g(n);
116
+ const n = t[e], o = f(n);
116
117
  o === "object" ? this.removeNilValue(n) : (o === "null" || o === "undefined" || o === "function") && delete t[e];
117
118
  }
118
119
  }
@@ -123,7 +124,7 @@ class N {
123
124
  * @returns
124
125
  */
125
126
  formatEncodeValue(t) {
126
- const e = g(t);
127
+ const e = f(t);
127
128
  return encodeURIComponent(e === "undefined" || e === "function" ? "" : t).replace(/%00/g, "\0").replace(/%2B/g, "+").replace(/%20/g, "+").replace(/\(/g, "%28").replace(/\)/g, "%29").replace(/'/g, "%27").replace(/!/g, "%21").replace(/~/g, "%7E");
128
129
  }
129
130
  /**
@@ -134,7 +135,7 @@ class N {
134
135
  * @returns
135
136
  */
136
137
  formatEncodeParam(t, e, n) {
137
- const o = g(n);
138
+ const o = f(n);
138
139
  if (o === "object") {
139
140
  const s = Object.keys(n).sort();
140
141
  s.length === 0 ? t.push(`${e}={}`) : s.forEach((i) => {
@@ -159,7 +160,7 @@ class N {
159
160
  * @returns
160
161
  */
161
162
  cryptoHash(t) {
162
- return U.HmacSHA1(t, this.appIdCode.code).toString(U.enc.Hex).toUpperCase();
163
+ return A.HmacSHA1(t, this.appIdCode.code).toString(A.enc.Hex).toUpperCase();
163
164
  }
164
165
  /**
165
166
  * 获取 url 参数
@@ -167,7 +168,7 @@ class N {
167
168
  * @returns
168
169
  */
169
170
  urlSearchParams(t) {
170
- return t && t.indexOf("?") > -1 ? b.parse(t.split("?").pop() ?? "") : {};
171
+ return t && t.indexOf("?") > -1 ? I.parse(t.split("?").pop() ?? "") : {};
171
172
  }
172
173
  /**
173
174
  * 获取签名 url
@@ -179,8 +180,8 @@ class N {
179
180
  try {
180
181
  const { pathname: e, origin: n } = new URL(t, window.location.origin), o = this.urlSearchParams(t), s = this.generateSignatureOption();
181
182
  u(o, s);
182
- const i = this.sortParamByKey(o), c = `${C.cleanUrl(`/${e}`)}?${i}`, h = this.cryptoHash(c);
183
- t = `${n}${c}&signature=${h}`;
183
+ const i = this.sortParamByKey(o), c = `${P.cleanUrl(`/${e}`)}?${i}`, m = this.cryptoHash(c);
184
+ t = `${n}${c}&signature=${m}`;
184
185
  } catch {
185
186
  console.error("签名失败,请使用有效的链接", t);
186
187
  }
@@ -195,36 +196,36 @@ class N {
195
196
  signatureConfig(t) {
196
197
  var e, n, o, s;
197
198
  try {
198
- const a = ((e = t.method) == null ? void 0 : e.toUpperCase()) === "GET", c = A(t.data), h = c !== null && typeof c == "object", f = ((o = (n = t.headers) == null ? void 0 : n["Content-Type"]) == null ? void 0 : o.toString()) || "", R = f.includes("multipart/form-data");
199
- let y = f.includes("application/json");
200
- !a && !f && h && (y = !0), u(t, { headers: { "App-Id": this.appIdCode.id } });
201
- const m = {}, O = this.urlSearchParams(t.url);
202
- if (u(m, O), !d(t.params)) {
203
- const l = A(t.params);
204
- this.removeNilValue(l), t.params = l, u(m, b.parse(b.stringify(l)));
199
+ const a = ((e = t.method) == null ? void 0 : e.toUpperCase()) === "GET", c = C(t.data), m = c !== null && typeof c == "object", b = ((o = (n = t.headers) == null ? void 0 : n["Content-Type"]) == null ? void 0 : o.toString()) || "", O = b.includes("multipart/form-data");
200
+ let S = b.includes("application/json");
201
+ !a && !b && m && (S = !0), u(t, { headers: { "App-Id": this.appIdCode.id } });
202
+ const g = {}, j = this.urlSearchParams(t.url);
203
+ if (u(g, j), !h(t.params)) {
204
+ const l = C(t.params);
205
+ this.removeNilValue(l), t.params = l, u(g, I.parse(I.stringify(l)));
205
206
  }
206
- !d(c) && h && !R && !y && u(m, c);
207
- const S = this.generateSignatureOption();
208
- u(m, S);
209
- let w = this.sortParamByKey(m);
210
- if (y) {
207
+ !h(c) && m && !O && !S && u(g, c);
208
+ const w = this.generateSignatureOption();
209
+ u(g, w);
210
+ let $ = this.sortParamByKey(g);
211
+ if (S) {
211
212
  const l = JSON.stringify(c);
212
- this.isStringOverKB(l, 128) || (h ? w += this.formatEncodeValue(l) : w += this.formatEncodeValue(c));
213
+ this.isStringOverKB(l, 128) || (m ? $ += this.formatEncodeValue(l) : $ += this.formatEncodeValue(c));
213
214
  }
214
- let $ = "";
215
- (s = t.url) != null && s.startsWith("http") ? $ = t.url : $ = `${t.baseURL}/${t.url || ""}`;
216
- const { pathname: P } = new URL($, window.location.origin), T = `${C.cleanUrl(`/${P}`)}?${w}`;
217
- S.signature = this.cryptoHash(T), t.params = u({}, t.params, S);
215
+ let x = "";
216
+ (s = t.url) != null && s.startsWith("http") ? x = t.url : x = `${t.baseURL}/${t.url || ""}`;
217
+ const { pathname: T } = new URL(x, window.location.origin), v = `${P.cleanUrl(`/${T}`)}?${$}`;
218
+ w.signature = this.cryptoHash(v), t.params = u({}, t.params, w);
218
219
  } catch (i) {
219
220
  console.error("签名失败", i);
220
221
  }
221
222
  }
222
223
  }
223
- const H = {
224
+ const z = {
224
225
  id: "mis",
225
226
  code: "c9d8e36df18ef01ff0da74e0bb13151c"
226
- }, K = new N(H);
227
- class z {
227
+ }, F = new D(z);
228
+ class M {
228
229
  constructor() {
229
230
  p(this, "axiosInstance");
230
231
  p(this, "egovaAdminToken");
@@ -235,7 +236,7 @@ class z {
235
236
  * @param token 统一用户中心的token
236
237
  */
237
238
  init(t, e) {
238
- this.egovaAdminToken = e, this.axiosInstance = E.create({
239
+ this.egovaAdminToken = e, this.axiosInstance = L.create({
239
240
  baseURL: t,
240
241
  timeout: 6e4
241
242
  }), this.configAxios();
@@ -264,28 +265,93 @@ class z {
264
265
  * @param config
265
266
  */
266
267
  configSignature(t) {
267
- K.signatureConfig(t);
268
+ F.signatureConfig(t);
268
269
  }
269
270
  }
270
- const x = new z();
271
- function _(r) {
271
+ const y = new M(), d = {
272
+ type: "sm2WithSalt",
273
+ publicKey: ""
274
+ }, J = "0123456789abcdeffedcba9876543210";
275
+ class Q {
276
+ constructor(t) {
277
+ p(this, "key");
278
+ this.key = t;
279
+ }
280
+ /**
281
+ * 加密数据
282
+ * @param inArray - 加密数据
283
+ * @param mode - 加密模式
284
+ * @returns 加密结果
285
+ */
286
+ encrypt(t, e) {
287
+ return E.encrypt(t, this.key, e);
288
+ }
289
+ /**
290
+ * 解密数据
291
+ * @param inArray - 解密数据
292
+ * @param mode - 解密模式
293
+ * @returns 解密结果
294
+ */
295
+ decrypt(t, e) {
296
+ return E.decrypt(t, this.key, e);
297
+ }
298
+ /**
299
+ * sm2 加密数据 (登录时对密码的加密)
300
+ * @param msg
301
+ * @param publicKey
302
+ * @returns
303
+ */
304
+ async sm2Encrypt(t, e) {
305
+ try {
306
+ if (!e)
307
+ return Promise.reject(new Error("无法获取加密密钥"));
308
+ const n = V.doEncrypt(t, e, 1);
309
+ return Promise.resolve(n);
310
+ } catch (n) {
311
+ return Promise.reject(n);
312
+ }
313
+ }
314
+ }
315
+ const R = new Q(J);
316
+ function rt(r) {
272
317
  var t;
273
- return (t = x.getAxiosInstance()) == null ? void 0 : t.get("/unity/org/human/gethumanlist", { params: r });
318
+ return (t = y.getAxiosInstance()) == null ? void 0 : t.get("/unity/org/human/gethumanlist", { params: r });
274
319
  }
275
- function W(r) {
320
+ function ot(r) {
276
321
  var t;
277
- return (t = x.getAxiosInstance()) == null ? void 0 : t.get("/unity/builder/org/gettenantunittree", { params: r });
322
+ return (t = y.getAxiosInstance()) == null ? void 0 : t.get("/unity/builder/org/gettenantunittree", { params: r });
278
323
  }
279
- function X(r) {
324
+ function st(r) {
280
325
  var o;
281
326
  const t = "/unity/org/unit/countunithumannumber", e = [];
282
- d(r.tenantId) || e.push(`tenantId=${r.tenantId}`), d(r.roleId) || e.push(`roleId=${r.roleId}`), d(r.onlyQueryUnbound) || e.push(`onlyQueryUnbound=${r.onlyQueryUnbound}`), d(r.permissionId) || e.push(`permissionId=${r.permissionId}`);
327
+ h(r.tenantId) || e.push(`tenantId=${r.tenantId}`), h(r.roleId) || e.push(`roleId=${r.roleId}`), h(r.onlyQueryUnbound) || e.push(`onlyQueryUnbound=${r.onlyQueryUnbound}`), h(r.permissionId) || e.push(`permissionId=${r.permissionId}`);
283
328
  const n = e.length ? `${t}?${e.join("&")}` : t;
284
- return (o = x.getAxiosInstance()) == null ? void 0 : o.post(n, r.ids);
329
+ return (o = y.getAxiosInstance()) == null ? void 0 : o.post(n, r.ids);
330
+ }
331
+ function q() {
332
+ var r;
333
+ return (r = y.getAxiosInstance()) == null ? void 0 : r.get("/free/oauth/getalgandpublickey");
334
+ }
335
+ async function it(r, t) {
336
+ var o, s;
337
+ if (!d.publicKey) {
338
+ const i = await q();
339
+ if (i && !i.hasError) {
340
+ let a = ((o = i.result) == null ? void 0 : o.data) || [];
341
+ a.length === 2 && (d.type = a[0], d.publicKey = a[1]);
342
+ }
343
+ }
344
+ let e = r, n = t;
345
+ return d.publicKey && (e = await R.sm2Encrypt(r, d.publicKey), n = await R.sm2Encrypt(t, d.publicKey)), (s = y.getAxiosInstance()) == null ? void 0 : s.post("/unity/org/human/changeuserowncryptogram", {
346
+ cryptogram: n,
347
+ cryptogramOld: e
348
+ });
285
349
  }
286
350
  export {
287
- x as adminAxios,
288
- X as countUnitHuman,
289
- W as getUnitTree,
290
- _ as gethumanlist
351
+ y as adminAxios,
352
+ it as changeUserCryptogram,
353
+ st as countUnitHuman,
354
+ q as getPublicKey,
355
+ ot as getUnitTree,
356
+ rt as gethumanlist
291
357
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "egova-admin-jssdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "build": "run-p type-check build-lib build-type",
@@ -12,13 +12,15 @@
12
12
  "axios": ">=0.29.0",
13
13
  "crypto-js": ">=4.1.1",
14
14
  "lodash-es": ">=4.17.21",
15
- "qs": ">=6.13.1"
15
+ "qs": ">=6.13.1",
16
+ "sm-crypto": ">=0.3.12"
16
17
  },
17
18
  "dependencies": {
18
19
  "axios": "^1.7.9",
19
20
  "crypto-js": "^4.2.0",
20
21
  "lodash-es": "^4.17.21",
21
22
  "qs": "^6.13.1",
23
+ "sm-crypto": "^0.3.13",
22
24
  "vue": "^3.5.13"
23
25
  },
24
26
  "devDependencies": {
@@ -27,6 +29,7 @@
27
29
  "@types/lodash-es": "^4.17.12",
28
30
  "@types/node": "^22.10.2",
29
31
  "@types/qs": "^6.9.17",
32
+ "@types/sm-crypto": "^0.3.4",
30
33
  "@vitejs/plugin-vue": "^5.2.1",
31
34
  "@vue/eslint-config-prettier": "^10.1.0",
32
35
  "@vue/eslint-config-typescript": "^14.1.3",