xctc-utils 1.6.68 → 1.6.70
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/canvas/index.js +202 -216
- package/dist/crypto/index.js +20 -16
- package/dist/event/changed.js +13 -13
- package/dist/event/drop.js +6 -6
- package/dist/event/index.js +5 -5
- package/dist/event/mouse-down.js +6 -6
- package/dist/event/mouse-move.js +6 -6
- package/dist/event/mouse-up.js +8 -8
- package/dist/event/mouse-wheel.js +2 -2
- package/dist/format/index.js +1 -1
- package/dist/handle/create.js +84 -60
- package/dist/handle/index.js +9 -9
- package/dist/handle/query.js +22 -22
- package/dist/handle/register.js +3 -3
- package/dist/handle/update.js +17 -17
- package/dist/iframe/index.js +30 -30
- package/dist/index.js +29 -24
- package/dist/is/has.js +2 -2
- package/dist/is/index.js +4 -4
- package/dist/modal/index.js +32 -23
- package/dist/params/index.js +59 -59
- package/dist/storage/index.js +4 -4
- package/dist/test.js +3 -3
- package/dist/time/index.js +32 -32
- package/dist/update/index.d.ts +1 -0
- package/dist/update/index.js +48 -0
- package/dist/utils.js +29 -29
- package/dist/weixin/index.d.ts +1 -0
- package/dist/weixin/index.js +109 -106
- package/package.json +3 -2
- package/tsconfig.json +1 -1
package/dist/weixin/index.js
CHANGED
|
@@ -23,28 +23,28 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.onlinePay = exports.shareReady = exports.configReady = exports.getCode = exports.envSDK = exports.getUrlCode = exports.loadWeiXinSDK = void 0;
|
|
26
|
+
exports.onlinePay = exports.shareReady = exports.configReady = exports.getCode = exports.envSDK = exports.getUrlCode = exports.initWeixinConfig = exports.loadWeiXinSDK = void 0;
|
|
27
27
|
// import * as weixin from 'weixin-js-sdk' // 引入微信SDK
|
|
28
28
|
// const weixin = require("weixin-js-sdk")
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
const utils_1 = require("../utils");
|
|
30
|
+
const crypto_1 = require("../crypto");
|
|
31
|
+
const params = __importStar(require("../params"));
|
|
32
|
+
const is_1 = require("../is");
|
|
33
|
+
const index_1 = require("../storage/index");
|
|
34
|
+
const utils_2 = require("../utils");
|
|
35
|
+
const w = window;
|
|
36
|
+
const loc = w.location;
|
|
37
|
+
const defaultKey = "5uMz4R8r0926DkC8";
|
|
38
|
+
const defaultIv = "5uMz4R8r0926DkC8";
|
|
39
39
|
var weixinConfig = {};
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
let weixinUrl = "https://res.wx.qq.com/open/js/jweixin-1.6.0.js";
|
|
41
|
+
let weixinJsSource = "";
|
|
42
42
|
function loadWeiXinSDK(url, callback) {
|
|
43
|
-
|
|
43
|
+
const win = window;
|
|
44
44
|
if (url) {
|
|
45
45
|
weixinUrl = url;
|
|
46
46
|
}
|
|
47
|
-
(0, utils_2.loadScript)(weixinUrl,
|
|
47
|
+
(0, utils_2.loadScript)(weixinUrl, () => {
|
|
48
48
|
weixinJsSource = (win === null || win === void 0 ? void 0 : win.wx) || "";
|
|
49
49
|
if (typeof callback === "function") {
|
|
50
50
|
callback();
|
|
@@ -52,39 +52,35 @@ function loadWeiXinSDK(url, callback) {
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
exports.loadWeiXinSDK = loadWeiXinSDK;
|
|
55
|
-
function
|
|
55
|
+
function initWeixinConfig(config) {
|
|
56
56
|
var _a;
|
|
57
|
-
if (!(0, utils_1.weixinBrowser)()) {
|
|
58
|
-
console.error("非微信环境下,该函数将终止执行!");
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
57
|
config = config || {};
|
|
62
|
-
|
|
58
|
+
let appId = (config === null || config === void 0 ? void 0 : config.appId) || "";
|
|
63
59
|
if (!appId)
|
|
64
60
|
return;
|
|
65
61
|
weixinConfig = config;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
let scope = (config === null || config === void 0 ? void 0 : config.scope) || "snsapi_userinfo";
|
|
63
|
+
let codeKey = (config === null || config === void 0 ? void 0 : config.codeKey) || "weixinAuthCode";
|
|
64
|
+
let stateKey = (config === null || config === void 0 ? void 0 : config.stateKey) || "weixinAuthState";
|
|
69
65
|
weixinConfig['scope'] = scope;
|
|
70
66
|
weixinConfig['codeKey'] = codeKey;
|
|
71
67
|
weixinConfig['stateKey'] = stateKey;
|
|
72
68
|
(0, index_1.useSessionStorage)("weixinConfig", weixinConfig);
|
|
73
|
-
|
|
69
|
+
let { cryptoiv = defaultIv, cryptokey = defaultKey, debuggerStatus = false } = weixinConfig;
|
|
74
70
|
initSdk(); // 加载微信sdk环境
|
|
75
71
|
// 默认第一次通过链接进入系统,没有code和state
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
let codeIndex = -1;
|
|
73
|
+
let stateIndex = -1;
|
|
74
|
+
let msgStr = "";
|
|
75
|
+
let isAuth = false; // 是否完成 code 授权
|
|
76
|
+
let search = loc.search; // ?code=0916SzFa1KH9TA0Ke7Ha1AQx6446SzFr&state=123
|
|
81
77
|
if (search) {
|
|
82
78
|
codeIndex = search.indexOf("code=");
|
|
83
79
|
stateIndex = search.indexOf("state=");
|
|
84
80
|
isAuth = search.includes("state=state");
|
|
85
81
|
}
|
|
86
82
|
// 获取地址栏返回 code 参数值
|
|
87
|
-
|
|
83
|
+
const localParamsData = (0, index_1.getSessionStorage)("urlParamsData") || "";
|
|
88
84
|
// 本地未存储微信授权 code 值, 并且地址栏携带有 code 值 ,则先存储该值
|
|
89
85
|
if (codeIndex != -1 && isAuth) {
|
|
90
86
|
params.get({ keys: ['code'], cache: "session", key: cryptokey, iv: cryptoiv });
|
|
@@ -107,8 +103,8 @@ function getUrlCode(config) {
|
|
|
107
103
|
}
|
|
108
104
|
else {
|
|
109
105
|
// 当前系统本地没有存储 code,流程为用户只需微信授权登录后返回系统,此时通过 CODE 执行微信登录
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
const urlParamsData = (0, index_1.getSessionStorage)("urlParamsData") || "";
|
|
107
|
+
const codeData = ((_a = urlParamsData === null || urlParamsData === void 0 ? void 0 : urlParamsData.code) === null || _a === void 0 ? void 0 : _a.str) || ""; // 第一次进入系统为空
|
|
112
108
|
login(codeData);
|
|
113
109
|
}
|
|
114
110
|
return;
|
|
@@ -130,6 +126,16 @@ function getUrlCode(config) {
|
|
|
130
126
|
return getCode();
|
|
131
127
|
}
|
|
132
128
|
}
|
|
129
|
+
exports.initWeixinConfig = initWeixinConfig;
|
|
130
|
+
function getUrlCode(config) {
|
|
131
|
+
if (!(0, utils_1.weixinBrowser)()) {
|
|
132
|
+
console.error("非微信环境下,该函数将终止执行!");
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
loadWeiXinSDK("", () => {
|
|
136
|
+
initWeixinConfig(config);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
133
139
|
exports.getUrlCode = getUrlCode;
|
|
134
140
|
function cryptoConfig(key, iv) {
|
|
135
141
|
if (!key)
|
|
@@ -143,8 +149,7 @@ function cryptoConfig(key, iv) {
|
|
|
143
149
|
}
|
|
144
150
|
// 执行微信登录
|
|
145
151
|
function login(code) {
|
|
146
|
-
|
|
147
|
-
var appId = weixinConfig.appId, http = weixinConfig.http, redirectUri = weixinConfig.redirectUri, _b = weixinConfig.appIdKey, appIdKey = _b === void 0 ? "app_id" : _b, _c = weixinConfig.jsCodeKey, jsCodeKey = _c === void 0 ? "js_code" : _c, _d = weixinConfig.cb, cb = _d === void 0 ? "" : _d, _e = weixinConfig.debuggerStatus, debuggerStatus = _e === void 0 ? false : _e;
|
|
152
|
+
let { appId, http, redirectUri, appIdKey = "app_id", jsCodeKey = "js_code", cb = "", debuggerStatus = false } = weixinConfig;
|
|
148
153
|
if (debuggerStatus) {
|
|
149
154
|
alert("地址栏携带code已完成本地存储 ,执行微信授权逻辑");
|
|
150
155
|
}
|
|
@@ -160,17 +165,17 @@ function login(code) {
|
|
|
160
165
|
console.error("未正常传入微信授权登录http函数");
|
|
161
166
|
return;
|
|
162
167
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
let obj = {
|
|
169
|
+
[appIdKey]: appId,
|
|
170
|
+
[jsCodeKey]: code
|
|
171
|
+
};
|
|
167
172
|
(0, index_1.useSessionStorage)("loginParams", JSON.stringify(obj));
|
|
168
173
|
// 调试字段 isPassLogin ,为true 时不继续执行微信登录,前端可拿到 code 给后端测试
|
|
169
174
|
// if(weixinConfig['isPassLogin']) return
|
|
170
|
-
weixinConfig === null || weixinConfig === void 0 ? void 0 : weixinConfig.http(obj).then(
|
|
175
|
+
weixinConfig === null || weixinConfig === void 0 ? void 0 : weixinConfig.http(obj).then((res) => {
|
|
171
176
|
var _a;
|
|
172
177
|
(0, index_1.useSessionStorage)("loginRes", res);
|
|
173
|
-
|
|
178
|
+
let code = -1;
|
|
174
179
|
if (res === null || res === void 0 ? void 0 : res.hasOwnProperty("code")) {
|
|
175
180
|
code = res.code;
|
|
176
181
|
}
|
|
@@ -185,7 +190,7 @@ function login(code) {
|
|
|
185
190
|
// 未登录则先执行登录
|
|
186
191
|
return getCode();
|
|
187
192
|
}
|
|
188
|
-
|
|
193
|
+
let data = {};
|
|
189
194
|
if (res === null || res === void 0 ? void 0 : res.hasOwnProperty("data")) {
|
|
190
195
|
data = res.data;
|
|
191
196
|
}
|
|
@@ -196,44 +201,44 @@ function login(code) {
|
|
|
196
201
|
console.error("http响应数据格式必须是:res:{code:xx,data:{}}");
|
|
197
202
|
return;
|
|
198
203
|
}
|
|
199
|
-
for (
|
|
200
|
-
|
|
204
|
+
for (let key in data) {
|
|
205
|
+
let item = data[key];
|
|
201
206
|
if (item instanceof Object) {
|
|
202
207
|
item = JSON.stringify(item);
|
|
203
208
|
}
|
|
204
209
|
(0, index_1.useSessionStorage)(key, item);
|
|
205
210
|
(0, index_1.useLocalStorage)(key, item);
|
|
206
211
|
}
|
|
207
|
-
|
|
212
|
+
let url = loc.origin;
|
|
208
213
|
if (redirectUri) {
|
|
209
214
|
url = encodeURIComponent(redirectUri);
|
|
210
215
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
216
|
+
const hashVal = loc.hash;
|
|
217
|
+
const urlParamsData = (0, index_1.getSessionStorage)("urlParamsData") || "";
|
|
218
|
+
const stateData = ((_a = urlParamsData === null || urlParamsData === void 0 ? void 0 : urlParamsData.state) === null || _a === void 0 ? void 0 : _a.data) || ""; // 默认有值,链接携带
|
|
219
|
+
let str = "";
|
|
215
220
|
if ((0, is_1.isObject)(stateData)) {
|
|
216
|
-
for (
|
|
221
|
+
for (let key in stateData) {
|
|
217
222
|
if (key == "path") {
|
|
218
223
|
if (stateData[key][0] == "/") {
|
|
219
|
-
url =
|
|
224
|
+
url = `${url}/#${stateData.path}`;
|
|
220
225
|
}
|
|
221
226
|
else {
|
|
222
|
-
url =
|
|
227
|
+
url = `${url}/#/${stateData.path}`;
|
|
223
228
|
}
|
|
224
229
|
}
|
|
225
230
|
else {
|
|
226
|
-
str +=
|
|
231
|
+
str += `${key}=${stateData[key]}&`;
|
|
227
232
|
}
|
|
228
233
|
}
|
|
229
234
|
if (stateData === null || stateData === void 0 ? void 0 : stateData.path) {
|
|
230
235
|
if (str) {
|
|
231
|
-
url =
|
|
236
|
+
url = `${url}?${str}`;
|
|
232
237
|
}
|
|
233
238
|
}
|
|
234
239
|
}
|
|
235
240
|
else if (hashVal) {
|
|
236
|
-
url =
|
|
241
|
+
url = `${url}/${hashVal}`;
|
|
237
242
|
}
|
|
238
243
|
if (weixinConfig['isPassLogin']) {
|
|
239
244
|
console.log("不执行跳转操作");
|
|
@@ -246,7 +251,7 @@ function login(code) {
|
|
|
246
251
|
loc.replace(url);
|
|
247
252
|
}
|
|
248
253
|
}
|
|
249
|
-
}).catch(
|
|
254
|
+
}).catch((err) => {
|
|
250
255
|
(0, index_1.useSessionStorage)("loginError", err);
|
|
251
256
|
});
|
|
252
257
|
}
|
|
@@ -255,21 +260,20 @@ function login(code) {
|
|
|
255
260
|
* 获取地址栏中的 search 参数,将参数转换为数组,最终返回地址栏参数数组
|
|
256
261
|
* keys 需要截取字符串开始字符
|
|
257
262
|
*/
|
|
258
|
-
function formatSearch(search, keys) {
|
|
259
|
-
if (search === void 0) { search = ""; }
|
|
263
|
+
function formatSearch(search = "", keys) {
|
|
260
264
|
if (!search)
|
|
261
265
|
return false;
|
|
262
|
-
|
|
266
|
+
let index = search.indexOf(keys);
|
|
263
267
|
search = search.substr(index);
|
|
264
268
|
if (search.startsWith("?")) {
|
|
265
269
|
search = search.substring(1);
|
|
266
270
|
}
|
|
267
|
-
|
|
271
|
+
let urlArr = search.split("&");
|
|
268
272
|
return urlArr;
|
|
269
273
|
}
|
|
270
274
|
// 加载当前微信sdk环境
|
|
271
275
|
function initSdk() {
|
|
272
|
-
|
|
276
|
+
let wx = null;
|
|
273
277
|
if (w.wx && w.wx.ready) {
|
|
274
278
|
wx = w.wx;
|
|
275
279
|
}
|
|
@@ -286,14 +290,14 @@ function initSdk() {
|
|
|
286
290
|
}
|
|
287
291
|
// 返回微信环境 sdk
|
|
288
292
|
function envSDK() {
|
|
289
|
-
|
|
293
|
+
const env = initSdk() || {};
|
|
290
294
|
return env;
|
|
291
295
|
}
|
|
292
296
|
exports.envSDK = envSDK;
|
|
293
297
|
// 前往微信授权登录页面
|
|
294
298
|
function getCode(appId, scope) {
|
|
295
299
|
if ((0, utils_1.weixinBrowser)()) {
|
|
296
|
-
|
|
300
|
+
let id = "";
|
|
297
301
|
if (weixinConfig['appId']) {
|
|
298
302
|
id = weixinConfig['appId'];
|
|
299
303
|
}
|
|
@@ -304,20 +308,20 @@ function getCode(appId, scope) {
|
|
|
304
308
|
console.log("调用跳转微信授权方法时getCode,请传入参数:appId");
|
|
305
309
|
return;
|
|
306
310
|
}
|
|
307
|
-
|
|
311
|
+
let scopeVal = "snsapi_userinfo";
|
|
308
312
|
if (weixinConfig['scope']) {
|
|
309
313
|
scopeVal = weixinConfig.scope;
|
|
310
314
|
}
|
|
311
315
|
else if (scope) {
|
|
312
316
|
scopeVal = scope;
|
|
313
317
|
}
|
|
314
|
-
|
|
318
|
+
let uri = encodeURIComponent(loc.origin);
|
|
315
319
|
if (weixinConfig['redirectUri']) {
|
|
316
320
|
uri = encodeURIComponent(weixinConfig.redirectUri);
|
|
317
321
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
322
|
+
let base = "https://open.weixin.qq.com/connect/oauth2/authorize?";
|
|
323
|
+
let config = `appid=${id}&redirect_uri=${uri}&response_type=code&scope=${scopeVal}&state=state#wechat_redirect`;
|
|
324
|
+
let wxJumpURL = base + config;
|
|
321
325
|
loc.replace(wxJumpURL);
|
|
322
326
|
}
|
|
323
327
|
else {
|
|
@@ -326,20 +330,20 @@ function getCode(appId, scope) {
|
|
|
326
330
|
}
|
|
327
331
|
}
|
|
328
332
|
exports.getCode = getCode;
|
|
329
|
-
|
|
333
|
+
const defaultJsApiList = [
|
|
330
334
|
'updateAppMessageShareData', 'updateTimelineShareData', "onMenuShareWeibo", "onMenuShareQZone", "startRecord", "stopRecord", "closeWindow", "scanQRCode", "chooseWXPay", "chooseCard", "openCard",
|
|
331
335
|
"onVoiceRecordEnd", "playVoice", "pauseVoice", "stopVoice", "onVoicePlayEnd", "uploadVoice", "downloadVoice", "chooseImage", "previewImage", "uploadImage", "openProductSpecificView", "addCard",
|
|
332
336
|
"downloadImage", "translateVoice", "getNetworkType", "openLocation", "getLocation", "hideOptionMenu", "showOptionMenu", "hideMenuItems", "showMenuItems", "hideAllNonBaseMenuItem", "showAllNonBaseMenuItem",
|
|
333
337
|
];
|
|
334
|
-
|
|
338
|
+
const defaultOpenTagList = [
|
|
335
339
|
"wx-open-subscribe", "wx-open-launch-app", "wx-open-launch-weapp",
|
|
336
340
|
"wx-open-audio"
|
|
337
341
|
];
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
342
|
+
const isContinue = (dataType) => {
|
|
343
|
+
const localCodeData = (0, index_1.getSessionStorage)("urlParamsData") || "";
|
|
344
|
+
let wxInfo = (0, index_1.getLocalStorage)("WxInfo") || "";
|
|
345
|
+
let search = loc.search; // ?code=0916SzFa1KH9TA0Ke7Ha1AQx6446SzFr&state=123
|
|
346
|
+
let codeIndex = -1;
|
|
343
347
|
if (search) {
|
|
344
348
|
codeIndex = search.indexOf("code=");
|
|
345
349
|
}
|
|
@@ -360,33 +364,32 @@ var isContinue = function (dataType) {
|
|
|
360
364
|
}
|
|
361
365
|
};
|
|
362
366
|
function configReady(config) {
|
|
363
|
-
var _a;
|
|
364
367
|
if (!isContinue(config === null || config === void 0 ? void 0 : config.dataType)) {
|
|
365
368
|
console.error("还未执行微信登录流程");
|
|
366
369
|
return;
|
|
367
370
|
}
|
|
368
|
-
|
|
371
|
+
const { appId, url, urlKey = "url", appIdKey = "appId", cb, jsApiList = [], openTagList = [], http = "" } = config || {};
|
|
369
372
|
if (!http)
|
|
370
373
|
return;
|
|
371
|
-
|
|
374
|
+
let currentUrl = loc.origin;
|
|
372
375
|
if (url) {
|
|
373
376
|
currentUrl = url;
|
|
374
377
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
378
|
+
let param = {
|
|
379
|
+
[urlKey]: currentUrl,
|
|
380
|
+
[appIdKey]: appId,
|
|
381
|
+
};
|
|
382
|
+
let jsApiListData = defaultJsApiList;
|
|
383
|
+
let openTagListData = defaultOpenTagList;
|
|
381
384
|
if (jsApiList === null || jsApiList === void 0 ? void 0 : jsApiList.length) {
|
|
382
385
|
jsApiListData = jsApiListData;
|
|
383
386
|
}
|
|
384
387
|
if (openTagList === null || openTagList === void 0 ? void 0 : openTagList.length) {
|
|
385
388
|
openTagListData = openTagList;
|
|
386
389
|
}
|
|
387
|
-
config.http(param).then(
|
|
390
|
+
config.http(param).then((res) => {
|
|
388
391
|
if (res) {
|
|
389
|
-
|
|
392
|
+
let data = {};
|
|
390
393
|
if (res === null || res === void 0 ? void 0 : res.hasOwnProperty("data")) {
|
|
391
394
|
data = res.data;
|
|
392
395
|
}
|
|
@@ -397,15 +400,15 @@ function configReady(config) {
|
|
|
397
400
|
console.error("http响应数据格式必须是:res:{data:{appid:xx,timestamp:xx,noncestr:xx,signature:xx}}");
|
|
398
401
|
return;
|
|
399
402
|
}
|
|
400
|
-
for (
|
|
401
|
-
|
|
403
|
+
for (let key in data) {
|
|
404
|
+
const newKey = key.toLowerCase();
|
|
402
405
|
data[newKey] = data[key];
|
|
403
406
|
}
|
|
404
407
|
if (!(data === null || data === void 0 ? void 0 : data.appid)) {
|
|
405
408
|
console.error("后端响应的data数据中缺乏appid或者appId或者AppId字段!");
|
|
406
409
|
return;
|
|
407
410
|
}
|
|
408
|
-
|
|
411
|
+
let obj = {
|
|
409
412
|
jsApiList: jsApiListData,
|
|
410
413
|
openTagList: openTagListData,
|
|
411
414
|
debug: false,
|
|
@@ -414,7 +417,7 @@ function configReady(config) {
|
|
|
414
417
|
nonceStr: data === null || data === void 0 ? void 0 : data.noncestr,
|
|
415
418
|
signature: data === null || data === void 0 ? void 0 : data.signature, //必填,生成的签名
|
|
416
419
|
};
|
|
417
|
-
|
|
420
|
+
const wx = initSdk();
|
|
418
421
|
console.log("wx.config.data:", obj);
|
|
419
422
|
wx.config(obj);
|
|
420
423
|
wx.ready(function (res) {
|
|
@@ -434,27 +437,27 @@ function shareReady(options) {
|
|
|
434
437
|
console.error("还未执行微信登录流程");
|
|
435
438
|
return;
|
|
436
439
|
}
|
|
437
|
-
|
|
440
|
+
let title = "微信分享标题";
|
|
438
441
|
if (options['title'])
|
|
439
442
|
title = options.title;
|
|
440
|
-
|
|
443
|
+
let desc = "微信分享描述";
|
|
441
444
|
if (options['desc'])
|
|
442
445
|
desc = options.desc;
|
|
443
|
-
|
|
446
|
+
let link = loc.origin;
|
|
444
447
|
if (options['link'])
|
|
445
448
|
link = options.link;
|
|
446
|
-
|
|
449
|
+
let imgUrl = "";
|
|
447
450
|
if (options['imgUrl'])
|
|
448
451
|
imgUrl = options.imgUrl;
|
|
449
452
|
if (options && typeof options == "object") {
|
|
450
|
-
|
|
453
|
+
let state = "";
|
|
451
454
|
if (options['data']) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
455
|
+
let data = options.data;
|
|
456
|
+
const key = options['key'] || defaultKey;
|
|
457
|
+
const iv = options['iv'] || defaultIv;
|
|
458
|
+
const cryptoObj = cryptoConfig(key, iv);
|
|
456
459
|
state = (0, crypto_1.encrypt)(data, cryptoObj.key, cryptoObj.iv);
|
|
457
|
-
link =
|
|
460
|
+
link = `${link}?state=${state}`;
|
|
458
461
|
}
|
|
459
462
|
}
|
|
460
463
|
if (options['shareUrl'])
|
|
@@ -462,7 +465,7 @@ function shareReady(options) {
|
|
|
462
465
|
if (options === null || options === void 0 ? void 0 : options.dbug) {
|
|
463
466
|
alert(JSON.stringify(options));
|
|
464
467
|
}
|
|
465
|
-
|
|
468
|
+
const wx = initSdk();
|
|
466
469
|
(0, index_1.useSessionStorage)("weixinShareUrl", link);
|
|
467
470
|
wx.ready(function () {
|
|
468
471
|
(0, index_1.useSessionStorage)("shareReady", "success");
|
|
@@ -493,7 +496,7 @@ function shareReady(options) {
|
|
|
493
496
|
}
|
|
494
497
|
});
|
|
495
498
|
});
|
|
496
|
-
wx.error(
|
|
499
|
+
wx.error((res) => {
|
|
497
500
|
console.log("配置进入错误:", res);
|
|
498
501
|
});
|
|
499
502
|
}
|
|
@@ -503,9 +506,9 @@ function onlinePay(config) {
|
|
|
503
506
|
console.error("还未执行微信登录流程");
|
|
504
507
|
return;
|
|
505
508
|
}
|
|
506
|
-
|
|
509
|
+
const wx = initSdk();
|
|
507
510
|
// let { timeStamp,signType,prepay_id,paySign,package,nonceStr,appId } = params
|
|
508
|
-
|
|
511
|
+
let cb = "";
|
|
509
512
|
if (config['cb'] && typeof config.cb === "function")
|
|
510
513
|
cb = config.cb;
|
|
511
514
|
wx.chooseWXPay({
|
|
@@ -515,7 +518,7 @@ function onlinePay(config) {
|
|
|
515
518
|
signType: config.signType,
|
|
516
519
|
paySign: config.paySign,
|
|
517
520
|
success: function (res) {
|
|
518
|
-
|
|
521
|
+
const obj = {
|
|
519
522
|
status: "success",
|
|
520
523
|
data: res,
|
|
521
524
|
};
|
|
@@ -523,7 +526,7 @@ function onlinePay(config) {
|
|
|
523
526
|
cb(obj);
|
|
524
527
|
},
|
|
525
528
|
cancel: function (cancel) {
|
|
526
|
-
|
|
529
|
+
const obj = {
|
|
527
530
|
status: "cancel",
|
|
528
531
|
data: cancel,
|
|
529
532
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xctc-utils",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.70",
|
|
5
5
|
"description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```\r 时间戳转时间,字符串转时间戳",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
"author": "dyb",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"devDependencies": {
|
|
16
|
+
"@types/crypto-js": "^4.2.2",
|
|
16
17
|
"@types/node": "^18.11.19",
|
|
17
18
|
"typescript": "^4.9.5"
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
20
|
-
|
|
21
|
+
"crypto-js": "^4.2.0"
|
|
21
22
|
},
|
|
22
23
|
"repository": {
|
|
23
24
|
"type": "git",
|