xctc-utils 1.3.2 → 1.3.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/dist/weixin/index.js +14 -16
- package/package.json +1 -1
package/dist/weixin/index.js
CHANGED
|
@@ -13,35 +13,37 @@ var defaultIv = "5uMz4Rsd0926DkC8";
|
|
|
13
13
|
var weixinConfig = {};
|
|
14
14
|
function weixinUrlCode(config) {
|
|
15
15
|
var _a, _b, _c, _d;
|
|
16
|
+
config = config !== null && config !== void 0 ? config : {};
|
|
16
17
|
var appId = (_a = config === null || config === void 0 ? void 0 : config.appId) !== null && _a !== void 0 ? _a : "";
|
|
17
18
|
if (!appId)
|
|
18
19
|
return;
|
|
19
|
-
weixinConfig = config
|
|
20
|
+
weixinConfig = config;
|
|
20
21
|
var scope = (_b = config === null || config === void 0 ? void 0 : config.scope) !== null && _b !== void 0 ? _b : "snsapi_userinfo";
|
|
21
22
|
var codeKey = (_c = config === null || config === void 0 ? void 0 : config.codeKey) !== null && _c !== void 0 ? _c : "weixinCode";
|
|
22
23
|
var stateKey = (_d = config === null || config === void 0 ? void 0 : config.stateKey) !== null && _d !== void 0 ? _d : "weixinState";
|
|
23
24
|
weixinConfig['scope'] = scope;
|
|
24
25
|
weixinConfig['codeKey'] = codeKey;
|
|
25
26
|
weixinConfig['stateKey'] = stateKey;
|
|
26
|
-
weixinConfig['scope'] = scope;
|
|
27
27
|
(0, index_1.useSessionStorage)("weixinConfig", weixinConfig);
|
|
28
|
-
var
|
|
28
|
+
var _e = weixinConfig.cryptoiv, cryptoiv = _e === void 0 ? "" : _e, _f = weixinConfig.cryptokey, cryptokey = _f === void 0 ? "" : _f;
|
|
29
29
|
var search = loc.search; // ?code=0916SzFa1KH9TA0Ke7Ha1AQx6446SzFr&state=123
|
|
30
30
|
// 获取地址栏返回 code 参数
|
|
31
31
|
var localCode = "";
|
|
32
|
-
if (codeKey)
|
|
32
|
+
if (codeKey) {
|
|
33
33
|
localCode = (0, index_1.getSessionStorage)(codeKey);
|
|
34
|
+
}
|
|
34
35
|
// 默认第一次通过链接进入系统,没有code和state
|
|
35
36
|
var searchIndex = -1;
|
|
36
37
|
var stateIndex = -1;
|
|
37
38
|
if (search) {
|
|
38
39
|
searchIndex = search.indexOf("code=");
|
|
39
40
|
stateIndex = search.indexOf("state=");
|
|
40
|
-
searchIndex = parseInt(searchIndex);
|
|
41
|
-
stateIndex = parseInt(stateIndex);
|
|
42
41
|
}
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if (localCode && stateIndex == -1 && searchIndex == -1) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// 如果链接地址中带有code
|
|
46
|
+
if (searchIndex >= 0) {
|
|
45
47
|
if (localCode) {
|
|
46
48
|
// localCode 存在,用户已执行微信跳转链接,用户可能执行当前网页的刷新操作
|
|
47
49
|
return;
|
|
@@ -65,7 +67,7 @@ function weixinUrlCode(config) {
|
|
|
65
67
|
return;
|
|
66
68
|
}
|
|
67
69
|
// 用户通过分享链接进入系统,此时含有State参数,无code参数
|
|
68
|
-
if (stateIndex >= 0
|
|
70
|
+
if (stateIndex >= 0) {
|
|
69
71
|
var hrefState = "";
|
|
70
72
|
var urlArr = formatSearch(search, "state=");
|
|
71
73
|
for (var k = 0; k < urlArr.length; k++) {
|
|
@@ -89,9 +91,7 @@ function weixinUrlCode(config) {
|
|
|
89
91
|
weixinCode(); // 微信授权页面获取CODE
|
|
90
92
|
return;
|
|
91
93
|
}
|
|
92
|
-
if (localCode)
|
|
93
|
-
return;
|
|
94
|
-
if (!localCode) {
|
|
94
|
+
if (!localCode && stateIndex == -1 && searchIndex == -1) {
|
|
95
95
|
return weixinCode();
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -192,13 +192,11 @@ function weixinInit() {
|
|
|
192
192
|
return wx;
|
|
193
193
|
}
|
|
194
194
|
function weixinCode() {
|
|
195
|
+
var _a;
|
|
195
196
|
if ((0, utils_1.weixinBrowser)()) {
|
|
196
197
|
if (!weixinConfig['appId'])
|
|
197
198
|
return;
|
|
198
|
-
var scope = "snsapi_userinfo";
|
|
199
|
-
if (weixinConfig['scope']) {
|
|
200
|
-
scope = weixinConfig['scope'];
|
|
201
|
-
}
|
|
199
|
+
var scope = (_a = weixinConfig === null || weixinConfig === void 0 ? void 0 : weixinConfig.scope) !== null && _a !== void 0 ? _a : "snsapi_userinfo";
|
|
202
200
|
var base = "https://open.weixin.qq.com/connect/oauth2/authorize?";
|
|
203
201
|
var uri = encodeURIComponent(loc.href.split("?")[0]);
|
|
204
202
|
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.3",
|
|
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",
|