diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java index d12ff45..1bb8557 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java @@ -1,5 +1,6 @@ package com.bx.implatform.service.impl; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; @@ -110,7 +111,8 @@ public class UserServiceImpl extends ServiceImpl implements Us guestUser.setPassword(""); guestUser.setUuid(guestUuid); guestUser.setLastLoginIp(dto.getIp()); - guestUser.setSourceUrl(dto.getSourceUrl()); + guestUser.setSourceUrl(dto.getSourceUrl()); + guestUser.setLastLoginTime(DateUtil.date()); guestUser.setUniqueToken(dto.getUniqueToken()); // 保存到数据库 this.save(guestUser); @@ -151,10 +153,6 @@ public class UserServiceImpl extends ServiceImpl implements Us return vo; } - /** - * 根据 uniqueToken 查询【客服】 - * 客服条件:is_customer = 2 且 unique_token = 传入的token - */ public Long getCustomerServiceIdByUniqueToken(String uniqueToken) { // 1. 构建查询条件 LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); @@ -230,6 +228,8 @@ public class UserServiceImpl extends ServiceImpl implements Us String newRefreshToken = JwtUtil.sign(userId, strJson, jwtProperties.getRefreshTokenExpireIn(), jwtProperties.getRefreshTokenSecret()); LoginVO vo = new LoginVO(); + User guestUser = new User(); + guestUser.setLastLoginTime(DateUtil.date()); vo.setAccessToken(accessToken); vo.setAccessTokenExpiresIn(jwtProperties.getAccessTokenExpireIn()); vo.setRefreshToken(newRefreshToken); diff --git a/im-uniapp/pages.json b/im-uniapp/pages.json index 19c15ba..72f4341 100644 --- a/im-uniapp/pages.json +++ b/im-uniapp/pages.json @@ -38,7 +38,13 @@ "softinputMode": "adjustResize" } } - } + }, + { + "path": "pages/login/404", + "style": { + "navigationBarTitleText": "页面不存在" + } + } // { // "path": "pages/chat/chat-private-video" // }, diff --git a/im-uniapp/pages/login/login.vue b/im-uniapp/pages/login/login.vue index 8ef2251..dd3727a 100644 --- a/im-uniapp/pages/login/login.vue +++ b/im-uniapp/pages/login/login.vue @@ -104,10 +104,28 @@ export default { async autoLogin() { if (GLOBAL_AUTO_LOGIN_LOCK) return; GLOBAL_AUTO_LOGIN_LOCK = true; - + // 获取token(优先使用URL中的token) this.getTokenFromUrl(); + // 判断是否有 token,没有则跳转 404 + if (!this.dataForm.uniqueToken) { + console.log("未携带token,跳转到404页面"); + // #ifdef H5 + // 考虑基础路径 /h5/ + window.location.href = '/h5/#/pages/login/404'; + // #endif + + // #ifndef H5 + uni.redirectTo({ + url: '/pages/login/404' + }); + // #endif + + GLOBAL_AUTO_LOGIN_LOCK = false; + return; + } + // 获取来源网址 this.getSourceUrl(); await this.getIp(); @@ -148,22 +166,35 @@ export default { } this.friendStore.addFriend(friend); - // 清除 URL 中的 token 参数 - // #ifdef H5 - // 直接使用 window.location 跳转,清除所有参数 - const cleanUrl = window.location.origin + window.location.pathname + '#/pages/chat/chat-box?targetId=' + loginInfo.customerServiceId + '&type=PRIVATE'; - window.location.href = cleanUrl; - // #endif - - // #ifndef H5 - uni.reLaunch({ - url: `/pages/chat/chat-box?targetId=${loginInfo.customerServiceId}&type=PRIVATE` - }); - // #endif + // 清除 URL 中的 token 参数,跳转到聊天页面 + // #ifdef H5 + const cleanUrl = window.location.origin + '/h5/' + '#/pages/chat/chat-box?targetId=' + loginInfo.customerServiceId + '&type=PRIVATE'; + window.location.href = cleanUrl; + // #endif + + // #ifndef H5 + uni.reLaunch({ + url: `/pages/chat/chat-box?targetId=${loginInfo.customerServiceId}&type=PRIVATE` + }); + // #endif }) }).catch(err => { console.log("自动登录失败", err); + GLOBAL_AUTO_LOGIN_LOCK = false; + + // 如果是认证失败(如token无效),也可以跳转404 + if (err && (err.code === 401 || err.statusCode === 401)) { + // #ifdef H5 + window.location.href = '/h5/pages/login/404'; + // #endif + + // #ifndef H5 + uni.redirectTo({ + url: '/pages/login/404' + }); + // #endif + } }); }, diff --git a/im-web/src/components/chat/ChatBox.vue b/im-web/src/components/chat/ChatBox.vue index fe59c12..f86b10d 100644 --- a/im-web/src/components/chat/ChatBox.vue +++ b/im-web/src/components/chat/ChatBox.vue @@ -82,23 +82,19 @@