helper.class.js
3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* 定义常用方法类
*/
// 引入组件
import CallApp from 'callapp-lib';
export default class Helper {
// 构造函数
constructor(context) {
// 设置上下文
this.context = context;
}
/**
* 设置唤起App弹窗
* @param {object} param [唤起App定向页面参数]
* @param {function} callback [回调函数]
*/
schemeLayer = function(param, callback) {
// 唤起App操作
function _doApp(callApp, path, param) {
callApp.open({
path: path,
param: param
});
}
// 设置平台固定参数
let path = this.context.isiPhone.value ? "ios-path" : "shop/schemaFilter";
let intentPackage = this.context.mode == "prod" ? "com.cnlive.strike" : "com.cnlive.strike.debug";
let universalHost = this.context.mode == "prod" ? "applelinkstest.cnlive.com" : "applelinkstest.cnlive.com";
// H5唤起App参数
let options = {
scheme: {
protocol: "cnlive"
},
intent: {
package: intentPackage,
scheme: "cnlive"
},
universal: {
host: universalHost + "/app_store.html",
pathKey: "page"
},
appstore: "https://sj.qq.com/myapp/detail.htm?apkName=com.cnlive.strike",
yingyongbao: "https://sj.qq.com/myapp/detail.htm?apkName=com.cnlive.strike",
fallback: "http://wjjh5.cnlive.com/apkdownload.php"
}
// 实例化对象
let callApp = new CallApp(options);
// 回调
if (typeof callback === "function") {
// 点击确定执行数据
let options = {
success: _doApp,
success_params: {
callApp, path, param
}
}
// 回调函数
callback(options);
}
}
/**
* 正则校验URL
* @param {string} strURL [URL地址]
*/
checkURL = function(strURL) {
// 校验参数
if (strURL) {
// 正则
let reg = /(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
// 校验匹配
if (reg.test(strURL)) {
return true;
}
}
return false;
}
/* 加密/解密算法 开始 */
/**
* 加密算法
* @param {string} word [原文]
*/
encrypt = function(word) {
let CryptoJS = require("crypto-js/crypto-js");
// KEY和IV
const KEY = CryptoJS.enc.Utf8.parse("cnlive!$@cnlive_");
const IV = CryptoJS.enc.Utf8.parse("yrEpH8Nx6umBLc1f");
// 明文编码
let srcs = CryptoJS.enc.Utf8.parse(word);
// crypt加密
var encrypted = CryptoJS.AES.encrypt(srcs, KEY, {
iv: IV,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
/**
* 解密算法
* @param {string} word [密文]
*/
decrypt = function(word) {
let CryptoJS = require("crypto-js/crypto-js");
// KEY和IV
const KEY = CryptoJS.enc.Utf8.parse("cnlive!$@cnlive_");
const IV = CryptoJS.enc.Utf8.parse("yrEpH8Nx6umBLc1f");
let srcs = word;
// let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
// let srcs = CryptoJS.enc.Base64.stringify(word);
let decrypt = CryptoJS.AES.decrypt(srcs, KEY, { iv: IV, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
return decryptedStr.toString();
}
/* 加密/解密算法 结束 */
}