增加token校验

This commit is contained in:
2025-12-01 16:08:09 +08:00
parent 9415af337c
commit 0c80c0dc48
3 changed files with 126 additions and 8 deletions

View File

@@ -1451,12 +1451,13 @@
<div class="fourquestion fourquestionmain">
<div class='question mainauestion' data-value='分析这个场站' data-pre-value="详细分析这个光伏场站,根据图片给出详细的运维方案"><img
src="./img/1.png" alt="">分析这个场站</div>
<div class='question mainauestion' data-value='详细的割草计划' data-pre-value="如果这个光伏场站需要割草怎么做,给出一份详细的计划"><img
src="./img/3.png" alt="">详细的割草计划</div>
<div class='question mainauestion' data-value='详细的清洗计划' data-pre-value="如果这个光伏场站需要用无人机清洗怎么做,给出一份详细的计划"><img
src="./img/4.png" alt="">详细的清洗计划</div>
<div class='question mainauestion' data-value='详细的巡检计划' data-pre-value="如果这个光伏场站需要巡检怎么做,给出一份详细的计划"><img
src="./img/2.png" alt="">详细的巡检计划</div>
<div class='question mainauestion' data-value='详细的割草计划' data-pre-value="如果这个光伏场站需要割草怎么做,给出一份详细的计划"><img
src="./img/3.png" alt="">详细的割草计划</div>
@@ -1591,6 +1592,7 @@
<script>
// document.addEventListener('DOMContentLoaded', function () {
const sidebar = document.getElementById("sidebar");
@@ -1617,6 +1619,16 @@
const encodedUserId = params.get("userId");
const from = params.get("from");
let token= params.get("token");//app的token
let localtoken= params.get("localtoken");//公众号的localtoken
// app会得到token;
// 手机端会验证token
if ((!getCookie("token")|| localtoken!= getCookie("token")) && isMobile()&&!token) {
window.location.href = './middle.html';
}
// ✅ 先 URL 解码,再 Base64 解码,再 UTF-8 解码
@@ -1887,9 +1899,16 @@
if (match) return decodeURIComponent(match[2]);
return null;
}
function deleteCookie(name) {
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
function deleteCookie(name, domain) {
if (domain) {
// 删除指定域名下的 cookie
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=${domain}`;
} else {
// 删除当前域下的 cookie(兼容旧写法)
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
}
}
function handleBack() {
RPJavaFragmentInterface.navigateTo("StatusFragment");
@@ -1904,6 +1923,7 @@
}
function logout() {
deleteCookie('userId');
deleteCookie("ai-Token", "ai.satabot.com")
window.location.href = 'http://ri.satabot.com/#/login?goRemote=1&clear=1';
}
@@ -2131,7 +2151,7 @@
shareSpan.onmouseleave = () => shareSpan.style.opacity = "0.75";
shareSpan.innerHTML = `
<svg t="1764059839985" class="icon" viewBox="0 0 1236 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5667" width="20" height="20"><path d="M741.743 1018.343c-28.287 0-50.917-11.315-73.547-28.288-22.63-22.63-39.602-50.917-39.602-84.862V792.044c-124.464 0-328.133 33.945-435.624 181.039-16.973 28.287-56.575 45.26-90.52 50.917H85.478C28.903 1012.685-5.042 961.768 0.616 905.193c28.287-243.27 113.15-418.652 260.243-537.458 107.492-84.862 231.956-130.122 367.735-141.437V118.807c0-50.917 22.63-96.177 67.89-113.15C736.086-5.657 781.345 0 815.29 33.945l362.077 367.735c28.288 22.63 45.26 56.574 50.918 96.176 5.657 39.603-5.658 79.205-33.945 107.492-5.658 5.658-11.315 16.972-22.63 22.63l-350.762 356.42c-22.63 22.63-50.918 33.945-79.205 33.945z m-90.52-339.448h90.52v226.298l356.42-367.734 5.658-5.658c5.657-5.657 5.657-16.972 5.657-22.63 0-11.315-5.657-16.972-11.315-22.63l-5.657-5.657-356.42-362.077V333.79l-79.205 5.658c-118.806 0-231.956 39.602-328.132 113.149-113.15 90.519-186.696 237.613-209.326 429.967 141.436-175.382 390.364-203.669 531.8-203.669z" p-id="5668"></path></svg>
<svg t="1764059839985" class="icon" viewBox="0 0 1236 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5667" width="20" height="20"><path d="M741.743 1018.343c-28.287 0-50.917-11.315-73.547-28.288-22.63-22.63-39.602-50.917-39.602-84.862V792.044c-124.464 0-328.133 33.945-435.624 181.039-16.973 28.287-56.575 45.26-90.52 50.917H85.478C28.903 1012.685-5.042 961.768 0.616 905.193c28.287-243.27 113.15-418.652 260.243-537.458 107.492-84.862 231.956-130.122 367.735-141.437V118.807c0-50.917 22.63-96.177 67.89-113.15C736.086-5.657 781.345 0 815.29 33.945l362.077 367.735c28.288 22.63 45.26 56.574 50.918 96.176 5.657 39.603-5.658 79.205-33.945 107.492-5.658 5.658-11.315 16.972-22.63 22.63l-350.762 356.42c-22.63 22.63-50.918 33.945-79.205 33.945z m-90.52-339.448h90.52v226.298l356.42-367.734 5.658-5.658c5.657-5.657 5.657-16.972 5.657-22.63 0-11.315-5.657-16.972-11.315-22.63l-5.657-5.657-356.42-362.077V333.79l-79.205 5.658c-118.806 0-231.956 39.602-328.132 113.149-113.15 90.519-186.696 237.613-209.326 429.967 141.436-175.382 390.364-203.669 531.8-203.669z" p-id="5668" fill="#878895"></path></svg>
`;
shareSpan.onclick = () => {
@@ -2139,6 +2159,35 @@
};
msg.appendChild(shareSpan);
const copySpan = document.createElement("span");
copySpan.style.display = "inline-flex";
copySpan.style.alignItems = "center";
copySpan.style.cursor = "pointer";
copySpan.style.marginTop = "8px";
copySpan.style.marginLeft = "10px";
copySpan.style.opacity = "0.75";
copySpan.style.transition = "opacity .2s";
copySpan.title = "复制内容";
copySpan.onmouseenter = () => copySpan.style.opacity = "1";
copySpan.onmouseleave = () => copySpan.style.opacity = "0.75";
copySpan.innerHTML = `
<svg t="1764549398754" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5335" width="20" height="20"><path d="M639.9 256.3H192.4c-35.2 0-63.9 28.8-63.9 63.9v575.4c0 35.2 28.8 63.9 63.9 63.9h447.5c35.2 0 63.9-28.8 63.9-63.9V320.2c0-35.1-28.8-63.9-63.9-63.9z m0 639.3H192.4V320.2h447.5v575.4z" fill="#878895" p-id="5336"></path><path d="M831.6 64.5H384.1c-35.2 0-63.9 28.8-63.9 63.9v63.9h63.9v-63.9h447.5v575.4h-63.9v63.9h63.9c35.2 0 63.9-28.8 63.9-63.9V128.4c0.1-35.1-28.7-63.9-63.9-63.9z" fill="#878895" p-id="5337"></path></svg>
`;
copySpan.onclick = async () => {
try {
await navigator.clipboard.writeText(content);
copySpan.style.opacity = "1";
showToast("复制成功")
copySpan.title = "复制成功";
setTimeout(() => { copySpan.title = "复制内容"; }, 1200);
} catch (err) {
alert("复制失败,可能不支持 HTTPS 环境以外复制。");
}
};
msg.appendChild(copySpan);
}
// 如果有时间,可以显示
@@ -2428,8 +2477,72 @@
shareSpan.onclick = () => {
generatePoster(aiMsg.content);
};
if (role === "assistant") {
// 分享按钮
const shareSpan = document.createElement("span");
shareSpan.style.display = "inline-flex";
shareSpan.style.alignItems = "center";
shareSpan.style.cursor = "pointer";
shareSpan.style.marginTop = "8px";
shareSpan.style.opacity = "0.75";
shareSpan.style.transition = "opacity .2s";
shareSpan.title = "分享";
shareSpan.onmouseenter = () => shareSpan.style.opacity = "1";
shareSpan.onmouseleave = () => shareSpan.style.opacity = "0.75";
shareSpan.innerHTML = `
<svg viewBox="0 0 1236 1024" width="20" height="20">
<path d="M741.743 1018.343c-28.287 0-50.917-11.315-73.547-28.288-22.63-22.63-39.602-50.917-39.602-84.862V792.044c-124.464 0-328.133 33.945-435.624 181.039-16.973 28.287-56.575 45.26-90.52 50.917H85.478C28.903 1012.685-5.042 961.768 0.616 905.193c28.287-243.27 113.15-418.652 260.243-537.458 107.492-84.862 231.956-130.122 367.735-141.437V118.807c0-50.917 22.63-96.177 67.89-113.15C736.086-5.657 781.345 0 815.29 33.945l362.077 367.735c28.288 22.63 45.26 56.574 50.918 96.176 5.657 39.603-5.658 79.205-33.945 107.492-5.658 5.658-11.315 16.972-22.63 22.63l-350.762 356.42c-22.63 22.63-50.918 33.945-79.205 33.945z" />
</svg>
`;
shareSpan.onclick = () => {
generatePoster(content, imgUrl);
};
msg.appendChild(shareSpan);
// ======================
// ✅ 复制按钮(新增)
// ======================
const copySpan = document.createElement("span");
copySpan.style.display = "inline-flex";
copySpan.style.alignItems = "center";
copySpan.style.cursor = "pointer";
copySpan.style.marginTop = "8px";
copySpan.style.marginLeft = "10px";
copySpan.style.opacity = "0.75";
copySpan.style.transition = "opacity .2s";
copySpan.title = "复制内容";
copySpan.onmouseenter = () => copySpan.style.opacity = "1";
copySpan.onmouseleave = () => copySpan.style.opacity = "0.75";
copySpan.innerHTML = `
<svg viewBox="0 0 1024 1024" width="20" height="20">
<path d="M320 128h448v64H320zM256 256h512v64H256zM192 384h640v64H192zM256 512h512v64H256zM320 640h448v64H320z"/>
</svg>
`;
copySpan.onclick = async () => {
try {
await navigator.clipboard.writeText(content);
copySpan.style.opacity = "1";
showToast("复制成功")
copySpan.title = "复制成功";
setTimeout(() => { copySpan.title = "复制内容"; }, 1200);
} catch (err) {
alert("复制失败,可能不支持 HTTPS 环境以外复制。");
}
};
}
setTimeout(() => {
msgDiv.appendChild(shareSpan);
msgDiv.appendChild(copySpan);
}, 1000)

View File

@@ -736,7 +736,7 @@
const t = Date.now();
document.body.classList.add('fadeout');
window.location.replace(`https://ai.satabot.com?userId=${encodedUserId}&headingimg=${userInfo.headimgurl}&nickname=${userInfo.nickname}&t=${t}`)
window.location.replace(`https://ai.satabot.com?userId=${encodedUserId}&headingimg=${userInfo.headimgurl}&nickname=${userInfo.nickname}&localtoken=${res.token}&t=${t}`)
}
})
.catch(err => {
@@ -932,7 +932,7 @@
const t = Date.now();
document.body.classList.add('fadeout');
window.location.replace(`https://ai.satabot.com?userId=${encodedUserId}&headingimg=${userInfo.headimgurl}&nickname=${userInfo.nickname}&t=${t}`)
window.location.replace(`https://ai.satabot.com?userId=${encodedUserId}&headingimg=${userInfo.headimgurl}&nickname=${userInfo.nickname}&localtoken=${res.token}&t=${t}`)
} else {
showToast(res.msg); // 给用户友好提示
}

View File

@@ -626,7 +626,12 @@ app.post("/user", async (req, res) => {
if (!userId&&userId!="NaN") {
return res.status(400).send("缺少 user_id");
res.json({
code: 300,
error: "http://ri.satabot.com/#/login?goRemote=1",
msg:"未找到该用户"
});
return;
}
// 查询 user_name