46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
function checkLicense(is_blank = 1) {
|
|
return new Promise((resolve, reject) => {
|
|
fetch("/api/license/check", {
|
|
method: "GET",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
})
|
|
.then((response) => response.json())
|
|
.then((data) => {
|
|
if (is_blank === 1) {
|
|
// 处理 can_use 逻辑
|
|
if (!data.can_use) {
|
|
needActivate();
|
|
}
|
|
}
|
|
resolve(data);
|
|
})
|
|
.catch((error) => {
|
|
console.error("Request failed", error);
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
function needActivate() {
|
|
if (typeof AndroidInterface !== "undefined") {
|
|
AndroidInterface.sendMessageToAndroid("Need Activate");
|
|
}
|
|
}
|
|
|
|
function useLicense() {
|
|
fetch("/api/license/use", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
})
|
|
.then((response) => response.json())
|
|
.then((data) => {
|
|
console.log("use license:", data);
|
|
})
|
|
.catch((error) => {
|
|
console.error("Request failed", error);
|
|
});
|
|
} |