egova-admin-jssdk 0.1.0 → 0.1.1
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/service/index.js +2 -1
- package/lib/egova-admin-jssdk.mjs +27 -27
- package/package.json +1 -1
package/dist/service/index.js
CHANGED
|
@@ -74,7 +74,8 @@ export function getPublicKey() {
|
|
|
74
74
|
*/
|
|
75
75
|
export async function changeUserCryptogram(oldPwd, newPwd) {
|
|
76
76
|
if (!saltData.publicKey) {
|
|
77
|
-
const
|
|
77
|
+
const bodyReponse = await getPublicKey();
|
|
78
|
+
const publicKeyRes = bodyReponse?.data || {};
|
|
78
79
|
if (publicKeyRes && !publicKeyRes.hasError) {
|
|
79
80
|
const data = publicKeyRes.result?.data || [];
|
|
80
81
|
if (data && data.length === 2) {
|
|
@@ -6,7 +6,7 @@ import { random as j, merge as d, isNil as m } from "lodash-es";
|
|
|
6
6
|
import P from "crypto-js";
|
|
7
7
|
import O from "qs";
|
|
8
8
|
import { sm4 as K, sm2 as v } from "sm-crypto";
|
|
9
|
-
/*! egova-admin-jssdk v0.
|
|
9
|
+
/*! egova-admin-jssdk v0.1.1 */
|
|
10
10
|
function C(r) {
|
|
11
11
|
return r instanceof Element ? "element" : Object.prototype.toString.call(r).replace(/\[object\s(.+)\]/, "$1").toLowerCase();
|
|
12
12
|
}
|
|
@@ -44,11 +44,11 @@ class N {
|
|
|
44
44
|
*/
|
|
45
45
|
getRandomPassword(t) {
|
|
46
46
|
const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", n = "abcdefghijklmnopqrstuvwxyz", o = "0123456789", s = ".~!@#$%^&*)(_+}{|:?><", i = e + n + o + s;
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
for (let
|
|
50
|
-
|
|
51
|
-
return
|
|
47
|
+
let c = "";
|
|
48
|
+
c += this.getRandomChar(e), c += this.getRandomChar(n), c += this.getRandomChar(o), c += this.getRandomChar(s);
|
|
49
|
+
for (let a = c.length; a < t; a++)
|
|
50
|
+
c += this.getRandomChar(i);
|
|
51
|
+
return c = c.split("").sort(() => j(!0) - 0.5).join(""), c;
|
|
52
52
|
}
|
|
53
53
|
getRandomChar(t) {
|
|
54
54
|
const e = Math.floor(j(!0) * t.length);
|
|
@@ -67,7 +67,7 @@ class H {
|
|
|
67
67
|
return t.replace(/([^:]|^)\/{2,}/g, "$1/");
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
const
|
|
70
|
+
const T = new H();
|
|
71
71
|
class _ {
|
|
72
72
|
constructor(t) {
|
|
73
73
|
/**
|
|
@@ -179,8 +179,8 @@ class _ {
|
|
|
179
179
|
try {
|
|
180
180
|
const { pathname: e, origin: n } = new URL(t, window.location.origin), o = this.urlSearchParams(t), s = this.generateSignatureOption();
|
|
181
181
|
d(o, s);
|
|
182
|
-
const i = this.sortParamByKey(o),
|
|
183
|
-
t = `${n}${
|
|
182
|
+
const i = this.sortParamByKey(o), a = `${T.cleanUrl(`/${e}`)}?${i}`, p = this.cryptoHash(a);
|
|
183
|
+
t = `${n}${a}&signature=${p}`;
|
|
184
184
|
} catch {
|
|
185
185
|
console.error("签名失败,请使用有效的链接", t);
|
|
186
186
|
}
|
|
@@ -195,25 +195,25 @@ class _ {
|
|
|
195
195
|
signatureConfig(t) {
|
|
196
196
|
var e, n, o, s;
|
|
197
197
|
try {
|
|
198
|
-
const
|
|
198
|
+
const c = ((e = t.method) == null ? void 0 : e.toUpperCase()) === "GET", a = t.data, p = a !== null && typeof a == "object", y = ((o = (n = t.headers) == null ? void 0 : n["Content-Type"]) == null ? void 0 : o.toString()) || "", g = y.includes("multipart/form-data");
|
|
199
199
|
let u = y.includes("application/json");
|
|
200
|
-
!
|
|
200
|
+
!c && !y && p && (u = !0), d(t, { headers: { "App-Id": this.appIdCode.id } });
|
|
201
201
|
const f = {}, x = this.urlSearchParams(t.url);
|
|
202
202
|
if (d(f, x), !m(t.params)) {
|
|
203
203
|
const S = t.params;
|
|
204
204
|
this.removeNilValue(S), t.params = S, d(f, O.parse(O.stringify(S)));
|
|
205
205
|
}
|
|
206
|
-
!m(
|
|
206
|
+
!m(a) && p && !g && !u && d(f, a);
|
|
207
207
|
const A = this.generateSignatureOption();
|
|
208
208
|
d(f, A);
|
|
209
209
|
let b = this.sortParamByKey(f);
|
|
210
210
|
if (u) {
|
|
211
|
-
const S = JSON.stringify(
|
|
212
|
-
this.isStringOverKB(S, 128) || (p ? b += this.formatEncodeValue(S) : b += this.formatEncodeValue(
|
|
211
|
+
const S = JSON.stringify(a);
|
|
212
|
+
this.isStringOverKB(S, 128) || (p ? b += this.formatEncodeValue(S) : b += this.formatEncodeValue(a));
|
|
213
213
|
}
|
|
214
214
|
let E = "";
|
|
215
215
|
(s = t.url) != null && s.startsWith("http") ? E = t.url : E = `${t.baseURL}/${t.url || ""}`;
|
|
216
|
-
const { pathname: U } = new URL(E, window.location.origin), B = `${
|
|
216
|
+
const { pathname: U } = new URL(E, window.location.origin), B = `${T.cleanUrl(`/${U}`)}?${b}`;
|
|
217
217
|
A.signature = this.cryptoHash(B), t.params = d({}, t.params, A);
|
|
218
218
|
} catch (i) {
|
|
219
219
|
console.error("签名失败", i);
|
|
@@ -279,17 +279,17 @@ class z {
|
|
|
279
279
|
return P.enc.Hex.stringify(e);
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
|
-
const I = new z(W),
|
|
282
|
+
const I = new z(W), R = /* @__PURE__ */ new Map(), J = [
|
|
283
283
|
{
|
|
284
284
|
type: "sm2WithSalt",
|
|
285
285
|
encrypt: (r, t) => {
|
|
286
286
|
const { type: e, publicKey: n } = t || {};
|
|
287
287
|
if (!e || !n) return;
|
|
288
|
-
let o =
|
|
289
|
-
(!o || o === "") && (o = I.cryptRandom(16),
|
|
290
|
-
const s = I.cryptRandom(16), i = I.cryptRandom(3),
|
|
291
|
-
if (
|
|
292
|
-
const p =
|
|
288
|
+
let o = R.get(e);
|
|
289
|
+
(!o || o === "") && (o = I.cryptRandom(16), R.set(e, o));
|
|
290
|
+
const s = I.cryptRandom(16), i = I.cryptRandom(3), c = v.doEncrypt(i + o, n, 1), a = K.encrypt(r, o, { iv: s, mode: "cbc" });
|
|
291
|
+
if (c && a) {
|
|
292
|
+
const p = c, y = s + a;
|
|
293
293
|
return {
|
|
294
294
|
data: p + y
|
|
295
295
|
};
|
|
@@ -298,7 +298,7 @@ const I = new z(W), T = /* @__PURE__ */ new Map(), J = [
|
|
|
298
298
|
}
|
|
299
299
|
];
|
|
300
300
|
function q(r, t) {
|
|
301
|
-
var s, i,
|
|
301
|
+
var s, i, c, a, p, y;
|
|
302
302
|
const e = r, { changeContentTypeEnabled: n } = t || {}, o = {
|
|
303
303
|
type: $.type,
|
|
304
304
|
publicKey: $.publicKey
|
|
@@ -310,8 +310,8 @@ function q(r, t) {
|
|
|
310
310
|
const u = e.data;
|
|
311
311
|
if (m(u))
|
|
312
312
|
return e;
|
|
313
|
-
let x = u !== null && typeof u == "object" && Object.prototype.toString.call(u) === "[object FormData]" || ((
|
|
314
|
-
if (x || (x = u instanceof FormData || typeof (u == null ? void 0 : u.append) == "function" && typeof (u == null ? void 0 : u.entries) == "function"), x || ((p = (
|
|
313
|
+
let x = u !== null && typeof u == "object" && Object.prototype.toString.call(u) === "[object FormData]" || ((c = (i = e.headers) == null ? void 0 : i["Content-Type"]) == null ? void 0 : c.includes("multipart/form-data"));
|
|
314
|
+
if (x || (x = u instanceof FormData || typeof (u == null ? void 0 : u.append) == "function" && typeof (u == null ? void 0 : u.entries) == "function"), x || ((p = (a = e.headers) == null ? void 0 : a["Content-Type"]) == null ? void 0 : p.includes("application/x-www-form-urlencoded")))
|
|
315
315
|
return e;
|
|
316
316
|
const b = o.type;
|
|
317
317
|
if (b && b === "sm2WithSalt") {
|
|
@@ -413,9 +413,9 @@ function X() {
|
|
|
413
413
|
async function dt(r, t) {
|
|
414
414
|
var o, s;
|
|
415
415
|
if (!w.publicKey) {
|
|
416
|
-
const i = await X();
|
|
417
|
-
if (
|
|
418
|
-
const a = ((o =
|
|
416
|
+
const i = await X(), c = (i == null ? void 0 : i.data) || {};
|
|
417
|
+
if (!c.hasError) {
|
|
418
|
+
const a = ((o = c.result) == null ? void 0 : o.data) || [];
|
|
419
419
|
a.length === 2 && (w.type = a[0], w.publicKey = a[1]);
|
|
420
420
|
}
|
|
421
421
|
}
|