xctc-utils 1.2.0 → 1.2.2
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/test.d.ts +1 -0
- package/dist/test.js +14 -0
- package/dist/weixin/index.d.ts +1 -0
- package/dist/weixin/index.js +63 -38
- package/package.json +1 -1
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// var crypto = require("./crypto/index")
|
|
4
|
+
function testcrypto() {
|
|
5
|
+
var hrefState = "219281DA5170E6A003B47D8143F049E3E54F2EE0FA2487EE302BA86B3110045A2047367251B76089F3343B974BBC265A";
|
|
6
|
+
var key = "5uMz4R8rop26DkC8";
|
|
7
|
+
var iv = "5uMz4Rsd0926DkC8";
|
|
8
|
+
// let data = crypto.decrypt( hrefState , key , iv )
|
|
9
|
+
console.log(iv);
|
|
10
|
+
}
|
|
11
|
+
testcrypto();
|
|
12
|
+
// module.exports = {
|
|
13
|
+
// testcrypto,
|
|
14
|
+
// }
|
package/dist/weixin/index.d.ts
CHANGED
package/dist/weixin/index.js
CHANGED
|
@@ -23,46 +23,63 @@ function weixinUrlCode(config) {
|
|
|
23
23
|
var localCode = "";
|
|
24
24
|
if (codeKey)
|
|
25
25
|
localCode = (0, index_1.getSessionStorage)(codeKey);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
code = item.substr(5);
|
|
35
|
-
if (codeKey)
|
|
36
|
-
(0, index_1.useSessionStorage)(codeKey, code);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (code) {
|
|
40
|
-
weixinLogin(code);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else if (localCode) {
|
|
44
|
-
// localCode 存在,用户已执行微信跳转链接,执行刷新操作
|
|
26
|
+
// 默认第一次通过链接进入系统,没有code和state
|
|
27
|
+
var searchIndex = -1;
|
|
28
|
+
var stateIndex = -1;
|
|
29
|
+
if (search) {
|
|
30
|
+
searchIndex = search.indexOf("code=");
|
|
31
|
+
stateIndex = search.indexOf("state=");
|
|
32
|
+
searchIndex = parseInt(searchIndex);
|
|
33
|
+
stateIndex = parseInt(stateIndex);
|
|
45
34
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
// 如果链接地址中带有code和state
|
|
36
|
+
if (searchIndex >= 0 && stateIndex >= 0) {
|
|
37
|
+
if (localCode) {
|
|
38
|
+
// localCode 存在,用户已执行微信跳转链接,用户可能执行当前网页的刷新操作
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// 当前系统没有存储 code,流程为用户只需微信授权登录后返回系统,此时通过CODE执行微信登录
|
|
43
|
+
var urlArr = formatSearch(search, "code=");
|
|
44
|
+
var code = "";
|
|
51
45
|
for (var k = 0; k < urlArr.length; k++) {
|
|
52
46
|
var item = urlArr[k];
|
|
53
|
-
if (item.indexOf("
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var stateObj = (0, crypto_1.decrypt)(hrefState, cryptoConfig(cryptokey).key, cryptoConfig(cryptoiv).iv);
|
|
58
|
-
if (stateObj instanceof Object)
|
|
59
|
-
stateObj = JSON.stringify(stateObj);
|
|
60
|
-
(0, index_1.useSessionStorage)("".concat(stateKey, "Obj"), stateObj);
|
|
47
|
+
if (item.indexOf("code=") != -1) {
|
|
48
|
+
code = item.substr(5);
|
|
49
|
+
if (codeKey)
|
|
50
|
+
(0, index_1.useSessionStorage)(codeKey, code);
|
|
61
51
|
}
|
|
62
52
|
}
|
|
53
|
+
if (code) {
|
|
54
|
+
weixinLogin(code);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// 用户通过分享链接进入系统,此时含有State参数,无code参数
|
|
60
|
+
if (stateIndex >= 0 && !(searchIndex >= 0)) {
|
|
61
|
+
var hrefState = "";
|
|
62
|
+
var urlArr = formatSearch(search, "state=");
|
|
63
|
+
for (var k = 0; k < urlArr.length; k++) {
|
|
64
|
+
var item = urlArr[k];
|
|
65
|
+
if (item.indexOf("state=") != -1) {
|
|
66
|
+
hrefState = item.substr(6);
|
|
67
|
+
var stateKey = weixinConfig['stateKey'] || "weixinState";
|
|
68
|
+
(0, index_1.useSessionStorage)(stateKey, hrefState);
|
|
69
|
+
var stateObj = (0, crypto_1.decrypt)(hrefState, cryptoConfig(cryptokey).key, cryptoConfig(cryptoiv).iv);
|
|
70
|
+
if (stateObj instanceof Object)
|
|
71
|
+
stateObj = JSON.stringify(stateObj);
|
|
72
|
+
(0, index_1.useSessionStorage)("".concat(stateKey, "Obj"), stateObj);
|
|
73
|
+
}
|
|
63
74
|
}
|
|
64
75
|
// 将 state进行本地存储,存储完成后跳转到微信授权页面
|
|
65
76
|
weixinCode(); // 微信授权页面获取CODE
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (localCode)
|
|
80
|
+
return;
|
|
81
|
+
if (!localCode) {
|
|
82
|
+
return weixinCode();
|
|
66
83
|
}
|
|
67
84
|
}
|
|
68
85
|
exports.weixinUrlCode = weixinUrlCode;
|
|
@@ -87,18 +104,26 @@ function weixinLogin(code) {
|
|
|
87
104
|
};
|
|
88
105
|
if (!http)
|
|
89
106
|
return;
|
|
107
|
+
(0, index_1.useSessionStorage)("weixinLoginParams", JSON.stringify(obj));
|
|
108
|
+
if (weixinConfig === null || weixinConfig === void 0 ? void 0 : weixinConfig.isPassLogin)
|
|
109
|
+
return;
|
|
90
110
|
weixinConfig.http(obj).then(function (res) {
|
|
91
111
|
if (res.code == 40163) {
|
|
92
112
|
// 未登录则先执行登录
|
|
93
113
|
return weixinCode();
|
|
94
114
|
}
|
|
95
115
|
var data = res === null || res === void 0 ? void 0 : res.data;
|
|
96
|
-
if
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
116
|
+
// if( data instanceof Object ){
|
|
117
|
+
// useSessionStorage( "weixinLoginData" , JSON.stringify(data) )
|
|
118
|
+
// }else{
|
|
119
|
+
// useSessionStorage( "weixinLoginStatus" , `微信登录失败:${res.code};${res.msg}` )
|
|
120
|
+
// }
|
|
121
|
+
var resobj = {
|
|
122
|
+
code: res.code,
|
|
123
|
+
msg: res.msg,
|
|
124
|
+
data: res.data
|
|
125
|
+
};
|
|
126
|
+
(0, index_1.useSessionStorage)("weixinLoginData", JSON.stringify(resobj));
|
|
102
127
|
for (var key in data) {
|
|
103
128
|
var item = data[key];
|
|
104
129
|
if (item instanceof Object) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xctc-utils",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```\r 时间戳转时间,字符串转时间戳",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|