diff --git a/index.html b/index.html
index 127437d..e7017d7 100755
--- a/index.html
+++ b/index.html
@@ -1648,18 +1648,18 @@
// ✅ 先 URL 解码,再 Base64 解码,再 UTF-8 解码
let userId;
- if (params.get("nickname")) {
- console.log(1)
+ if (params.get("nickname") || getcookie("nickname")) {
+ console.log(getcookie("headingimg"), 888888, document.cookie, params.get("nickname"))
document.querySelectorAll('.logout1').forEach(el => {
el.style.display = 'none';
});
console.log(3)
document.querySelectorAll('.username').forEach((e) => {
- e.textContent = params.get("nickname");
+ e.textContent = params.get("nickname") || getcookie("nickname");
})
- document.querySelector(".userinfo-wrapper img").src = params.get("headingimg");
+ document.querySelector(".userinfo-wrapper img").src = getcookie("headimgurl") || params.get("headingimg");
userId = decodeURIComponent(Number(escape(atob(encodedUserId))));
console.log(4)
@@ -1839,7 +1839,7 @@
const questions = document.querySelectorAll(".question");
// 获取到用户名称
function getUserName(userId) {
- if (params.get("nickname")) return;
+ if (params.get("nickname") || getcookie("nickname")) return;
try {
fetch("https://serviceai.satabot.com/user", {
method: "POST",
@@ -1913,6 +1913,13 @@
const expires = "expires=" + d.toUTCString();
document.cookie = `${name}=${encodeURIComponent(value)}; ${expires}; path=/`;
}
+ function getcookie(name, cookieStr = document.cookie) {
+ const match = cookieStr.match(
+ new RegExp('(?:^|; )' + name.replace(/([.$?*|{}()[\]\\/+^])/g, '\\$1') + '=([^;]*)')
+ );
+ return match ? decodeURIComponent(match[1]) : null;
+ }
+
function getCookie(name) {
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
if (match) return decodeURIComponent(match[2]);
@@ -2115,14 +2122,6 @@
d.setFullYear(d.getFullYear() + 100); // +100 年
document.cookie = `${name}=${value};expires=${d.toUTCString()};path=/`;
}
- function getcookie(name) {
- const cookies = document.cookie.split("; ");
- for (let c of cookies) {
- const [key, val] = c.split("=");
- if (key === name) return val;
- }
- return null;
- }
function showPop(userId) {
if (!userId) {
diff --git a/server2.js b/server2.js
index 795b478..9a8a231 100755
--- a/server2.js
+++ b/server2.js
@@ -543,12 +543,23 @@ app.get('/webCallback', async (req, res) => {
if (loginRes.data.code === 200) {
// 登录成功,设置 token 并跳转
const { token, userId, username } = loginRes.data;
- res.cookie('Admin-Token', token, {
- maxAge: 900000, httpOnly: true, sameSite: 'None', // 或 'Strict' / 'Lax',具体根据需要选择
- });
- res.cookie('userId', userId, {
- maxAge: 900000, httpOnly: true, sameSite: 'None', // 或 'Strict' / 'Lax',具体根据需要选择
- });
+ const cookieConfig = {
+ maxAge: 7 * 24 * 60 * 60 * 1000, // Cookie有效期:7天(毫秒),可自行调整
+ httpOnly: false, // ☢️ 核心!必须为false,前端JS才能读取这个Cookie!!!
+ path: '/', // 浏览器的所有页面路径都能访问该Cookie
+ domain: '.satabot.com', // ✅ 核心!所有子域名共享Cookie,前面必须加【点】
+ sameSite: 'Lax', // ✅ 推荐Lax,兼顾安全+前端读取,比None更安全
+ secure: true // ✅ 你的域名都是HTTPS,必须true,Cookie仅在HTTPS下生效
+ }
+ // 写入Token Cookie(前端读:Admin-Token)
+ res.cookie('Admin-Token', token, cookieConfig);
+ // 写入用户ID Cookie(前端读:userId)
+ res.cookie('userId', userId, cookieConfig);
+ // 可选:写入用户名Cookie(前端读:username)
+ res.cookie('username', username, cookieConfig);
+ // 可选:写入微信昵称/头像(前端可直接用,不用解析URL参数)
+ res.cookie('nickname', userInfo.nickname, cookieConfig);
+ res.cookie('headimgurl', userInfo.headimgurl, cookieConfig);
const encodedUserId = btoa(unescape(encodeURIComponent(userId)));
// 跳转到指定的页面
@@ -561,7 +572,7 @@ app.get('/webCallback', async (req, res) => {
} else {
const encodedToken = btoa(unescape(encodeURIComponent(token)));
const encodedUsername = btoa(unescape(encodeURIComponent(username)));
- res.redirect(`http://ri.satabot.com/#/index?djjdbsjdwjhedbh=${encodedToken}&username=${encodedUsername}`);
+ res.redirect(`http://ri.satabot.com/#/index`);
}
// res.redirect(`https://ai.satabot.com?userId=${encodedUserId}&headingimg=${userInfo.headimgurl}&nickname=${userInfo.nickname}&localtoken=${token}&t=${t}`);