cloudcc-ccdk 0.0.4 → 0.0.7
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/README.md +24 -0
- package/lib/ccdk.js +33 -18
- package/lib/ccdk.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
#### 发布版本:0.0.7
|
|
2
|
+
#### 更新日期:2022/8/11
|
|
3
|
+
#### 更新内容:
|
|
4
|
+
* 修复
|
|
5
|
+
* 迭代
|
|
6
|
+
* token存储到cookes的二级域名兼容com.cn/org.cn/net.cn
|
|
7
|
+
* 优化
|
|
8
|
+
|
|
9
|
+
#### 发布版本:0.0.6
|
|
10
|
+
#### 更新日期:2022/8/8
|
|
11
|
+
#### 更新内容:
|
|
12
|
+
* 修复
|
|
13
|
+
* 迭代
|
|
14
|
+
* 优化加密库依赖导入
|
|
15
|
+
* 优化
|
|
16
|
+
|
|
17
|
+
#### 发布版本:0.0.5
|
|
18
|
+
#### 更新日期:2022/8/8
|
|
19
|
+
#### 更新内容:
|
|
20
|
+
* 修复
|
|
21
|
+
* 迭代
|
|
22
|
+
* 优化加密库依赖导入
|
|
23
|
+
* 优化
|
|
24
|
+
|
|
1
25
|
#### 发布版本:0.0.4
|
|
2
26
|
#### 更新日期:2022/8/8
|
|
3
27
|
#### 更新内容:
|
package/lib/ccdk.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Cookies from 'js-cookie';
|
|
2
2
|
import CryptoJS from 'crypto-js/aes';
|
|
3
|
+
import UTF8 from 'crypto-js/enc-utf8';
|
|
4
|
+
import PAD from 'crypto-js/pad-pkcs7';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* 加密
|
|
@@ -9,12 +11,11 @@ import CryptoJS from 'crypto-js/aes';
|
|
|
9
11
|
* @returns
|
|
10
12
|
*/
|
|
11
13
|
function getAesString(data, key, iv) {
|
|
12
|
-
key =
|
|
13
|
-
iv =
|
|
14
|
-
let encrypted = CryptoJS.
|
|
14
|
+
key = UTF8.parse(key);
|
|
15
|
+
iv = UTF8.parse(iv);
|
|
16
|
+
let encrypted = CryptoJS.encrypt(data, key, {
|
|
15
17
|
iv: iv,
|
|
16
|
-
|
|
17
|
-
padding: CryptoJS.pad.Pkcs7,
|
|
18
|
+
padding: PAD,
|
|
18
19
|
});
|
|
19
20
|
return encrypted.toString(); //返回的是base64格式的密文
|
|
20
21
|
}
|
|
@@ -27,14 +28,13 @@ function getAesString(data, key, iv) {
|
|
|
27
28
|
* @returns
|
|
28
29
|
*/
|
|
29
30
|
function getDAesString(encrypted, key, iv) {
|
|
30
|
-
key =
|
|
31
|
-
iv =
|
|
32
|
-
let decrypted = CryptoJS.
|
|
31
|
+
key = UTF8.parse(key);
|
|
32
|
+
iv = UTF8.parse(iv);
|
|
33
|
+
let decrypted = CryptoJS.decrypt(encrypted, key, {
|
|
33
34
|
iv: iv,
|
|
34
|
-
|
|
35
|
-
padding: CryptoJS.pad.Pkcs7,
|
|
35
|
+
padding: PAD,
|
|
36
36
|
});
|
|
37
|
-
return decrypted.toString(
|
|
37
|
+
return decrypted.toString(UTF8);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -74,6 +74,21 @@ var Crypto = /*#__PURE__*/Object.freeze({
|
|
|
74
74
|
decrypt: decrypt
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* 获得一级域名
|
|
79
|
+
* 比如:xx.com、xx.cn、xx.com.cn、xx.net.cn、xx.org.cn
|
|
80
|
+
*/
|
|
81
|
+
function getDomain() {
|
|
82
|
+
// 倒数第二位域名
|
|
83
|
+
let lastTow = document.domain.split('.').slice(-2, -1)[0];
|
|
84
|
+
// 如果倒数第二位是这些关键字,那么需要取倒数三位域名
|
|
85
|
+
if (lastTow == 'com' || lastTow == 'org' || lastTow == 'net') {
|
|
86
|
+
return "." + document.domain.split('.').slice(-3).join('.')
|
|
87
|
+
} else {
|
|
88
|
+
return "." + document.domain.split('.').slice(-2).join('.')
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
77
92
|
// cookie存储标识
|
|
78
93
|
const USER_INFO = "cc_user_info";
|
|
79
94
|
|
|
@@ -82,8 +97,8 @@ const USER_INFO = "cc_user_info";
|
|
|
82
97
|
* @param {String} userInfo 用户信息
|
|
83
98
|
* @param {String} domain 域名
|
|
84
99
|
*/
|
|
85
|
-
function setUserInfo(userInfo, domain) {
|
|
86
|
-
Cookies.set(Crypto.encrypt(USER_INFO), userInfo, { domain: domain
|
|
100
|
+
function setUserInfo(userInfo, domain = getDomain()) {
|
|
101
|
+
Cookies.set(Crypto.encrypt(USER_INFO), Crypto.encrypt(userInfo), { domain: domain, expires: 1 });
|
|
87
102
|
}
|
|
88
103
|
|
|
89
104
|
/**
|
|
@@ -120,7 +135,7 @@ function getUrlQuery(name) {
|
|
|
120
135
|
return res;
|
|
121
136
|
}
|
|
122
137
|
/**
|
|
123
|
-
* 获取token
|
|
138
|
+
* 获取token:优先级-url最高,cc_token-cookies第二,binding-cookies第三
|
|
124
139
|
* @param {String} urlName 获取token的url名称
|
|
125
140
|
* @returns
|
|
126
141
|
*/
|
|
@@ -137,17 +152,17 @@ function getToken(urlName = "binding") {
|
|
|
137
152
|
* @param {String} token token
|
|
138
153
|
* @param {String} domain 域名
|
|
139
154
|
*/
|
|
140
|
-
function setToken(token, domain) {
|
|
155
|
+
function setToken(token, domain = getDomain()) {
|
|
141
156
|
// 开发模式不设置domain
|
|
142
|
-
Cookies.set(Crypto.encrypt(TOKEN), token, { domain: domain
|
|
157
|
+
Cookies.set(Crypto.encrypt(TOKEN), token, { domain: domain, expires: 1 });
|
|
143
158
|
}
|
|
144
159
|
|
|
145
160
|
/**
|
|
146
161
|
* 清除Token数据
|
|
147
162
|
* @param {String} domain 域名
|
|
148
163
|
*/
|
|
149
|
-
function clearToken(domain) {
|
|
150
|
-
Cookies.remove(Crypto.encrypt(TOKEN), { domain: domain
|
|
164
|
+
function clearToken(domain = getDomain()) {
|
|
165
|
+
Cookies.remove(Crypto.encrypt(TOKEN), { domain: domain, expires: 1 });
|
|
151
166
|
}
|
|
152
167
|
|
|
153
168
|
var CCToken = /*#__PURE__*/Object.freeze({
|
package/lib/ccdk.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import Cookies from"js-cookie";import CryptoJS from"crypto-js/aes";function getAesString(data,key,iv){key=
|
|
1
|
+
import Cookies from"js-cookie";import CryptoJS from"crypto-js/aes";import UTF8 from"crypto-js/enc-utf8";import PAD from"crypto-js/pad-pkcs7";function getAesString(data,key,iv){key=UTF8.parse(key);iv=UTF8.parse(iv);let encrypted=CryptoJS.encrypt(data,key,{iv:iv,padding:PAD});return encrypted.toString()}function getDAesString(encrypted,key,iv){key=UTF8.parse(key);iv=UTF8.parse(iv);let decrypted=CryptoJS.decrypt(encrypted,key,{iv:iv,padding:PAD});return decrypted.toString(UTF8)}function encrypt(data,key="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",iv=1){data=JSON.stringify(data);var encrypted=getAesString(data,key,iv);return encrypted}function decrypt(data,key="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",iv=1){try{var decryptedStr=getDAesString(data,key,iv);if(!decryptedStr)return null;return JSON.parse(decryptedStr)}catch(error){console.trace("解密密码错误",error);return null}}var Crypto=Object.freeze({__proto__:null,encrypt:encrypt,decrypt:decrypt});function getDomain(){let lastTow=document.domain.split(".").slice(-2,-1)[0];if(lastTow=="com"||lastTow=="org"||lastTow=="net"){return"."+document.domain.split(".").slice(-3).join(".")}else{return"."+document.domain.split(".").slice(-2).join(".")}}const USER_INFO="cc_user_info";function setUserInfo(userInfo,domain=getDomain()){Cookies.set(Crypto.encrypt(USER_INFO),Crypto.encrypt(userInfo),{domain:domain,expires:1})}function getUserInfo(){let encryptUserInfo=Cookies.get(Crypto.encrypt(USER_INFO));if(encryptUserInfo){return Crypto.decrypt(encryptUserInfo)}else{return""}}var CCUser=Object.freeze({__proto__:null,setUserInfo:setUserInfo,getUserInfo:getUserInfo});const TOKEN="cc_token";function getUrlQuery(name){var reg=new RegExp(name+"=([^&]*)(&|$)");var r=window.location.href.match(reg);let res=null;if(r!=null)res=r[1].trim();return res}function getToken(urlName="binding"){let token=getUrlQuery(urlName)||Cookies.get(Crypto.encrypt(TOKEN))||Cookies.get(urlName);if(token){setToken(token)}return token}function setToken(token,domain=getDomain()){Cookies.set(Crypto.encrypt(TOKEN),token,{domain:domain,expires:1})}function clearToken(domain=getDomain()){Cookies.remove(Crypto.encrypt(TOKEN),{domain:domain,expires:1})}var CCToken=Object.freeze({__proto__:null,setToken:setToken,getToken:getToken,clearToken:clearToken});export{Crypto as CCCrypto,CCToken,CCUser};
|