diff --git a/app/src/main/java/org/yameida/worktool/service/WeworkLoopImpl.kt b/app/src/main/java/org/yameida/worktool/service/WeworkLoopImpl.kt index 9e2c570..1bb5e01 100644 --- a/app/src/main/java/org/yameida/worktool/service/WeworkLoopImpl.kt +++ b/app/src/main/java/org/yameida/worktool/service/WeworkLoopImpl.kt @@ -132,7 +132,7 @@ object WeworkLoopImpl { for (i in 0 until list.childCount) { val item = list.getChild(i) if (item != null && item.childCount > 0) { - messageList.add(parseChatMessageItem(item, titleList, roomType)) + messageList.add(parseChatMessageItem(item, titleList, roomType, false)) } } } @@ -144,7 +144,7 @@ object WeworkLoopImpl { for (i in 0 until list2.childCount) { val item = list2.getChild(i) if (item != null && item.childCount > 0) { - messageList2.add(parseChatMessageItem(item, titleList, roomType)) + messageList2.add(parseChatMessageItem(item, titleList, roomType, true)) } } } @@ -163,7 +163,13 @@ object WeworkLoopImpl { null ) ) - SPUtils.getInstance("lastSyncMessage").put(title, messageList.last().itemMessageList.lastOrNull()?.text) + val lastMessage = messageList.last() + val lastSyncMessage = if (lastMessage.textType == 2) { + "[图片]" + } else { + lastMessage.itemMessageList.lastOrNull()?.text + } + SPUtils.getInstance("lastSyncMessage").put(title, lastSyncMessage) //推测是否回复并在房间等待指令 if (needInfer) { val lastMessage = messageList.lastOrNull() @@ -467,7 +473,7 @@ object WeworkLoopImpl { continue } if (SPUtils.getInstance("noSyncMessage").getString(title) != lastSyncMessage) { - LogUtils.e("发现不一致消息: $tvList") + LogUtils.e("发现不一致消息: $tvList $lastSyncMessage") error("发现不一致消息: $tvList $lastSyncMessage") SPUtils.getInstance("noSyncMessage").put(title, lastSyncMessage) if (AccessibilityUtil.performClick(item)) { @@ -493,7 +499,8 @@ object WeworkLoopImpl { private fun parseChatMessageItem( node: AccessibilityNodeInfo, titleList: ArrayList, - roomType: Int + roomType: Int, + doubleCheck: Boolean ): WeworkMessageBean.SubMessageBean { val message: WeworkMessageBean.SubMessageBean val nameList = arrayListOf() @@ -537,7 +544,7 @@ object WeworkLoopImpl { } message = WeworkMessageBean.SubMessageBean(0, textType, itemMessageList, nameList) //图片类型特殊处理 - if (Constant.pushImage && textType == 2) { + if (doubleCheck && Constant.pushImage && textType == 2) { val lastPicCreateTime = MultiFileObserver.lastPicCreateTime val lastPicPath = MultiFileObserver.lastPicPath LogUtils.d("发现图片类型应该点击") diff --git a/app/src/main/java/org/yameida/worktool/utils/HttpUtil.kt b/app/src/main/java/org/yameida/worktool/utils/HttpUtil.kt index 3d24fb5..2f9687e 100644 --- a/app/src/main/java/org/yameida/worktool/utils/HttpUtil.kt +++ b/app/src/main/java/org/yameida/worktool/utils/HttpUtil.kt @@ -1,17 +1,16 @@ package org.yameida.worktool.utils -import com.blankj.utilcode.util.AppUtils -import com.blankj.utilcode.util.GsonUtils -import com.blankj.utilcode.util.LogUtils -import com.blankj.utilcode.util.ToastUtils +import com.blankj.utilcode.util.* import com.lzy.okgo.OkGo import com.lzy.okgo.callback.StringCallback import com.lzy.okgo.model.Response import model.UpdateConfig +import org.json.JSONObject import org.yameida.worktool.Constant import org.yameida.worktool.R import org.yameida.worktool.model.network.CheckUpdateResult import org.yameida.worktool.model.network.GetMyConfigResult +import org.yameida.worktool.service.log import update.UpdateAppUtils import java.io.File @@ -112,19 +111,38 @@ object HttpUtil { /** * 推送图片 */ - fun pushImage(url: String, groupName: String, receivedName: String?, imagePath: String) { + fun pushImage(url: String, titleList: List, receivedName: String?, imagePath: String, roomType: Int) { + val json = JSONObject() + if (receivedName != null) { + json.put("receivedName", receivedName) + json.put("groupName", titleList.lastOrNull()) + if (titleList.size > 1) { + json.put("groupRemark", titleList.first()) + } else { + json.put("groupRemark", null) + } + } else { + json.put("receivedName", titleList.lastOrNull() { !it.contains("@") } ?: "") + json.put("groupName", null) + json.put("groupRemark", null) + } + json.put("image", EncodeUtils.base64Encode2String(File(imagePath).readBytes())) + json.put("robotId", Constant.robotId) + json.put("roomType", roomType) + json.put("atMe", false) + json.put("textType", 2) OkGo.post(url) - .params("groupName", groupName) - .params("receivedName", receivedName ?: "") - .params("image", File(imagePath)) + .upJson(json) .execute(object : StringCallback() { override fun onSuccess(response: Response) { - LogUtils.d("推送图片成功: $groupName $receivedName $imagePath") + LogUtils.d("推送图片成功: ${titleList.joinToString()} $receivedName $imagePath") + log("推送图片成功: ${titleList.joinToString()} $receivedName $imagePath") } override fun onError(response: Response) { ToastUtils.showLong("推送图片失败") LogUtils.e("推送图片失败") + error("推送图片失败: $${titleList.joinToString()} $receivedName $imagePath") } }) }