微信头像显示
This commit is contained in:
25
server2.js
25
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}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user