2026-10-14 13:04:10 +08:00
|
|
|
const DEVICE_ID_KEY = 'jayucloud-salon_device_id'
|
2026-06-24 15:04:17 +08:00
|
|
|
|
|
|
|
|
function createDeviceId() {
|
|
|
|
|
const randomText = Math.random().toString(36).slice(2, 10)
|
|
|
|
|
return `manager-mini-device-${Date.now()}-${randomText}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assertStorageApi() {
|
|
|
|
|
if (typeof wx === 'undefined' || typeof wx.getStorageSync !== 'function' || typeof wx.setStorageSync !== 'function') {
|
|
|
|
|
throw new Error('wx storage API is required to build request signature device id')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function readDeviceId() {
|
|
|
|
|
assertStorageApi()
|
|
|
|
|
return wx.getStorageSync(DEVICE_ID_KEY) || ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function writeDeviceId(value) {
|
|
|
|
|
assertStorageApi()
|
|
|
|
|
wx.setStorageSync(DEVICE_ID_KEY, value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getDeviceId() {
|
|
|
|
|
const current = readDeviceId()
|
|
|
|
|
if (current) {
|
|
|
|
|
return current
|
|
|
|
|
}
|
|
|
|
|
const next = createDeviceId()
|
|
|
|
|
writeDeviceId(next)
|
|
|
|
|
return next
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
getDeviceId
|
|
|
|
|
}
|