function cached(callback) {
let value, isCalled = false;
return function () {
if (!isCalled) {
value = callback.apply(this, arguments);
isCalled = true;
}
return value;
}
}
function generateUUID() {
let d = new Date().getTime();
const seconds = timestamp() - 946656000;
console.log(seconds)
let daysStr = Math.floor(seconds / 86400).toString(16);
let uuid = ('xxxx-yxxx-' + daysStr + '-8xxx-yx').replace(/[xy]/g, function (c) {
let r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
let v = (c === 'x' ? r : (r & 0x3 | 0x8));
return v.toString(16);
});
let sum = 0;
const splits = uuid.split('-');
for (let i = 0; i < splits.length; i++) {
sum += parseInt(splits[i], 16);
}
return (uuid + (sum % 256).toString(16)).toUpperCase();
}
const getClientID = cached(function () {
const STORAGE_KEY = "uuid";
let uuid = '';
if (!uuid) {
uuid = generateUUID();
console.log(1,uuid)
// setStorageSync(STORAGE_KEY, uuid);
}
return uuid;
})
function timestamp(time = undefined) {
return Math.floor(((time ? new Date(time) : new Date) - 0) / 1000);
}
console.log(getClientID())
console