xctc-utils 1.3.3 → 1.3.4
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 +28 -25
- package/package.json +1 -1
package/dist/weixin/index.js
CHANGED
|
@@ -12,20 +12,19 @@ var defaultKey = "5uMz4R8rop26DkC8";
|
|
|
12
12
|
var defaultIv = "5uMz4Rsd0926DkC8";
|
|
13
13
|
var weixinConfig = {};
|
|
14
14
|
function weixinUrlCode(config) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var appId = (_a = config === null || config === void 0 ? void 0 : config.appId) !== null && _a !== void 0 ? _a : "";
|
|
15
|
+
config = config || {};
|
|
16
|
+
var appId = config['appId'] || "";
|
|
18
17
|
if (!appId)
|
|
19
18
|
return;
|
|
20
19
|
weixinConfig = config;
|
|
21
|
-
var scope =
|
|
22
|
-
var codeKey =
|
|
23
|
-
var stateKey =
|
|
20
|
+
var scope = config['scope'] || "snsapi_userinfo";
|
|
21
|
+
var codeKey = config['codeKey'] || "weixinCode";
|
|
22
|
+
var stateKey = config['stateKey'] || "weixinState";
|
|
24
23
|
weixinConfig['scope'] = scope;
|
|
25
24
|
weixinConfig['codeKey'] = codeKey;
|
|
26
25
|
weixinConfig['stateKey'] = stateKey;
|
|
27
26
|
(0, index_1.useSessionStorage)("weixinConfig", weixinConfig);
|
|
28
|
-
var
|
|
27
|
+
var _a = weixinConfig.cryptoiv, cryptoiv = _a === void 0 ? "" : _a, _b = weixinConfig.cryptokey, cryptokey = _b === void 0 ? "" : _b;
|
|
29
28
|
var search = loc.search; // ?code=0916SzFa1KH9TA0Ke7Ha1AQx6446SzFr&state=123
|
|
30
29
|
// 获取地址栏返回 code 参数
|
|
31
30
|
var localCode = "";
|
|
@@ -119,14 +118,14 @@ function weixinLogin(code) {
|
|
|
119
118
|
return;
|
|
120
119
|
(0, index_1.useSessionStorage)("weixinLoginParams", JSON.stringify(obj));
|
|
121
120
|
// 调试字段 isPassLogin ,为true 时不继续执行微信登录,前端可拿到 code 给后端测试
|
|
122
|
-
if (weixinConfig
|
|
121
|
+
if (weixinConfig['isPassLogin'])
|
|
123
122
|
return;
|
|
124
123
|
weixinConfig.http(obj).then(function (res) {
|
|
125
124
|
if (res.code == 40163) {
|
|
126
125
|
// 未登录则先执行登录
|
|
127
126
|
return weixinCode();
|
|
128
127
|
}
|
|
129
|
-
var data = res
|
|
128
|
+
var data = res['data'] || {};
|
|
130
129
|
for (var key in data) {
|
|
131
130
|
var item = data[key];
|
|
132
131
|
if (item instanceof Object) {
|
|
@@ -192,11 +191,13 @@ function weixinInit() {
|
|
|
192
191
|
return wx;
|
|
193
192
|
}
|
|
194
193
|
function weixinCode() {
|
|
195
|
-
var _a;
|
|
196
194
|
if ((0, utils_1.weixinBrowser)()) {
|
|
197
195
|
if (!weixinConfig['appId'])
|
|
198
196
|
return;
|
|
199
|
-
var scope =
|
|
197
|
+
var scope = "snsapi_userinfo";
|
|
198
|
+
if (weixinConfig['scope']) {
|
|
199
|
+
scope = weixinConfig.scope;
|
|
200
|
+
}
|
|
200
201
|
var base = "https://open.weixin.qq.com/connect/oauth2/authorize?";
|
|
201
202
|
var uri = encodeURIComponent(loc.href.split("?")[0]);
|
|
202
203
|
var config = "appid=".concat(weixinConfig.appId, "&redirect_uri=").concat(uri, "&response_type=code&scope=").concat(scope, "&state=state#wechat_redirect");
|
|
@@ -214,8 +215,7 @@ var defaultJsApiList = [
|
|
|
214
215
|
"downloadImage", "translateVoice", "getNetworkType", "openLocation", "getLocation", "hideOptionMenu", "showOptionMenu", "hideMenuItems", "showMenuItems", "hideAllNonBaseMenuItem", "showAllNonBaseMenuItem",
|
|
215
216
|
];
|
|
216
217
|
function weixinShareConfig(config) {
|
|
217
|
-
|
|
218
|
-
if (!(config === null || config === void 0 ? void 0 : config.http))
|
|
218
|
+
if (!config['http'])
|
|
219
219
|
return;
|
|
220
220
|
var url = loc.href.split("#")[0];
|
|
221
221
|
var param = {
|
|
@@ -223,12 +223,12 @@ function weixinShareConfig(config) {
|
|
|
223
223
|
appId: config.appId,
|
|
224
224
|
};
|
|
225
225
|
var jsApiList = defaultJsApiList;
|
|
226
|
-
if (
|
|
226
|
+
if (config && config.jsApiList && config.jsApiList.length) {
|
|
227
227
|
jsApiList = config.jsApiList;
|
|
228
|
+
}
|
|
228
229
|
config.http(param).then(function (res) {
|
|
229
|
-
var _a;
|
|
230
230
|
if (res.code == 0) {
|
|
231
|
-
var data =
|
|
231
|
+
var data = res['data'] || {};
|
|
232
232
|
var wx = weixinInit();
|
|
233
233
|
wx.config({
|
|
234
234
|
debug: false,
|
|
@@ -241,7 +241,7 @@ function weixinShareConfig(config) {
|
|
|
241
241
|
wx.ready(function (res) {
|
|
242
242
|
console.log("加载微信分享配置完成:", res);
|
|
243
243
|
(0, index_1.useSessionStorage)("weixinShareConfigSuccess", "\u52A0\u8F7D\u5FAE\u4FE1\u5206\u4EAB\u914D\u7F6E\u5B8C\u6210\uFF1A".concat(res));
|
|
244
|
-
if (
|
|
244
|
+
if (config['cb'] && typeof config.cb === "function")
|
|
245
245
|
config.cb();
|
|
246
246
|
});
|
|
247
247
|
wx.error(function (err) {
|
|
@@ -252,23 +252,26 @@ function weixinShareConfig(config) {
|
|
|
252
252
|
}
|
|
253
253
|
exports.weixinShareConfig = weixinShareConfig;
|
|
254
254
|
function weixinShareInit(options) {
|
|
255
|
-
var title = "
|
|
256
|
-
if (options
|
|
255
|
+
var title = "微信分享标题";
|
|
256
|
+
if (options['title'])
|
|
257
257
|
title = options.title;
|
|
258
258
|
var desc = "微信分享描述";
|
|
259
|
-
if (options
|
|
259
|
+
if (options['desc'])
|
|
260
260
|
desc = options.desc;
|
|
261
261
|
var link = loc.origin;
|
|
262
|
-
if (options
|
|
262
|
+
if (options['link'])
|
|
263
263
|
link = options.link;
|
|
264
264
|
var imgUrl = "";
|
|
265
|
-
if (options
|
|
265
|
+
if (options['imgUrl'])
|
|
266
266
|
imgUrl = options.imgUrl;
|
|
267
267
|
if (options && typeof options == "object") {
|
|
268
268
|
var state = "";
|
|
269
|
-
if (options
|
|
269
|
+
if (options['data']) {
|
|
270
270
|
var data = options.data;
|
|
271
|
-
|
|
271
|
+
var key = options['key'] || defaultKey;
|
|
272
|
+
var iv = options['iv'] || defaultIv;
|
|
273
|
+
var cryptoObj = cryptoConfig(key, iv);
|
|
274
|
+
state = (0, crypto_1.encrypt)(data, cryptoObj.key, cryptoObj.iv);
|
|
272
275
|
link = "".concat(link, "?state=").concat(state);
|
|
273
276
|
}
|
|
274
277
|
}
|
|
@@ -312,7 +315,7 @@ function weixinPay(config) {
|
|
|
312
315
|
var wx = weixinInit();
|
|
313
316
|
// let { timeStamp,signType,prepay_id,paySign,package,nonceStr,appId } = params
|
|
314
317
|
var cb = "";
|
|
315
|
-
if (
|
|
318
|
+
if (config['cb'] && typeof config.cb === "function")
|
|
316
319
|
cb = config.cb;
|
|
317
320
|
wx.chooseWXPay({
|
|
318
321
|
timestamp: config.timeStamp,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xctc-utils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
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",
|