Browse Source

修改域名功能、转接客服功能

master
[yxf] 3 weeks ago
parent
commit
924b74b3b2
  1. 3
      im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java
  2. 46
      im-platform/src/main/java/com/bx/implatform/service/impl/PlatformConfigurationServiceImpl.java
  3. 76
      im-uniapp/App.vue
  4. 44
      im-uniapp/pages/chat/chat-box.vue
  5. 30
      im-uniapp/pages/login/login.vue
  6. 1128
      im-uniapp/store/chatStore.js

3
im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java

@ -107,7 +107,7 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme
log.info("删除好友,用户id:{},好友id:{}", userId, friendId);
}
@Cacheable(key = "#userId1+':'+#userId2")
// @Cacheable(key = "#userId1+':'+#userId2")
@Override
public Boolean isFriend(Long userId1, Long userId2) {
LambdaQueryWrapper<Friend> wrapper = Wrappers.lambdaQuery();
@ -117,6 +117,7 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme
return this.exists(wrapper);
}
/**
* 单向绑定好友关系
*

46
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<PlatformConfig
return null;
}
List<String> inputDomains = Arrays.stream(sourceUrl.split("\n"))
List<String> inputList = Arrays.stream(sourceUrl.split("\n"))
.map(String::trim)
.filter(StringUtils::hasText)
.toList();
List<PlatformConfiguration> 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;
}
}
}

76
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 idnewKfId 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;
if (!msg.selfSend) {
let friend = this.friendStore.findFriend(friendId);
if (!friend) {
this.chatStore.forceMergeAllOldCustomerToNew(friendId);
//
let existingFriend = this.friendStore.findFriend(friendId);
if (!existingFriend && !msg.selfSend) {
console.log("收到未知用户消息,刷新应用:", friendId);
//
uni.showToast({
title: "客服已更换,刷新中...",
icon: "none",
duration: 1500
});
this.loadStore().then(() => {
// #ifdef H5
window.location.reload();
// #endif
setTimeout(() => {
// #ifdef H5
window.location.reload();
// #endif
// #ifdef APP-PLUS
plus.runtime.restart();
// #endif
// #ifdef APP-PLUS
plus.runtime.restart();
// #endif
// #ifdef MP-WEIXIN
uni.reLaunch({
url: '/pages/chat/chat'
});
// #endif
});
// #ifdef MP-WEIXIN
uni.reLaunch({
url: '/pages/chat/chat'
});
// #endif
}, 800);
return;
// 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();
});
}

44
im-uniapp/pages/chat/chat-box.vue

@ -227,7 +227,10 @@
<script>
import UNI_APP from "@/.env.js";
import useFriendStore from "@/store/friendStore.js";
import useUserStore from "@/store/userStore.js";
import useChatStore from "@/store/chatStore.js";
import useGroupStore from "@/store/groupStore.js";
export default {
data() {
return {
@ -285,6 +288,43 @@ export default {
};
},
methods: {
//
autoMergeOldCustomerOnRefresh() {
try {
const userStore = useUserStore();
const chatStore = useChatStore();
if (!this.isPrivate || !userStore.userInfo?.id) return;
const currentKfId = this.currentTargetId;
if (!currentKfId) return;
//
chatStore.forceMergeAllOldCustomerToNew(currentKfId);
//
setTimeout(() => {
this.reloadChatMessages(currentKfId);
}, 300);
} catch (e) {
console.log("自动合并失败", e);
}
},
reloadChatMessages(targetId) {
try {
const chat = this.chatStore.chats.find(
(c) => c.targetId == targetId && c.type === "PRIVATE"
);
if (chat) {
// 500
this.$forceUpdate();
this.$nextTick(() => {
this.scrollToBottom();
});
}
} catch (e) {}
},
//
selectLang(lang) {
this.currentLang = lang;
@ -1656,7 +1696,7 @@ export default {
await this.getSetting();
this.$nextTick(() => this.scrollToBottom());
this.autoMergeOldCustomerOnRefresh();
} catch (err) {
console.error("错误:", err);
} finally {

30
im-uniapp/pages/login/login.vue

@ -20,24 +20,28 @@ export default {
password: '',
ip: '',
sourceUrl: '',
uniqueToken: '' ,// token
kefuid: '' // ID
uniqueToken: '',
kefuid: ''
}
}
},
methods: {
//
getSourceUrl() {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options || {};
if (options.from) {
this.dataForm.sourceUrl = options.from;
}
// #ifdef H5
this.dataForm.sourceUrl = window.location.origin;
const referrer = document.referrer;
if (referrer) {
this.dataForm.sourceUrl = referrer;
} else {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options || {};
if (options.from) {
this.dataForm.sourceUrl = options.from;
} else {
this.dataForm.sourceUrl = window.location.origin;
}
}
// #endif
// #ifdef APP-PLUS
@ -65,12 +69,10 @@ export default {
if (options.token) {
this.dataForm.uniqueToken = options.token;
console.log("从options获取到token:", this.dataForm.uniqueToken);
}
if (options.kefuid) {
this.dataForm.kefuid = options.kefuid;
console.log("从options获取到kefuid:", this.dataForm.kefuid);
}
const urlParams = new URLSearchParams(window.location.search);
@ -79,12 +81,10 @@ export default {
if (token) {
this.dataForm.uniqueToken = token;
console.log("从URL解析获取到token:", this.dataForm.uniqueToken);
}
if (kefuid) {
this.dataForm.kefuid = kefuid;
console.log("从URL解析获取到kefuid:", this.dataForm.kefuid);
}
// #endif

1128
im-uniapp/store/chatStore.js

File diff suppressed because it is too large
Loading…
Cancel
Save