From 924b74b3b2a96a2368db7fdbe256ec00c11af2c8 Mon Sep 17 00:00:00 2001 From: "[yxf]" <[1524240689@qq.com]> Date: Wed, 22 Apr 2026 19:25:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9F=9F=E5=90=8D=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E3=80=81=E8=BD=AC=E6=8E=A5=E5=AE=A2=E6=9C=8D=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/FriendServiceImpl.java | 3 +- .../PlatformConfigurationServiceImpl.java | 46 +- im-uniapp/App.vue | 84 +- im-uniapp/pages/chat/chat-box.vue | 44 +- im-uniapp/pages/login/login.vue | 30 +- im-uniapp/store/chatStore.js | 1144 +++++++++-------- 6 files changed, 730 insertions(+), 621 deletions(-) diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java index d7f9358..3cc83d2 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java @@ -107,7 +107,7 @@ public class FriendServiceImpl extends ServiceImpl impleme log.info("删除好友,用户id:{},好友id:{}", userId, friendId); } - @Cacheable(key = "#userId1+':'+#userId2") +// @Cacheable(key = "#userId1+':'+#userId2") @Override public Boolean isFriend(Long userId1, Long userId2) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); @@ -117,6 +117,7 @@ public class FriendServiceImpl extends ServiceImpl impleme return this.exists(wrapper); } + /** * 单向绑定好友关系 * diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/PlatformConfigurationServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/PlatformConfigurationServiceImpl.java index 010021f..fcaae52 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/PlatformConfigurationServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/PlatformConfigurationServiceImpl.java @@ -1,7 +1,5 @@ package com.bx.implatform.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.bx.implatform.entity.PlatformConfiguration; import com.bx.implatform.mapper.PlatformConfigurationMapper; @@ -11,6 +9,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Arrays; import java.util.List; @@ -25,23 +25,51 @@ public class PlatformConfigurationServiceImpl extends ServiceImpl inputDomains = Arrays.stream(sourceUrl.split("\n")) + List inputList = Arrays.stream(sourceUrl.split("\n")) .map(String::trim) .filter(StringUtils::hasText) .toList(); List allConfigs = this.list(); - for (String input : inputDomains) { - for (PlatformConfiguration config : allConfigs) { - String dbDomain = config.getDomainName(); - if (StringUtils.hasText(dbDomain) && dbDomain.contains(input)) { - log.info("【匹配成功】平台:{},匹配规则:{}", config.getPlatformName(), input); - return config.getPlatformName(); + for (String input : inputList) { + try { + String inputHost = extractHost(input); + if (inputHost == null) continue; + + for (PlatformConfiguration config : allConfigs) { + String dbDomain = config.getDomainName(); + if (!StringUtils.hasText(dbDomain)) continue; + + String dbHost = extractHost(dbDomain); + + if (inputHost.equals(dbHost)) { + log.info("【精确匹配成功】平台:{},匹配域名:{}", config.getPlatformName(), inputHost); + return config.getPlatformName(); + } } + + } catch (Exception e) { + log.warn("解析域名失败: {}", input); } } return null; } + + /** + * 通用提取纯净域名方法 + */ + private String extractHost(String urlStr) { + try { + // 如果不是http开头,手动补全,防止报错 + if (!urlStr.startsWith("http")) { + urlStr = "http://" + urlStr; + } + URL url = new URL(urlStr); + return url.getHost(); + } catch (MalformedURLException e) { + return null; + } + } } \ No newline at end of file diff --git a/im-uniapp/App.vue b/im-uniapp/App.vue index 3443174..2a6c47a 100644 --- a/im-uniapp/App.vue +++ b/im-uniapp/App.vue @@ -42,7 +42,9 @@ export default { this.configStore.setAppInit(true); } }); + // console.log(cmd, msgInfo); wsApi.onMessage((cmd, msgInfo) => { + console.log(cmd, msgInfo); if (cmd == 2) { // 异地登录,强制下线 // uni.showModal({ @@ -79,40 +81,17 @@ export default { this.configStore.setAppInit(false); } }) - wsApi.onMessage((cmd, msgInfo) => { - if (cmd == 2) { - // 异地登录 - this.exit(); - } else if (cmd == 3) { - // 私聊消息 - this.handlePrivateMessage(msgInfo); - } else if (cmd == 4) { - // 群聊消息 - this.handleGroupMessage(msgInfo); - } else if (cmd == 5) { - // 系统消息 - this.handleSystemMessage(msgInfo); - } else if (cmd == 6) { - // 新增:客服变更通知 - this.handleCustomerChanged(msgInfo); - } - }); }, // 处理客服变更 - // 处理客服变更【终极修复版】 handleCustomerChanged(msgInfo) { - console.log('【客服转接】后台下发变更通知', msgInfo); - // msgInfo 里自带:oldKfId 旧客服id、newKfId 新客服id const oldKfId = msgInfo.oldKfId; const newKfId = msgInfo.newKfId; - // ========== 强制合并:旧客服所有消息 -> 新客服 ========== if (oldKfId && newKfId && oldKfId != newKfId) { const oldChat = this.chatStore.findChatByFriend(oldKfId); const newChat = this.chatStore.findChatByFriend(newKfId); if (oldChat && oldChat.messages.length > 0) { - console.log('【开始强制合并】旧客服', oldKfId, '→ 新客服', newKfId); // 执行合并 this.chatStore.mergeOldCustomerToNew(oldKfId, newKfId); } @@ -212,34 +191,40 @@ export default { }) }, handlePrivateMessage(msg) { - // 标记这条消息是不是自己发的 msg.selfSend = msg.sendId == this.userStore.userInfo.id; // 好友id let friendId = msg.selfSend ? msg.recvId : msg.sendId; - - // 检查是否为未知用户(只检查收到的消息) - let existingFriend = this.friendStore.findFriend(friendId); - if (!existingFriend && !msg.selfSend) { - console.log("收到未知用户消息,刷新应用:", friendId); - - this.loadStore().then(() => { - // #ifdef H5 - window.location.reload(); - // #endif - - // #ifdef APP-PLUS - plus.runtime.restart(); - // #endif - - // #ifdef MP-WEIXIN - uni.reLaunch({ - url: '/pages/chat/chat' + if (!msg.selfSend) { + let friend = this.friendStore.findFriend(friendId); + if (!friend) { + this.chatStore.forceMergeAllOldCustomerToNew(friendId); + + // 合并完成 → 强制刷新页面 + uni.showToast({ + title: "客服已更换,刷新中...", + icon: "none", + duration: 1500 }); - // #endif - }); - - return; + + setTimeout(() => { + // #ifdef H5 + window.location.reload(); + // #endif + + // #ifdef APP-PLUS + plus.runtime.restart(); + // #endif + + // #ifdef MP-WEIXIN + uni.reLaunch({ + url: '/pages/chat/chat' + }); + // #endif + }, 800); + + // return; + } } // 会话信息 let chatInfo = { @@ -470,7 +455,6 @@ export default { return group; }, exit() { - console.log("exit"); this.isExit = true; wsApi.close(3099); uni.removeStorageSync("loginInfo"); @@ -543,7 +527,6 @@ export default { this.pullOfflineMessage(); this.configStore.setAppInit(true); }).catch((e) => { - console.log(e); this.exit(); }) }, @@ -585,14 +568,9 @@ export default { this.$nextTick(() => { const btn = document.querySelector('.btn-send'); if (btn) { - console.log('按钮找到:', btn); - // 获取所有事件监听器(需要浏览器支持) const listeners = getEventListeners?.(btn); - console.log('按钮事件监听器:', listeners); - // 手动绑定一个测试事件 btn.addEventListener('click', (e) => { - console.log('原生点击事件触发'); this.sendTextMessage(); }); } diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index d059dbb..9d780ad 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -227,7 +227,10 @@