xctc-utils 1.2.7 → 1.2.9

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.
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.decrypt = exports.encrypt = void 0;
7
7
  var crypto_js_1 = __importDefault(require("crypto-js"));
8
8
  var utils_1 = require("../utils");
9
- var index_1 = require("../storage/index");
10
9
  function formatVal(val) {
11
10
  var key = "5uMz4R8r0926DkC8";
12
11
  if (val)
@@ -37,9 +36,7 @@ function decrypt(word, key, iv) {
37
36
  var decrypt = crypto_js_1.default.AES.decrypt(src, key, { iv: iv, mode: crypto_js_1.default.mode.CBC, padding: crypto_js_1.default.pad.Pkcs7 });
38
37
  var decryptedStr = decrypt.toString(crypto_js_1.default.enc.Utf8);
39
38
  var data = decryptedStr.toString();
40
- (0, index_1.useSessionStorage)("decryptData", data);
41
39
  if ((0, utils_1.isJson)(data)) {
42
- (0, index_1.useSessionStorage)("decryptData2222", JSON.stringify(data));
43
40
  return JSON.parse(data);
44
41
  }
45
42
  else {
@@ -18,8 +18,10 @@ function weixinUrlCode(config) {
18
18
  var search = loc.search; // ?code=0916SzFa1KH9TA0Ke7Ha1AQx6446SzFr&state=123
19
19
  // 获取地址栏返回 code 参数
20
20
  var codeKey = weixinConfig['codeKey'];
21
- if (!codeKey)
21
+ if (!codeKey) {
22
22
  codeKey = "weixinCode";
23
+ weixinConfig['codeKey'] = codeKey;
24
+ }
23
25
  var localCode = "";
24
26
  if (codeKey)
25
27
  localCode = (0, index_1.getSessionStorage)(codeKey);
@@ -64,12 +66,14 @@ function weixinUrlCode(config) {
64
66
  var item = urlArr[k];
65
67
  if (item.indexOf("state=") != -1) {
66
68
  hrefState = item.substr(6);
67
- var stateKey = weixinConfig['stateKey'] || "weixinState";
69
+ var stateKey = weixinConfig['stateKey'];
70
+ if (!stateKey) {
71
+ stateKey = "weixinState";
72
+ weixinConfig['stateKey'] = stateKey;
73
+ }
68
74
  (0, index_1.useSessionStorage)(stateKey, hrefState);
69
75
  var cryptoObj = cryptoConfig(cryptokey, cryptoiv);
70
- (0, index_1.useSessionStorage)("cryptoObj", cryptoObj);
71
76
  var stateObj = (0, crypto_1.decrypt)(hrefState, cryptoObj.key, cryptoObj.iv);
72
- (0, index_1.useSessionStorage)("".concat(stateKey, "Obj111111"), stateObj);
73
77
  if (stateObj instanceof Object)
74
78
  stateObj = JSON.stringify(stateObj);
75
79
  (0, index_1.useSessionStorage)("".concat(stateKey, "Obj"), stateObj);
@@ -90,7 +94,7 @@ function cryptoConfig(key, iv) {
90
94
  if (!key)
91
95
  key = defaultKey;
92
96
  if (!iv)
93
- key = defaultIv;
97
+ iv = defaultIv;
94
98
  return {
95
99
  key: key,
96
100
  iv: iv,
@@ -128,7 +132,6 @@ function weixinLogin(code) {
128
132
  var hashVal = loc.hash;
129
133
  var state = (0, index_1.getSessionStorage)(stateKey);
130
134
  var str = "";
131
- (0, index_1.useSessionStorage)("getWeixinSessionState", state);
132
135
  if (state) {
133
136
  var stateObj = (0, index_1.getSessionStorage)("".concat(stateKey, "Obj"));
134
137
  for (var key in stateObj) {
@@ -187,8 +190,12 @@ function weixinCode() {
187
190
  if (!weixinConfig['appId'])
188
191
  return;
189
192
  var scope = "snsapi_userinfo";
190
- if (weixinConfig['scope'])
193
+ if (weixinConfig['scope']) {
191
194
  scope = weixinConfig['scope'];
195
+ }
196
+ else {
197
+ weixinConfig['scope'] = scope;
198
+ }
192
199
  var base = "https://open.weixin.qq.com/connect/oauth2/authorize?";
193
200
  var uri = encodeURIComponent(loc.href.split("?")[0]);
194
201
  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.2.7",
3
+ "version": "1.2.9",
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",