From fc4ffcdc5b536b7df369afdee7625127a75637d2 Mon Sep 17 00:00:00 2001 From: tanjianbin <632190820@qq.com> Date: Tue, 24 Mar 2026 19:47:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(wechat):=20=E6=B7=BB=E5=8A=A0=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E5=AD=98=E5=9C=A8=E6=80=A7=E9=AA=8C=E8=AF=81=E4=BB=A5?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=97=A0=E6=95=88=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在发送消息、图片和文件前,先验证目标会话是否存在于当前会话列表中 通过数字正则匹配处理会话标题中的数字差异,提高匹配准确性 当会话不存在或无法获取列表时,提前返回错误信息,避免不必要的后续操作 --- .../worktool/service/WeworkOperationImpl.kt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt b/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt index 05dccc1..5b1fb4a 100644 --- a/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt +++ b/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt @@ -44,6 +44,23 @@ object WeworkOperationImpl { goHome() return false } + + // 验证titleList是否在当前会话列表中存在 + val currentRoomList = WeworkRoomUtil.getRoomTitle(print = false) + if (currentRoomList.isEmpty()) { + LogUtils.d("无法获取当前会话列表") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "无法获取当前会话列表,请确保在微信首页", startTime, listOf(), titleList) + return false + } + val notFoundList = titleList.filter { title -> + currentRoomList.none { it == title || it.replace(Constant.digitalRegex, "") == title || title.replace(Constant.digitalRegex, "") == it } + } + if (notFoundList.isNotEmpty()) { + LogUtils.d("以下会话不存在: ${notFoundList.joinToString()}") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "会话不存在: ${notFoundList.joinToString()}", startTime, listOf(), titleList) + return false + } + val successList = arrayListOf() val failList = arrayListOf() for (title in LinkedHashSet(titleList)) { @@ -107,6 +124,23 @@ object WeworkOperationImpl { goHome() return false } + + // 验证titleList是否在当前会话列表中存在 + val currentRoomList = WeworkRoomUtil.getRoomTitle(print = false) + if (currentRoomList.isEmpty()) { + LogUtils.d("无法获取当前会话列表") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "无法获取当前会话列表,请确保在微信首页", startTime, listOf(), titleList) + return false + } + val notFoundList = titleList.filter { title -> + currentRoomList.none { it == title || it.replace(Constant.digitalRegex, "") == title || title.replace(Constant.digitalRegex, "") == it } + } + if (notFoundList.isNotEmpty()) { + LogUtils.d("以下会话不存在: ${notFoundList.joinToString()}") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "会话不存在: ${notFoundList.joinToString()}", startTime, listOf(), titleList) + return false + } + val successList = arrayListOf() val failList = arrayListOf() for (title in LinkedHashSet(titleList)) { @@ -182,6 +216,23 @@ object WeworkOperationImpl { extraText: String? = null ): Boolean { val startTime = System.currentTimeMillis() + + // 验证titleList是否在当前会话列表中存在 + val currentRoomList = WeworkRoomUtil.getRoomTitle(print = false) + if (currentRoomList.isEmpty()) { + LogUtils.d("无法获取当前会话列表") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "无法获取当前会话列表,请确保在微信首页", startTime, listOf(), titleList) + return false + } + val notFoundList = titleList.filter { title -> + currentRoomList.none { it == title || it.replace(Constant.digitalRegex, "") == title || title.replace(Constant.digitalRegex, "") == it } + } + if (notFoundList.isNotEmpty()) { + LogUtils.d("以下会话不存在: ${notFoundList.joinToString()}") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "会话不存在: ${notFoundList.joinToString()}", startTime, listOf(), titleList) + return false + } + for (title in LinkedHashSet(titleList)) { if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) { if (!receivedName.isNullOrEmpty()) {