wl-design-mobile 0.7.9 → 0.8.1
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/package.json +1 -1
- package/util/jssdk-sczy.js +33 -85
package/package.json
CHANGED
package/util/jssdk-sczy.js
CHANGED
|
@@ -2,48 +2,6 @@ import wx from "weixin-js-sdk";
|
|
|
2
2
|
import config from '../config/config'
|
|
3
3
|
import {axios} from '../util/axios'
|
|
4
4
|
|
|
5
|
-
const SIGNATURE_CACHE_KEY = 'sczy_js_signature_cache'
|
|
6
|
-
const SIGNATURE_CACHE_TTL = 5 * 60 * 1000
|
|
7
|
-
let configPromise = null
|
|
8
|
-
|
|
9
|
-
function getCacheKey(url) {
|
|
10
|
-
return `${SIGNATURE_CACHE_KEY}:${url}`
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getCachedSignature(url) {
|
|
14
|
-
try {
|
|
15
|
-
const raw = sessionStorage.getItem(getCacheKey(url))
|
|
16
|
-
if (!raw) {
|
|
17
|
-
return null
|
|
18
|
-
}
|
|
19
|
-
const cached = JSON.parse(raw)
|
|
20
|
-
if (!cached || !cached.data || !cached.expireAt || Date.now() > cached.expireAt) {
|
|
21
|
-
sessionStorage.removeItem(getCacheKey(url))
|
|
22
|
-
return null
|
|
23
|
-
}
|
|
24
|
-
return cached.data
|
|
25
|
-
} catch (e) {
|
|
26
|
-
sessionStorage.removeItem(getCacheKey(url))
|
|
27
|
-
return null
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function setCachedSignature(url, data) {
|
|
32
|
-
try {
|
|
33
|
-
sessionStorage.setItem(getCacheKey(url), JSON.stringify({
|
|
34
|
-
expireAt: Date.now() + SIGNATURE_CACHE_TTL,
|
|
35
|
-
data,
|
|
36
|
-
}))
|
|
37
|
-
} catch (e) {
|
|
38
|
-
// ignore storage failures
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 判断ios系统版本号是否大于14
|
|
45
|
-
* @returns {boolean}
|
|
46
|
-
*/
|
|
47
5
|
const isIos14AndMore = () => {
|
|
48
6
|
try {
|
|
49
7
|
const str = navigator.userAgent.toLowerCase()
|
|
@@ -58,41 +16,33 @@ const isIos14AndMore = () => {
|
|
|
58
16
|
}
|
|
59
17
|
}
|
|
60
18
|
|
|
61
|
-
function getSczyJsConfig() {
|
|
62
|
-
let url = window.location.href.split('#')[0]
|
|
19
|
+
async function getSczyJsConfig() {
|
|
20
|
+
let url = window.location.href.split('#')[0].toString()
|
|
63
21
|
if (isIos14AndMore()) {
|
|
64
|
-
|
|
65
|
-
if (storedUrl) {
|
|
66
|
-
url = storedUrl
|
|
67
|
-
}
|
|
22
|
+
console.log('[jssdk-sczy] iOS 14+,使用当前页面 URL 参与签名', url)
|
|
68
23
|
}
|
|
69
24
|
|
|
70
|
-
const
|
|
71
|
-
if (cached) {
|
|
72
|
-
return Promise.resolve(cached)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return axios.get(config.platformServerContext + '/api/weixin/js/signature', {
|
|
25
|
+
const resp = await axios.get(config.platformServerContext + '/api/weixin/js/signature', {
|
|
76
26
|
params: { url }
|
|
77
|
-
}).then((resp) => {
|
|
78
|
-
const data = resp && resp.data ? resp.data : {}
|
|
79
|
-
if (!data || data.data.errcode !== 0 || !data.data) {
|
|
80
|
-
throw new Error((data && data.errmsg) ? data.errmsg : '获取签名失败')
|
|
81
|
-
}
|
|
82
|
-
setCachedSignature(url, data.data)
|
|
83
|
-
return data.data
|
|
84
27
|
})
|
|
85
|
-
}
|
|
86
28
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
29
|
+
const signatureData = resp.data
|
|
30
|
+
const errcode = resp.errcode
|
|
31
|
+
const errmsg = resp.errmsg || resp.message
|
|
32
|
+
|
|
33
|
+
if (errcode !== 0) {
|
|
34
|
+
throw new Error(errmsg)
|
|
90
35
|
}
|
|
91
36
|
|
|
92
|
-
|
|
93
|
-
|
|
37
|
+
return signatureData
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function configWx() {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
getSczyJsConfig().then((resp) => {
|
|
94
43
|
wx.config({
|
|
95
|
-
|
|
44
|
+
beta: true,
|
|
45
|
+
debug: true,
|
|
96
46
|
appId: resp.appId,
|
|
97
47
|
timestamp: resp.timestamp,
|
|
98
48
|
nonceStr: resp.nonceStr,
|
|
@@ -105,37 +55,35 @@ function configWx() {
|
|
|
105
55
|
})
|
|
106
56
|
|
|
107
57
|
wx.error((res) => {
|
|
108
|
-
configPromise = null
|
|
109
58
|
reject('企业微信初始化js-sdk失败' + (res && res.errMsg ? res.errMsg : ''))
|
|
110
59
|
})
|
|
60
|
+
}).catch((error) => {
|
|
61
|
+
reject('请求服务端jssdk签名失败:'+error)
|
|
111
62
|
})
|
|
112
|
-
}).catch((error) => {
|
|
113
|
-
configPromise = null
|
|
114
|
-
throw new Error('请求服务端jssdk签名失败:' + error)
|
|
115
63
|
})
|
|
116
|
-
|
|
117
|
-
return configPromise
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function extractScanText(res) {
|
|
121
|
-
if (!res) {
|
|
122
|
-
return ''
|
|
123
|
-
}
|
|
124
|
-
if (typeof res === 'string') {
|
|
125
|
-
return res
|
|
126
|
-
}
|
|
127
|
-
return res.resultStr || res.result || res.text || res.code || ''
|
|
128
64
|
}
|
|
129
65
|
|
|
130
66
|
function scanQRCode() {
|
|
131
67
|
return new Promise((resolve, reject) => {
|
|
132
68
|
configWx().then(() => {
|
|
69
|
+
if (!wx.scanQRCode) {
|
|
70
|
+
reject('当前客户端不支持扫码能力')
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
133
74
|
wx.scanQRCode({
|
|
134
75
|
desc: 'scanQRCode desc',
|
|
135
76
|
needResult: 1,
|
|
136
77
|
scanType: ['qrCode', 'barCode'],
|
|
137
78
|
success: function (res) {
|
|
138
|
-
resolve(
|
|
79
|
+
resolve(res)
|
|
80
|
+
},
|
|
81
|
+
fail: function (res) {
|
|
82
|
+
if (res && res.errMsg && res.errMsg.indexOf('function_not_exist') > -1) {
|
|
83
|
+
reject('版本过低请升级')
|
|
84
|
+
} else {
|
|
85
|
+
reject('企业微信扫码失败,请联系系统管理员!')
|
|
86
|
+
}
|
|
139
87
|
},
|
|
140
88
|
error: function (res) {
|
|
141
89
|
if (res && res.errMsg && res.errMsg.indexOf('function_not_exist') > -1) {
|