xctc-utils 1.3.0 → 1.3.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/weixin/index.js +18 -21
- package/package.json +1 -1
package/dist/weixin/index.js
CHANGED
|
@@ -12,16 +12,22 @@ var defaultKey = "5uMz4R8rop26DkC8";
|
|
|
12
12
|
var defaultIv = "5uMz4Rsd0926DkC8";
|
|
13
13
|
var weixinConfig = {};
|
|
14
14
|
function weixinUrlCode(config) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
16
|
+
var appId = (_a = config === null || config === void 0 ? void 0 : config.appId) !== null && _a !== void 0 ? _a : "";
|
|
17
|
+
if (!appId)
|
|
18
|
+
return;
|
|
15
19
|
weixinConfig = config || {};
|
|
20
|
+
var scope = (_b = config === null || config === void 0 ? void 0 : config.scope) !== null && _b !== void 0 ? _b : "snsapi_userinfo";
|
|
21
|
+
var codeKey = (_c = config === null || config === void 0 ? void 0 : config.codeKey) !== null && _c !== void 0 ? _c : "weixinCode";
|
|
22
|
+
var stateKey = (_d = config === null || config === void 0 ? void 0 : config.stateKey) !== null && _d !== void 0 ? _d : "weixinState";
|
|
23
|
+
weixinConfig['scope'] = scope;
|
|
24
|
+
weixinConfig['codeKey'] = codeKey;
|
|
25
|
+
weixinConfig['stateKey'] = stateKey;
|
|
26
|
+
weixinConfig['scope'] = scope;
|
|
16
27
|
(0, index_1.useSessionStorage)("weixinConfig", weixinConfig);
|
|
17
28
|
var cryptoiv = weixinConfig.cryptoiv, cryptokey = weixinConfig.cryptokey;
|
|
18
29
|
var search = loc.search; // ?code=0916SzFa1KH9TA0Ke7Ha1AQx6446SzFr&state=123
|
|
19
30
|
// 获取地址栏返回 code 参数
|
|
20
|
-
var codeKey = weixinConfig['codeKey'];
|
|
21
|
-
if (!codeKey) {
|
|
22
|
-
codeKey = "weixinCode";
|
|
23
|
-
weixinConfig['codeKey'] = codeKey;
|
|
24
|
-
}
|
|
25
31
|
var localCode = "";
|
|
26
32
|
if (codeKey)
|
|
27
33
|
localCode = (0, index_1.getSessionStorage)(codeKey);
|
|
@@ -66,17 +72,17 @@ function weixinUrlCode(config) {
|
|
|
66
72
|
var item = urlArr[k];
|
|
67
73
|
if (item.indexOf("state=") != -1) {
|
|
68
74
|
hrefState = item.substr(6);
|
|
69
|
-
var
|
|
70
|
-
if (!
|
|
71
|
-
|
|
72
|
-
weixinConfig['stateKey'] =
|
|
75
|
+
var stateKey_1 = weixinConfig['stateKey'];
|
|
76
|
+
if (!stateKey_1) {
|
|
77
|
+
stateKey_1 = "weixinState";
|
|
78
|
+
weixinConfig['stateKey'] = stateKey_1;
|
|
73
79
|
}
|
|
74
|
-
(0, index_1.useSessionStorage)(
|
|
80
|
+
(0, index_1.useSessionStorage)(stateKey_1, hrefState);
|
|
75
81
|
var cryptoObj = cryptoConfig(cryptokey, cryptoiv);
|
|
76
82
|
var stateObj = (0, crypto_1.decrypt)(hrefState, cryptoObj.key, cryptoObj.iv);
|
|
77
83
|
if (stateObj instanceof Object)
|
|
78
84
|
stateObj = JSON.stringify(stateObj);
|
|
79
|
-
(0, index_1.useSessionStorage)("".concat(
|
|
85
|
+
(0, index_1.useSessionStorage)("".concat(stateKey_1, "Obj"), stateObj);
|
|
80
86
|
}
|
|
81
87
|
}
|
|
82
88
|
// 将 state进行本地存储,存储完成后跳转到微信授权页面
|
|
@@ -130,14 +136,10 @@ function weixinLogin(code) {
|
|
|
130
136
|
}
|
|
131
137
|
var url = loc.origin;
|
|
132
138
|
var hashVal = loc.hash;
|
|
133
|
-
var state = (0, index_1.getSessionStorage)(stateKey)
|
|
139
|
+
var state = (0, index_1.getSessionStorage)(stateKey);
|
|
134
140
|
var str = "";
|
|
135
|
-
(0, index_1.useSessionStorage)("getstatedata===", state);
|
|
136
141
|
if (state) {
|
|
137
|
-
(0, index_1.useSessionStorage)("stateKey===", "".concat(stateKey, "Obj"));
|
|
138
142
|
var stateObj = (0, index_1.getSessionStorage)("".concat(stateKey, "Obj"));
|
|
139
|
-
(0, index_1.useSessionStorage)("getstateObj===", stateObj);
|
|
140
|
-
(0, index_1.useSessionStorage)("url11111===", url);
|
|
141
143
|
for (var key in stateObj) {
|
|
142
144
|
if (key == "path") {
|
|
143
145
|
if (stateObj[key][0] == "/") {
|
|
@@ -146,7 +148,6 @@ function weixinLogin(code) {
|
|
|
146
148
|
else {
|
|
147
149
|
url = "".concat(url, "/#/").concat(stateObj.path);
|
|
148
150
|
}
|
|
149
|
-
(0, index_1.useSessionStorage)("url22222===", url);
|
|
150
151
|
}
|
|
151
152
|
else {
|
|
152
153
|
str += "".concat(key, "=").concat(stateObj[key], "&");
|
|
@@ -157,7 +158,6 @@ function weixinLogin(code) {
|
|
|
157
158
|
url = "".concat(url, "?").concat(str);
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
|
-
(0, index_1.useSessionStorage)("url333333===", url);
|
|
161
161
|
loc.replace(url);
|
|
162
162
|
}
|
|
163
163
|
else {
|
|
@@ -199,9 +199,6 @@ function weixinCode() {
|
|
|
199
199
|
if (weixinConfig['scope']) {
|
|
200
200
|
scope = weixinConfig['scope'];
|
|
201
201
|
}
|
|
202
|
-
else {
|
|
203
|
-
weixinConfig['scope'] = scope;
|
|
204
|
-
}
|
|
205
202
|
var base = "https://open.weixin.qq.com/connect/oauth2/authorize?";
|
|
206
203
|
var uri = encodeURIComponent(loc.href.split("?")[0]);
|
|
207
204
|
var config = "appid=".concat(weixinConfig.appId, "&redirect_uri=").concat(uri, "&response_type=code&scope=").concat(scope, "&state=state#wechat_redirect");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xctc-utils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.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",
|