update 执行错误回调;交互通知;搜索房间修复

This commit is contained in:
gallonyin
2022-10-23 00:17:01 +08:00
parent 820ff80ac2
commit a0f0168a30
12 changed files with 323 additions and 94 deletions

View File

@@ -2,10 +2,12 @@ package org.yameida.worktool
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.LogUtils import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.SPUtils import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.Utils import com.blankj.utilcode.util.Utils
import com.efs.sdk.base.core.util.PackageUtil import com.efs.sdk.base.core.util.PackageUtil
import com.google.gson.Gson
import com.hjq.toast.ToastUtils import com.hjq.toast.ToastUtils
import com.tendcloud.tenddata.TalkingDataSDK import com.tendcloud.tenddata.TalkingDataSDK
import com.umeng.commonsdk.UMConfigure import com.umeng.commonsdk.UMConfigure
@@ -33,6 +35,7 @@ class MyApplication : Application() {
super.onCreate() super.onCreate()
//初始化工具类 //初始化工具类
Utils.init(this) Utils.init(this)
GsonUtils.setGsonDelegate(Gson())
//初始化 Toast 框架 //初始化 Toast 框架
ToastUtils.init(this) ToastUtils.init(this)
//初始化友盟统计 //初始化友盟统计

View File

@@ -1,18 +1,75 @@
package org.yameida.worktool.model package org.yameida.worktool.model
import java.util.* /**
* 任务执行成功失败结果回传
*/
data class ExecCallbackBean( data class ExecCallbackBean(
//原生消息指令 //原生消息指令
var rawMsg: String? = null, var rawMsg: String? = null,
//1成功 0失败 //0成功 其他是失败错误码
var rawSuccess: Int = 0, var errorCode: Int = 0,
//失败原因 //失败原因
var errorReason: String = "", var errorReason: String = "",
//执行时间 //执行时间
var runTime: Date = Date() var runTime: Long = 0,
) : WeworkMessageBean() //执行耗时
var timeCost: Double = 0.0
) : WeworkMessageBean() {
companion object {
/**
* 错误码
* 通用格式错误 10xxx
* 执行任务错误 20xxx
* 服务端返回错误 50xxx
*/
const val SUCCESS = 0
//数据格式错误
const val ERROR_ILLEGAL_DATA = 101011
//非法操作
const val ERROR_ILLEGAL_OPERATION = 101012
//创建群失败
const val ERROR_CREATE_GROUP = 201011
//群改名失败
const val ERROR_GROUP_RENAME = 201012
//群拉人失败
const val ERROR_GROUP_ADD_MEMBER = 201013
//群踢人失败
const val ERROR_GROUP_REMOVE_MEMBER = 201014
//改群公告失败
const val ERROR_GROUP_CHANGE_ANNOUNCEMENT = 201015
//改群备注失败
const val ERROR_GROUP_CHANGE_REMARK = 201016
//查找聊天窗失败
const val ERROR_INTO_ROOM = 201101
//发送消息失败
const val ERROR_SEND_MESSAGE = 201102
//按钮寻找失败
const val ERROR_BUTTON = 201103
//目标寻找失败
const val ERROR_TARGET = 201104
//转发失败
const val ERROR_RELAY = 201105
//重复添加
const val ERROR_REPEAT = 201106
//文件下载异常
const val ERROR_FILE_DOWNLOAD = 201107
//文件存储异常
const val ERROR_FILE_STORAGE = 201108
//机器人id错误
const val ERROR_INVALID_ROBOT_ID = 501011
//机器人key错误
const val ERROR_INVALID_ROBOT_KEY = 501012
//机器人重复登录
const val ERROR_ROBOT_MULTI_LOGIN = 501013
//机器人其他未知错误
const val ERROR_OTHER = 501000
}
}

View File

@@ -14,6 +14,7 @@ public class WeworkMessageBean {
* <p> * <p>
* 消息类型 100 * 消息类型 100
* 上传消息列表 TYPE_RECEIVE_MESSAGE_LIST * 上传消息列表 TYPE_RECEIVE_MESSAGE_LIST
* 交互通知 TYPE_CONSOLE_TOAST
* <p> * <p>
* 全局操作类型 200 * 全局操作类型 200
* 停止所有任务并返回首页待命 STOP_AND_GO_HOME * 停止所有任务并返回首页待命 STOP_AND_GO_HOME
@@ -21,7 +22,7 @@ public class WeworkMessageBean {
* 在房间内发送消息 SEND_MESSAGE * 在房间内发送消息 SEND_MESSAGE
* 在房间内指定回复消息 REPLY_MESSAGE * 在房间内指定回复消息 REPLY_MESSAGE
* 在房间内转发消息 RELAY_MESSAGE * 在房间内转发消息 RELAY_MESSAGE
* 创建群 CREATE_GROUP * 创建群 INIT_GROUP
* 进入群聊并修改群配置 INTO_GROUP_AND_CONFIG * 进入群聊并修改群配置 INTO_GROUP_AND_CONFIG
* 推送微盘图片 PUSH_MICRO_DISK_IMAGE * 推送微盘图片 PUSH_MICRO_DISK_IMAGE
* 推送微盘文件 PUSH_MICRO_DISK_FILE * 推送微盘文件 PUSH_MICRO_DISK_FILE
@@ -44,6 +45,7 @@ public class WeworkMessageBean {
*/ */
public static final int HEART_BEAT = 11; public static final int HEART_BEAT = 11;
public static final int TYPE_RECEIVE_MESSAGE_LIST = 101; public static final int TYPE_RECEIVE_MESSAGE_LIST = 101;
public static final int TYPE_CONSOLE_TOAST = 102;
public static final int STOP_AND_GO_HOME = 201; public static final int STOP_AND_GO_HOME = 201;
public static final int LOOP_RECEIVE_NEW_MESSAGE = 202; public static final int LOOP_RECEIVE_NEW_MESSAGE = 202;

View File

@@ -147,10 +147,10 @@ fun backPress() {
/** /**
* 上传执行指令结果 * 上传执行指令结果
*/ */
fun uploadCommandResult(message: WeworkMessageBean, success: Boolean, reason: String) { fun uploadCommandResult(message: WeworkMessageBean, errorCode: Int, errorReason: String, startTime: Long) {
WeworkController.weworkService.webSocketManager.send( WeworkController.weworkService.webSocketManager.send(
WeworkMessageListBean( WeworkMessageListBean(
ExecCallbackBean(GsonUtils.toJson(message), if (success) 1 else 0, reason), ExecCallbackBean(GsonUtils.toJson(message), errorCode, errorReason, startTime, (System.currentTimeMillis() - startTime) / 1000.0),
WeworkMessageListBean.SOCKET_TYPE_RAW_CONFIRM, WeworkMessageListBean.SOCKET_TYPE_RAW_CONFIRM,
messageId = message.messageId messageId = message.messageId
), true ), true

View File

@@ -9,6 +9,7 @@ import com.blankj.utilcode.util.LogUtils
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import okhttp3.WebSocket import okhttp3.WebSocket
import org.yameida.worktool.Constant import org.yameida.worktool.Constant
import org.yameida.worktool.model.ExecCallbackBean
import org.yameida.worktool.model.WeworkMessageBean import org.yameida.worktool.model.WeworkMessageBean
import org.yameida.worktool.model.WeworkMessageListBean import org.yameida.worktool.model.WeworkMessageListBean
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
@@ -52,7 +53,7 @@ object MyLooper {
fun onMessage(webSocket: WebSocket?, text: String) { fun onMessage(webSocket: WebSocket?, text: String) {
val messageList: WeworkMessageListBean<WeworkMessageBean> = val messageList: WeworkMessageListBean<WeworkMessageBean> =
GsonUtils.fromJson<WeworkMessageListBean<WeworkMessageBean>>(text, object : TypeToken<WeworkMessageListBean<WeworkMessageBean>>(){}.type) GsonUtils.fromJson<WeworkMessageListBean<WeworkMessageBean>>(text, object : TypeToken<WeworkMessageListBean<ExecCallbackBean>>(){}.type)
if (messageList.socketType == WeworkMessageListBean.SOCKET_TYPE_HEARTBEAT) { if (messageList.socketType == WeworkMessageListBean.SOCKET_TYPE_HEARTBEAT) {
return return
} }
@@ -97,6 +98,9 @@ object MyLooper {
private fun dealWithMessage(message: WeworkMessageBean) { private fun dealWithMessage(message: WeworkMessageBean) {
when (message.type) { when (message.type) {
WeworkMessageBean.TYPE_CONSOLE_TOAST -> {
WeworkController.consoleToast(message as ExecCallbackBean)
}
WeworkMessageBean.STOP_AND_GO_HOME -> { WeworkMessageBean.STOP_AND_GO_HOME -> {
WeworkController.stopAndGoHome() WeworkController.stopAndGoHome()
} }
@@ -148,7 +152,7 @@ object MyLooper {
WeworkController.getFriendInfo(message) WeworkController.getFriendInfo(message)
} }
WeworkMessageBean.GET_MY_INFO -> { WeworkMessageBean.GET_MY_INFO -> {
WeworkController.getMyInfo() WeworkController.getMyInfo(message)
} }
WeworkMessageBean.ROBOT_CONTROLLER_TEST -> { WeworkMessageBean.ROBOT_CONTROLLER_TEST -> {
WeworkController.test(message) WeworkController.test(message)

View File

@@ -3,6 +3,7 @@ package org.yameida.worktool.service
import com.blankj.utilcode.util.* import com.blankj.utilcode.util.*
import org.yameida.worktool.Demo import org.yameida.worktool.Demo
import org.yameida.worktool.annotation.RequestMapping import org.yameida.worktool.annotation.RequestMapping
import org.yameida.worktool.model.ExecCallbackBean
import org.yameida.worktool.model.WeworkMessageBean import org.yameida.worktool.model.WeworkMessageBean
/** /**
@@ -15,6 +16,18 @@ object WeworkController {
var enableLoopRunning = false var enableLoopRunning = false
var mainLoopRunning = false var mainLoopRunning = false
/**
* 交互通知
* @see WeworkMessageBean.TYPE_CONSOLE_TOAST
* @param message#errorCode 失败错误码
* @param message#errorReason 失败原因
*/
@RequestMapping
fun consoleToast(message: ExecCallbackBean): Boolean {
LogUtils.d("consoleToast(): ${message.errorCode} ${message.errorReason}")
return WeworkInteractionImpl.consoleToast(message, message.errorCode, message.errorReason)
}
/** /**
* 停止所有任务并返回首页待命 * 停止所有任务并返回首页待命
* @see WeworkMessageBean.STOP_AND_GO_HOME * @see WeworkMessageBean.STOP_AND_GO_HOME
@@ -48,7 +61,7 @@ object WeworkController {
@RequestMapping @RequestMapping
fun sendMessage(message: WeworkMessageBean): Boolean { fun sendMessage(message: WeworkMessageBean): Boolean {
LogUtils.d("sendMessage(): ${message.titleList} ${message.receivedContent} ${message.at} ${message.atList?.joinToString()}") LogUtils.d("sendMessage(): ${message.titleList} ${message.receivedContent} ${message.at} ${message.atList?.joinToString()}")
return WeworkOperationImpl.sendMessage(message.titleList, message.receivedContent, message.at, message.atList) return WeworkOperationImpl.sendMessage(message, message.titleList, message.receivedContent, message.at, message.atList)
} }
/** /**
@@ -65,6 +78,7 @@ object WeworkController {
fun replyMessage(message: WeworkMessageBean): Boolean { fun replyMessage(message: WeworkMessageBean): Boolean {
LogUtils.d("replyMessage(): ${message.receivedName} ${message.originalContent} ${message.receivedContent}") LogUtils.d("replyMessage(): ${message.receivedName} ${message.originalContent} ${message.receivedContent}")
return WeworkOperationImpl.replyMessage( return WeworkOperationImpl.replyMessage(
message,
message.titleList, message.titleList,
message.receivedName, message.receivedName,
message.originalContent, message.originalContent,
@@ -88,6 +102,7 @@ object WeworkController {
fun relayMessage(message: WeworkMessageBean): Boolean { fun relayMessage(message: WeworkMessageBean): Boolean {
LogUtils.d("relayMessage(): ${message.titleList} ${message.receivedName} ${message.originalContent} ${message.textType} ${message.nameList} ${message.extraText}") LogUtils.d("relayMessage(): ${message.titleList} ${message.receivedName} ${message.originalContent} ${message.textType} ${message.nameList} ${message.extraText}")
return WeworkOperationImpl.relayMessage( return WeworkOperationImpl.relayMessage(
message,
message.titleList, message.titleList,
message.receivedName, message.receivedName,
message.originalContent, message.originalContent,
@@ -109,6 +124,7 @@ object WeworkController {
fun initGroup(message: WeworkMessageBean): Boolean { fun initGroup(message: WeworkMessageBean): Boolean {
LogUtils.d("initGroup(): ${message.groupName} ${message.selectList} ${message.groupAnnouncement} ${message.groupRemark}") LogUtils.d("initGroup(): ${message.groupName} ${message.selectList} ${message.groupAnnouncement} ${message.groupRemark}")
return WeworkOperationImpl.initGroup( return WeworkOperationImpl.initGroup(
message,
message.groupName, message.groupName,
message.selectList, message.selectList,
message.groupAnnouncement, message.groupAnnouncement,
@@ -142,6 +158,7 @@ object WeworkController {
fun intoGroupAndConfig(message: WeworkMessageBean): Boolean { fun intoGroupAndConfig(message: WeworkMessageBean): Boolean {
LogUtils.d("intoGroupAndConfig(): ${message.groupName} ${message.newGroupName} ${message.newGroupAnnouncement} ${message.selectList} ${message.showMessageHistory} ${message.removeList} ${message.groupRemark}") LogUtils.d("intoGroupAndConfig(): ${message.groupName} ${message.newGroupName} ${message.newGroupAnnouncement} ${message.selectList} ${message.showMessageHistory} ${message.removeList} ${message.groupRemark}")
return WeworkOperationImpl.intoGroupAndConfig( return WeworkOperationImpl.intoGroupAndConfig(
message,
message.groupName, message.groupName,
message.newGroupName, message.newGroupName,
message.newGroupAnnouncement, message.newGroupAnnouncement,
@@ -163,6 +180,7 @@ object WeworkController {
fun pushMicroDiskImage(message: WeworkMessageBean): Boolean { fun pushMicroDiskImage(message: WeworkMessageBean): Boolean {
LogUtils.d("pushMicroDiskImage(): ${message.titleList} ${message.objectName} ${message.extraText}") LogUtils.d("pushMicroDiskImage(): ${message.titleList} ${message.objectName} ${message.extraText}")
return WeworkOperationImpl.pushMicroDiskImage( return WeworkOperationImpl.pushMicroDiskImage(
message,
message.titleList, message.titleList,
message.objectName, message.objectName,
message.extraText message.extraText
@@ -180,6 +198,7 @@ object WeworkController {
fun pushMicroDiskFile(message: WeworkMessageBean): Boolean { fun pushMicroDiskFile(message: WeworkMessageBean): Boolean {
LogUtils.d("pushMicroDiskFile(): ${message.titleList} ${message.objectName} ${message.extraText}") LogUtils.d("pushMicroDiskFile(): ${message.titleList} ${message.objectName} ${message.extraText}")
return WeworkOperationImpl.pushMicroDiskFile( return WeworkOperationImpl.pushMicroDiskFile(
message,
message.titleList, message.titleList,
message.objectName, message.objectName,
message.extraText message.extraText
@@ -197,6 +216,7 @@ object WeworkController {
fun pushMicroprogram(message: WeworkMessageBean): Boolean { fun pushMicroprogram(message: WeworkMessageBean): Boolean {
LogUtils.d("pushMicroprogram(): ${message.titleList} ${message.objectName} ${message.extraText}") LogUtils.d("pushMicroprogram(): ${message.titleList} ${message.objectName} ${message.extraText}")
return WeworkOperationImpl.pushMicroprogram( return WeworkOperationImpl.pushMicroprogram(
message,
message.titleList, message.titleList,
message.objectName, message.objectName,
message.extraText message.extraText
@@ -215,6 +235,7 @@ object WeworkController {
fun pushOffice(message: WeworkMessageBean): Boolean { fun pushOffice(message: WeworkMessageBean): Boolean {
LogUtils.d("pushOffice(): ${message.titleList} ${message.objectName} ${message.extraText}") LogUtils.d("pushOffice(): ${message.titleList} ${message.objectName} ${message.extraText}")
return WeworkOperationImpl.pushOffice( return WeworkOperationImpl.pushOffice(
message,
message.titleList, message.titleList,
message.objectName, message.objectName,
message.extraText message.extraText
@@ -234,6 +255,7 @@ object WeworkController {
fun pushFile(message: WeworkMessageBean): Boolean { fun pushFile(message: WeworkMessageBean): Boolean {
LogUtils.d("pushFile(): ${message.titleList} ${message.objectName} ${message.fileUrl} ${message.fileType} ${message.extraText}") LogUtils.d("pushFile(): ${message.titleList} ${message.objectName} ${message.fileUrl} ${message.fileType} ${message.extraText}")
return WeworkOperationImpl.pushFile( return WeworkOperationImpl.pushFile(
message,
message.titleList, message.titleList,
message.objectName, message.objectName,
message.fileUrl, message.fileUrl,
@@ -250,7 +272,7 @@ object WeworkController {
@RequestMapping @RequestMapping
fun addFriendByPhone(message: WeworkMessageBean): Boolean { fun addFriendByPhone(message: WeworkMessageBean): Boolean {
LogUtils.d("addFriendByPhone(): ${message.friend}") LogUtils.d("addFriendByPhone(): ${message.friend}")
return WeworkOperationImpl.addFriendByPhone(message.friend) return WeworkOperationImpl.addFriendByPhone(message, message.friend)
} }
/** /**
@@ -265,6 +287,7 @@ object WeworkController {
fun showGroupInfo(message: WeworkMessageBean): Boolean { fun showGroupInfo(message: WeworkMessageBean): Boolean {
LogUtils.d("showGroupInfo(): ${message.titleList} ${message.receivedName} ${message.originalContent} ${message.textType}") LogUtils.d("showGroupInfo(): ${message.titleList} ${message.receivedName} ${message.originalContent} ${message.textType}")
return WeworkOperationImpl.showGroupInfo( return WeworkOperationImpl.showGroupInfo(
message,
message.titleList, message.titleList,
message.receivedName, message.receivedName,
message.originalContent, message.originalContent,
@@ -280,7 +303,7 @@ object WeworkController {
@RequestMapping @RequestMapping
fun getGroupInfo(message: WeworkMessageBean): Boolean { fun getGroupInfo(message: WeworkMessageBean): Boolean {
LogUtils.d("getGroupInfo(): ${message.selectList}") LogUtils.d("getGroupInfo(): ${message.selectList}")
return WeworkGetImpl.getGroupInfo(message.selectList) return WeworkGetImpl.getGroupInfo(message, message.selectList)
} }
/** /**
@@ -292,7 +315,7 @@ object WeworkController {
@RequestMapping @RequestMapping
fun getFriendInfo(message: WeworkMessageBean): Boolean { fun getFriendInfo(message: WeworkMessageBean): Boolean {
LogUtils.d("getFriendInfo(): ${message.selectList}") LogUtils.d("getFriendInfo(): ${message.selectList}")
return WeworkGetImpl.getFriendInfo(message.selectList) return WeworkGetImpl.getFriendInfo(message, message.selectList)
} }
/** /**
@@ -300,9 +323,9 @@ object WeworkController {
* @see WeworkMessageBean.GET_MY_INFO * @see WeworkMessageBean.GET_MY_INFO
*/ */
@RequestMapping @RequestMapping
fun getMyInfo(): Boolean { fun getMyInfo(message: WeworkMessageBean): Boolean {
LogUtils.d("getMyInfo():") LogUtils.d("getMyInfo():")
return WeworkGetImpl.getMyInfo() return WeworkGetImpl.getMyInfo(message)
} }
} }

View File

@@ -18,7 +18,7 @@ object WeworkGetImpl {
* 获取群信息 * 获取群信息
* @param selectList 群名列表 为空时去群管理页查询并返回群聊页 * @param selectList 群名列表 为空时去群管理页查询并返回群聊页
*/ */
fun getGroupInfo(selectList: List<String>): Boolean { fun getGroupInfo(message: WeworkMessageBean, selectList: List<String>): Boolean {
if (selectList.isNullOrEmpty()) { if (selectList.isNullOrEmpty()) {
WeworkRoomUtil.intoGroupManager() WeworkRoomUtil.intoGroupManager()
val groupInfo = getGroupInfoDetail() val groupInfo = getGroupInfoDetail()
@@ -39,14 +39,14 @@ object WeworkGetImpl {
* 获取好友信息 * 获取好友信息
* @param selectList 好友名列表 * @param selectList 好友名列表
*/ */
fun getFriendInfo(selectList: List<String>): Boolean { fun getFriendInfo(message: WeworkMessageBean, selectList: List<String>): Boolean {
return true return true
} }
/** /**
* 获取我的信息 * 获取我的信息
*/ */
fun getMyInfo(): Boolean { fun getMyInfo(message: WeworkMessageBean): Boolean {
if (!goHomeTab("")) { if (!goHomeTab("")) {
LogUtils.d("未找到我的信息") LogUtils.d("未找到我的信息")
log("未找到我的信息") log("未找到我的信息")

View File

@@ -0,0 +1,28 @@
package org.yameida.worktool.service
import com.blankj.utilcode.util.*
import com.hjq.toast.ToastUtils
import org.yameida.worktool.model.ExecCallbackBean
/**
* 消息类型 100
*/
object WeworkInteractionImpl {
/**
* 交互通知
* @param errorCode 失败错误码
* @param errorReason 失败原因
*/
fun consoleToast(
message: ExecCallbackBean,
errorCode: Int,
errorReason: String
): Boolean {
LogUtils.e("错误提示 错误码: $errorCode 错误信息: $errorReason")
ToastUtils.show("错误提示 错误码: $errorCode 错误信息: $errorReason")
return true
}
}

View File

@@ -6,6 +6,7 @@ import org.yameida.worktool.model.WeworkMessageBean
import com.github.yoojia.qrcode.qrcode.QRCodeDecoder import com.github.yoojia.qrcode.qrcode.QRCodeDecoder
import com.blankj.utilcode.util.* import com.blankj.utilcode.util.*
import com.lzy.okgo.OkGo import com.lzy.okgo.OkGo
import org.yameida.worktool.model.ExecCallbackBean
import org.yameida.worktool.utils.* import org.yameida.worktool.utils.*
import java.io.File import java.io.File
import java.lang.Exception import java.lang.Exception
@@ -26,28 +27,41 @@ object WeworkOperationImpl {
* @see WeworkMessageBean.TEXT_TYPE * @see WeworkMessageBean.TEXT_TYPE
*/ */
fun sendMessage( fun sendMessage(
message: WeworkMessageBean,
titleList: List<String>, titleList: List<String>,
receivedContent: String?, receivedContent: String?,
at: String? = null, at: String? = null,
atList: List<String>? = null atList: List<String>? = null
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis()
if (receivedContent.isNullOrEmpty()) { if (receivedContent.isNullOrEmpty()) {
LogUtils.d("未发现发送内容") LogUtils.d("未发现发送内容")
uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_DATA, "发送内容为空", startTime)
return false return false
} }
val successList = arrayListOf<String>()
val failList = arrayListOf<String>()
for (title in titleList) { for (title in titleList) {
if (WeworkRoomUtil.intoRoom(title)) { if (WeworkRoomUtil.intoRoom(title)) {
if (sendChatMessage(receivedContent, at = at, atList = atList)) { if (sendChatMessage(receivedContent, at = at, atList = atList)) {
successList.add(title)
LogUtils.d("$title: 发送成功") LogUtils.d("$title: 发送成功")
} else { } else {
LogUtils.d("$title: 发送失败") LogUtils.d("$title: 发送失败")
failList.add(title)
error("$title: 发送失败 $receivedContent") error("$title: 发送失败 $receivedContent")
} }
} else { } else {
failList.add(title)
LogUtils.d("$title: 发送失败 进入房间失败") LogUtils.d("$title: 发送失败 进入房间失败")
error("$title: 发送失败 进入房间失败 $receivedContent") error("$title: 发送失败 进入房间失败 $receivedContent")
} }
} }
if (failList.isNotEmpty()) {
uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "发送成功: ${successList.joinToString()} 发送失败: ${failList.joinToString()}", startTime)
return false
}
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
return true return true
} }
@@ -61,12 +75,14 @@ object WeworkOperationImpl {
* @see WeworkMessageBean.TEXT_TYPE * @see WeworkMessageBean.TEXT_TYPE
*/ */
fun replyMessage( fun replyMessage(
message: WeworkMessageBean,
titleList: List<String>, titleList: List<String>,
receivedName: String?, receivedName: String?,
originalContent: String, originalContent: String,
textType: Int, textType: Int,
receivedContent: String? receivedContent: String?
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis()
if (receivedContent.isNullOrEmpty()) { if (receivedContent.isNullOrEmpty()) {
LogUtils.d("未发现回复内容") LogUtils.d("未发现回复内容")
return false return false
@@ -83,33 +99,40 @@ object WeworkOperationImpl {
) )
) { ) {
LogUtils.v("开始回复") LogUtils.v("开始回复")
sendChatMessage(receivedContent, reply = true) if (sendChatMessage(receivedContent, reply = true)) {
LogUtils.d("$title: 回复成功") LogUtils.d("$title: 回复成功")
WeworkLoopImpl.getChatMessageList() WeworkLoopImpl.getChatMessageList()
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
return true return true
} else {
LogUtils.d("$title: 回复发送失败")
uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "回复发送失败", startTime)
return false
}
} else { } else {
LogUtils.d("$title: 回复失败 直接发送答案") LogUtils.d("$title: 回复失败 直接发送答案")
error("$title: 回复失败 直接发送答案 $receivedContent") error("$title: 回复失败 直接发送答案 $receivedContent")
if (originalContent.isNotEmpty()) { val text = if (originalContent.isNotEmpty()) "$originalContent\n$receivedContent" else receivedContent
if (receivedName == null) { if (sendChatMessage(text, receivedName)) {
sendChatMessage("$originalContent\n$receivedContent") LogUtils.d("$title: 直接发送答案成功")
} else {
sendChatMessage("$originalContent\n$receivedContent", receivedName)
}
} else {
if (receivedName == null) {
sendChatMessage(receivedContent)
} else {
sendChatMessage(receivedContent, receivedName)
}
}
WeworkLoopImpl.getChatMessageList() WeworkLoopImpl.getChatMessageList()
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
return true
} else {
LogUtils.d("$title: 直接发送答案失败")
uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "直接发送答案失败", startTime)
return false
}
} }
} else { } else {
LogUtils.d("$title: 回复失败")
error("$title: 回复失败 $receivedContent") error("$title: 回复失败 $receivedContent")
LogUtils.d("进入房间失败 $title")
uploadCommandResult(message, ExecCallbackBean.ERROR_INTO_ROOM, "进入房间失败 $title", startTime)
return false
} }
} }
LogUtils.d("房间名为空")
uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_DATA, "房间名为空", startTime)
return false return false
} }
@@ -124,6 +147,7 @@ object WeworkOperationImpl {
* @see WeworkMessageBean.TEXT_TYPE * @see WeworkMessageBean.TEXT_TYPE
*/ */
fun relayMessage( fun relayMessage(
message: WeworkMessageBean,
titleList: List<String>, titleList: List<String>,
receivedName: String, receivedName: String,
originalContent: String, originalContent: String,
@@ -131,6 +155,7 @@ object WeworkOperationImpl {
nameList: List<String>, nameList: List<String>,
extraText: String? = null extraText: String? = null
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis()
for (title in titleList) { for (title in titleList) {
if (WeworkRoomUtil.intoRoom(title)) { if (WeworkRoomUtil.intoRoom(title)) {
if (WeworkTextUtil.longClickMessageItem( if (WeworkTextUtil.longClickMessageItem(
@@ -182,24 +207,37 @@ object WeworkOperationImpl {
* @param groupRemark 修改群备注 选填 * @param groupRemark 修改群备注 选填
*/ */
fun initGroup( fun initGroup(
message: WeworkMessageBean,
groupName: String, groupName: String,
selectList: List<String>?, selectList: List<String>?,
groupAnnouncement: String?, groupAnnouncement: String?,
groupRemark: String? groupRemark: String?
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis()
if (!WeworkRoomUtil.isGroupExists(groupName)) { if (!WeworkRoomUtil.isGroupExists(groupName)) {
if (!createGroup() || !groupRename(groupName) || !groupAddMember(selectList) if (!createGroup()) {
|| !groupChangeAnnouncement(groupAnnouncement) uploadCommandResult(message, ExecCallbackBean.ERROR_CREATE_GROUP, "创建群失败", startTime)
) return false return false
} else {
if (!groupRename(groupName) || !groupAddMember(selectList)
|| !groupChangeAnnouncement(groupAnnouncement)
) return false
} }
if (groupRemark != null) {
groupChangeRemark(groupRemark)
} }
// getGroupQrcode(groupName, groupRemark) if (!groupRename(groupName)) {
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_RENAME, "创建群成功 群改名失败", startTime)
return false
}
if (!groupAddMember(selectList)) {
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_ADD_MEMBER, "创建群成功 群改名成功 群拉人失败 ${selectList?.joinToString()}", startTime)
return false
}
if (!groupChangeAnnouncement(groupAnnouncement)) {
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_CHANGE_ANNOUNCEMENT, "创建群成功 群改名成功 群拉人成功 群公告失败", startTime)
return false
}
if (!groupChangeRemark(groupRemark)) {
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_CHANGE_REMARK, "创建群成功 群改名成功 群拉人成功 群公告成功 群备注失败", startTime)
return false
}
getGroupQrcode(groupName, groupRemark)
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
return true return true
} }
@@ -215,6 +253,7 @@ object WeworkOperationImpl {
* @param removeList 移除群成员名称列表/踢人 选填 * @param removeList 移除群成员名称列表/踢人 选填
*/ */
fun intoGroupAndConfig( fun intoGroupAndConfig(
message: WeworkMessageBean,
groupName: String, groupName: String,
newGroupName: String?, newGroupName: String?,
newGroupAnnouncement: String?, newGroupAnnouncement: String?,
@@ -223,39 +262,49 @@ object WeworkOperationImpl {
showMessageHistory: Boolean = false, showMessageHistory: Boolean = false,
removeList: List<String>? removeList: List<String>?
): Boolean { ): Boolean {
if (WeworkRoomUtil.intoRoom(groupName)) { val startTime = System.currentTimeMillis()
if (newGroupName != null) { if (!WeworkRoomUtil.intoRoom(groupName)) {
groupRename(newGroupName) uploadCommandResult(message, ExecCallbackBean.ERROR_INTO_ROOM, "进入房间失败 $groupName", startTime)
}
if (!selectList.isNullOrEmpty()) {
groupAddMember(selectList, showMessageHistory)
}
if (!removeList.isNullOrEmpty()) {
groupRemoveMember(removeList)
}
if (newGroupAnnouncement != null) {
groupChangeAnnouncement(newGroupAnnouncement)
}
if (groupRemark != null) {
groupChangeRemark(groupRemark)
}
backPress()
return true
}
return false return false
} }
if (!groupRename(newGroupName)) {
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_RENAME, "进入房间成功 群改名失败", startTime)
return false
}
if (!groupAddMember(selectList, showMessageHistory)) {
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_ADD_MEMBER, "进入房间成功 群改名成功 群拉人失败 ${selectList?.joinToString()}", startTime)
return false
}
if (!groupRemoveMember(removeList)) {
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_REMOVE_MEMBER, "进入房间成功 群改名成功 群拉人成功 群踢人失败 ${removeList?.joinToString()}", startTime)
return false
}
if (!groupChangeAnnouncement(newGroupAnnouncement)) {
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_CHANGE_ANNOUNCEMENT, "进入房间成功 群改名成功 群拉人成功 群公告失败", startTime)
return false
}
if (!groupChangeRemark(groupRemark)) {
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_CHANGE_REMARK, "进入房间成功 群改名成功 群拉人成功 群公告成功 群备注失败", startTime)
return false
}
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
return true
}
/** /**
* 推送微盘图片 * 推送微盘图片(不推荐)
* @see pushFile
* @param titleList 待发送姓名列表 * @param titleList 待发送姓名列表
* @param objectName 图片名称 * @param objectName 图片名称
* @param extraText 附加留言 可选 * @param extraText 附加留言 可选
*/ */
fun pushMicroDiskImage( fun pushMicroDiskImage(
message: WeworkMessageBean,
titleList: List<String>, titleList: List<String>,
objectName: String, objectName: String,
extraText: String? = null extraText: String? = null
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis()
goHomeTab("工作台") goHomeTab("工作台")
val node = AccessibilityUtil.scrollAndFindByText(WeworkController.weworkService, getRoot(), "微盘") val node = AccessibilityUtil.scrollAndFindByText(WeworkController.weworkService, getRoot(), "微盘")
if (node != null) { if (node != null) {
@@ -292,16 +341,19 @@ object WeworkOperationImpl {
} }
/** /**
* 推送微盘文件 * 推送微盘文件(不推荐)
* @see pushFile
* @param titleList 待发送姓名列表 * @param titleList 待发送姓名列表
* @param objectName 文件名称 * @param objectName 文件名称
* @param extraText 附加留言 可选 * @param extraText 附加留言 可选
*/ */
fun pushMicroDiskFile( fun pushMicroDiskFile(
message: WeworkMessageBean,
titleList: List<String>, titleList: List<String>,
objectName: String, objectName: String,
extraText: String? = null extraText: String? = null
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis()
goHomeTab("工作台") goHomeTab("工作台")
val node = AccessibilityUtil.scrollAndFindByText(WeworkController.weworkService, getRoot(), "微盘") val node = AccessibilityUtil.scrollAndFindByText(WeworkController.weworkService, getRoot(), "微盘")
if (node != null) { if (node != null) {
@@ -334,16 +386,18 @@ object WeworkOperationImpl {
} }
/** /**
* 推送任意小程序 * 推送任意小程序(不推荐)
* @param titleList 待发送姓名列表 * @param titleList 待发送姓名列表
* @param objectName 小程序名称 * @param objectName 小程序名称
* @param extraText 附加留言 可选 * @param extraText 附加留言 可选
*/ */
fun pushMicroprogram( fun pushMicroprogram(
message: WeworkMessageBean,
titleList: List<String>, titleList: List<String>,
objectName: String, objectName: String,
extraText: String? = null extraText: String? = null
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis()
goHomeTab("工作台") goHomeTab("工作台")
val node = AccessibilityUtil.scrollAndFindByText(WeworkController.weworkService, getRoot(), "用过的小程序") val node = AccessibilityUtil.scrollAndFindByText(WeworkController.weworkService, getRoot(), "用过的小程序")
if (node != null) { if (node != null) {
@@ -373,20 +427,24 @@ object WeworkOperationImpl {
* @param extraText 附加留言 可选 * @param extraText 附加留言 可选
*/ */
fun pushOffice( fun pushOffice(
message: WeworkMessageBean,
titleList: List<String>, titleList: List<String>,
objectName: String, objectName: String,
extraText: String? = null extraText: String? = null
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis()
goHomeTab("文档") goHomeTab("文档")
val allButton = AccessibilityUtil.findOneByText(getRoot(), "全部") val allButton = AccessibilityUtil.findOneByText(getRoot(), "全部")
if (allButton == null) { if (allButton == null) {
LogUtils.e("未找到全部按钮") LogUtils.e("未找到全部按钮")
uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到全部按钮", startTime)
return false return false
} }
AccessibilityUtil.performClick(allButton) AccessibilityUtil.performClick(allButton)
val myFileButton = AccessibilityUtil.findOneByText(getRoot(), "共享空间") val myFileButton = AccessibilityUtil.findOneByText(getRoot(), "共享空间")
if (myFileButton == null) { if (myFileButton == null) {
LogUtils.e("未找到共享空间按钮") LogUtils.e("未找到共享空间按钮")
uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到共享空间按钮", startTime)
return false return false
} }
AccessibilityUtil.performClick(myFileButton) AccessibilityUtil.performClick(myFileButton)
@@ -400,18 +458,24 @@ object WeworkOperationImpl {
val shareFileButton = AccessibilityUtil.findOneByDesc(getRoot(), "转发") val shareFileButton = AccessibilityUtil.findOneByDesc(getRoot(), "转发")
AccessibilityUtil.performClick(shareFileButton) AccessibilityUtil.performClick(shareFileButton)
if (relaySelectTarget(titleList, extraText)) { if (relaySelectTarget(titleList, extraText)) {
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
return true return true
} else { } else {
LogUtils.e("微盘文件转发失败: $objectName") LogUtils.e("微盘文件转发失败: $objectName")
uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "微盘文件转发失败: $objectName", startTime)
return false
} }
} else { } else {
LogUtils.e("文档未搜索到相关文件: $objectName") LogUtils.e("文档未搜索到相关文件: $objectName")
uploadCommandResult(message, ExecCallbackBean.ERROR_TARGET, "文档未搜索到相关文件: $objectName", startTime)
return false
} }
} else { } else {
LogUtils.e("未找到文档搜索按钮") LogUtils.e("未找到文档搜索按钮")
} uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到文档搜索按钮", startTime)
return false return false
} }
}
/** /**
* 推送文件(网络图片视频和文件等) * 推送文件(网络图片视频和文件等)
@@ -423,15 +487,17 @@ object WeworkOperationImpl {
* @param extraText 附加留言 可选 * @param extraText 附加留言 可选
*/ */
fun pushFile( fun pushFile(
message: WeworkMessageBean,
titleList: List<String>, titleList: List<String>,
objectName: String, objectName: String,
fileUrl: String, fileUrl: String,
fileType: String, fileType: String,
extraText: String? = null extraText: String? = null
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis()
LogUtils.i("下载开始 $fileUrl") LogUtils.i("下载开始 $fileUrl")
val execute = OkGo.get<File>(fileUrl).execute() val execute = OkGo.get<File>(fileUrl).execute()
LogUtils.i("下载成 $fileUrl") LogUtils.i("下载$fileUrl")
val body = execute.body() val body = execute.body()
if (body != null) { if (body != null) {
val df = SimpleDateFormat("yyyy-MM-dd") val df = SimpleDateFormat("yyyy-MM-dd")
@@ -447,17 +513,24 @@ object WeworkOperationImpl {
if (relaySelectTarget(titleList, extraText)) { if (relaySelectTarget(titleList, extraText)) {
val stayButton = AccessibilityUtil.findOneByText(getRoot(), "留在企业微信") val stayButton = AccessibilityUtil.findOneByText(getRoot(), "留在企业微信")
AccessibilityUtil.performClick(stayButton) AccessibilityUtil.performClick(stayButton)
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
return true return true
} else { } else {
LogUtils.e("文件转发失败: $objectName") LogUtils.e("文件转发失败: $objectName")
uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "文件转发失败: $objectName", startTime)
return false
} }
} else { } else {
LogUtils.e("文件存储本地失败 $filePath") LogUtils.e("文件存储本地失败 $filePath")
error("文件存储本地失败 $filePath") uploadCommandResult(message, ExecCallbackBean.ERROR_FILE_STORAGE, "文件存储本地失败 $filePath", startTime)
}
}
return false return false
} }
} else {
LogUtils.e("文件下载失败")
uploadCommandResult(message, ExecCallbackBean.ERROR_FILE_DOWNLOAD, "文件下载失败 $fileUrl", startTime)
return false
}
}
/** /**
* 手机号添加好友 * 手机号添加好友
@@ -465,8 +538,10 @@ object WeworkOperationImpl {
* @param friend 待添加用户列表 * @param friend 待添加用户列表
*/ */
fun addFriendByPhone( fun addFriendByPhone(
message: WeworkMessageBean,
friend: WeworkMessageBean.Friend friend: WeworkMessageBean.Friend
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis()
goHome() goHome()
val list = AccessibilityUtil.findOneByClazz(getRoot(), Views.RecyclerView, Views.ListView, Views.ViewGroup) val list = AccessibilityUtil.findOneByClazz(getRoot(), Views.RecyclerView, Views.ListView, Views.ViewGroup)
if (list != null) { if (list != null) {
@@ -552,34 +627,55 @@ object WeworkOperationImpl {
} }
if (AccessibilityUtil.findTextAndClick(getRoot(), "发送添加邀请", "发送申请")) { if (AccessibilityUtil.findTextAndClick(getRoot(), "发送添加邀请", "发送申请")) {
LogUtils.d("发送添加邀请成功: " + friend.phone) LogUtils.d("发送添加邀请成功: " + friend.phone)
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
return true
} else {
LogUtils.e("未找到发送邀请按钮")
uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到发送邀请按钮", startTime)
return false
} }
} else { } else {
if (AccessibilityUtil.findOnceByText(getRoot(), "发消息", exact = true) != null) { if (AccessibilityUtil.findOnceByText(getRoot(), "发消息", exact = true) != null) {
LogUtils.e("已经添加联系人,请勿重复添加") LogUtils.e("已经添加联系人,请勿重复添加" + friend.phone)
uploadCommandResult(message, ExecCallbackBean.ERROR_REPEAT, "已经添加联系人,请勿重复添加" + friend.phone, startTime)
return false
} else { } else {
LogUtils.e("未找到添加为联系人") LogUtils.e("未找到添加为联系人")
uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到添加为联系人", startTime)
return false
} }
} }
} else { } else {
LogUtils.e("未找到标签") LogUtils.e("未找到标签")
uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到标签", startTime)
return false
} }
} else { } else {
LogUtils.e("未找到查找手机选项") LogUtils.e("未找到查找手机选项")
uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到查找手机选项", startTime)
return false
} }
} else { } else {
LogUtils.e("未找到添加客户按钮") LogUtils.e("未找到添加客户按钮")
uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到添加客户按钮", startTime)
return false
} }
} else { } else {
LogUtils.e("未找到添加客户列表") LogUtils.e("未找到添加客户列表")
uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到添加客户列表", startTime)
return false
} }
return true
} else { } else {
LogUtils.e("未找到搜索按钮") LogUtils.e("未找到搜索按钮")
} uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到搜索按钮", startTime)
}
LogUtils.e("未找到聊天列表")
return false return false
} }
} else {
LogUtils.e("未找到聊天列表")
uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到聊天列表", startTime)
return false
}
}
/** /**
* 展示群信息 * 展示群信息
@@ -590,11 +686,13 @@ object WeworkOperationImpl {
* @param textType 原始消息的消息类型 * @param textType 原始消息的消息类型
*/ */
fun showGroupInfo( fun showGroupInfo(
message: WeworkMessageBean,
titleList: MutableList<String>, titleList: MutableList<String>,
receivedName: String, receivedName: String,
originalContent: String, originalContent: String,
textType: Int textType: Int
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis()
for (groupName in titleList) { for (groupName in titleList) {
if (WeworkRoomUtil.intoRoom(groupName) && WeworkRoomUtil.intoGroupManager()) { if (WeworkRoomUtil.intoRoom(groupName) && WeworkRoomUtil.intoGroupManager()) {
val groupInfo = WeworkGetImpl.getGroupInfoDetail() val groupInfo = WeworkGetImpl.getGroupInfoDetail()
@@ -604,10 +702,13 @@ object WeworkOperationImpl {
groupInfo.originalContent = originalContent groupInfo.originalContent = originalContent
groupInfo.textType = textType groupInfo.textType = textType
WeworkController.weworkService.webSocketManager.send(groupInfo) WeworkController.weworkService.webSocketManager.send(groupInfo)
} uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
}
return true return true
} }
}
uploadCommandResult(message, ExecCallbackBean.ERROR_TARGET, "", startTime)
return false
}
/** /**
* 转发消息到目标列表 * 转发消息到目标列表
@@ -632,7 +733,7 @@ object WeworkOperationImpl {
AccessibilityUtil.findTextInput(getRoot(), trimTitle) AccessibilityUtil.findTextInput(getRoot(), trimTitle)
sleep(Constant.CHANGE_PAGE_INTERVAL) sleep(Constant.CHANGE_PAGE_INTERVAL)
val selectListView = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView, Views.RecyclerView, Views.ViewGroup, minChildCount = 2) val selectListView = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView, Views.RecyclerView, Views.ViewGroup, minChildCount = 2)
val regex = "^$trimTitle(-.*)?(…)?(\\(.*?\\))?" + if (needTrim) "" else "$" val regex = "^$trimTitle" + if (needTrim) ".*?" else "(-.*)?(…)?(\\(.*?\\))?$"
val matchSelect = AccessibilityUtil.findOneByTextRegex( val matchSelect = AccessibilityUtil.findOneByTextRegex(
selectListView, selectListView,
regex, regex,
@@ -709,7 +810,8 @@ object WeworkOperationImpl {
/** /**
* 修改群名称 * 修改群名称
*/ */
private fun groupRename(groupName: String): Boolean { private fun groupRename(groupName: String?): Boolean {
if (groupName == null) return true
if (WeworkRoomUtil.intoGroupManager()) { if (WeworkRoomUtil.intoGroupManager()) {
val textView = AccessibilityUtil.findOneByText(getRoot(), "全部群成员", "微信用户创建") val textView = AccessibilityUtil.findOneByText(getRoot(), "全部群成员", "微信用户创建")
?: return false ?: return false
@@ -747,7 +849,7 @@ object WeworkOperationImpl {
* 默认不附带历史记录 * 默认不附带历史记录
*/ */
private fun groupAddMember( private fun groupAddMember(
selectList: List<String>? = null, selectList: List<String>?,
showMessageHistory: Boolean = false showMessageHistory: Boolean = false
): Boolean { ): Boolean {
if (selectList.isNullOrEmpty()) return true if (selectList.isNullOrEmpty()) return true
@@ -759,10 +861,8 @@ object WeworkOperationImpl {
LogUtils.v("tvEmptySize: $tvEmptySize") LogUtils.v("tvEmptySize: $tvEmptySize")
if (tvEmptySize == 0) { if (tvEmptySize == 0) {
return true return true
} else if (tvEmptySize == 1) { } else if (tvEmptySize == 1 || tvEmptySize == 2) {
AccessibilityUtil.performClick(gridView.getChild(gridView.childCount - 1)) AccessibilityUtil.performClick(gridView.getChild(gridView.childCount - tvEmptySize))
} else if (tvEmptySize == 2) {
AccessibilityUtil.performClick(gridView.getChild(gridView.childCount - 2))
} }
} else { } else {
LogUtils.e("未找到添加成员按钮") LogUtils.e("未找到添加成员按钮")
@@ -782,7 +882,7 @@ object WeworkOperationImpl {
AccessibilityUtil.findTextInput(getRoot(), trimTitle) AccessibilityUtil.findTextInput(getRoot(), trimTitle)
sleep(Constant.POP_WINDOW_INTERVAL) sleep(Constant.POP_WINDOW_INTERVAL)
val selectListView = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView, Views.RecyclerView, Views.ViewGroup, minChildCount = 2, firstChildClazz = Views.TextView) val selectListView = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView, Views.RecyclerView, Views.ViewGroup, minChildCount = 2, firstChildClazz = Views.TextView)
val regex = "^$trimTitle(-.*)?(…)?(\\(.*?\\))?" + if (needTrim) "" else "$" val regex = "^$trimTitle" + if (needTrim) ".*?" else "(-.*)?(…)?(\\(.*?\\))?$"
val matchSelect = AccessibilityUtil.findOneByTextRegex( val matchSelect = AccessibilityUtil.findOneByTextRegex(
selectListView, selectListView,
regex, regex,
@@ -790,6 +890,7 @@ object WeworkOperationImpl {
root = false root = false
) )
if (selectListView != null && matchSelect != null) { if (selectListView != null && matchSelect != null) {
var flag = false
for (i in 0 until selectListView.childCount) { for (i in 0 until selectListView.childCount) {
val item = selectListView.getChild(i) val item = selectListView.getChild(i)
val searchResult = AccessibilityUtil.findOnceByTextRegex(item, regex) val searchResult = AccessibilityUtil.findOnceByTextRegex(item, regex)
@@ -797,10 +898,15 @@ object WeworkOperationImpl {
item.refresh() item.refresh()
val imageView = val imageView =
AccessibilityUtil.findOneByClazz(item, Views.ImageView, root = false) AccessibilityUtil.findOneByClazz(item, Views.ImageView, root = false)
AccessibilityUtil.performClick(imageView) if (AccessibilityUtil.performClick(imageView)) {
flag = true
} }
} }
} }
if (!flag) {
LogUtils.e("拉人失败 找不到: $select")
}
}
val textView = AccessibilityUtil.findOnceByClazz(getRoot(), Views.TextView) val textView = AccessibilityUtil.findOnceByClazz(getRoot(), Views.TextView)
if (textView != null && textView.text.isNullOrBlank()) { if (textView != null && textView.text.isNullOrBlank()) {
AccessibilityUtil.performClick(textView) AccessibilityUtil.performClick(textView)
@@ -810,6 +916,7 @@ object WeworkOperationImpl {
LogUtils.d("找到搜索结果: $select") LogUtils.d("找到搜索结果: $select")
} else { } else {
LogUtils.e("未搜索到结果") LogUtils.e("未搜索到结果")
return false
} }
} }
if (showMessageHistory) { if (showMessageHistory) {
@@ -838,7 +945,7 @@ object WeworkOperationImpl {
/** /**
* 移除群成员/踢人 * 移除群成员/踢人
*/ */
private fun groupRemoveMember(removeList: List<String>): Boolean { private fun groupRemoveMember(removeList: List<String>?): Boolean {
if (removeList.isNullOrEmpty()) return true if (removeList.isNullOrEmpty()) return true
if (WeworkRoomUtil.intoGroupManager()) { if (WeworkRoomUtil.intoGroupManager()) {
val gridView = AccessibilityUtil.findOneByClazz(getRoot(), Views.GridView) val gridView = AccessibilityUtil.findOneByClazz(getRoot(), Views.GridView)
@@ -869,7 +976,7 @@ object WeworkOperationImpl {
AccessibilityUtil.findTextInput(getRoot(), trimTitle) AccessibilityUtil.findTextInput(getRoot(), trimTitle)
sleep(Constant.POP_WINDOW_INTERVAL) sleep(Constant.POP_WINDOW_INTERVAL)
val selectListView = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView, Views.RecyclerView, Views.ViewGroup, minChildCount = 2, firstChildClazz = Views.RelativeLayout) val selectListView = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView, Views.RecyclerView, Views.ViewGroup, minChildCount = 2, firstChildClazz = Views.RelativeLayout)
val regex = "^$trimTitle(-.*)?(…)?(\\(.*?\\))?" + if (needTrim) "" else "$" val regex = "^$trimTitle" + if (needTrim) ".*?" else "(-.*)?(…)?(\\(.*?\\))?$"
val matchSelect = AccessibilityUtil.findOneByTextRegex( val matchSelect = AccessibilityUtil.findOneByTextRegex(
selectListView, selectListView,
regex, regex,
@@ -897,6 +1004,7 @@ object WeworkOperationImpl {
LogUtils.d("找到搜索结果: $select") LogUtils.d("找到搜索结果: $select")
} else { } else {
LogUtils.e("未搜索到结果") LogUtils.e("未搜索到结果")
return false
} }
} }
val confirmButton = val confirmButton =
@@ -924,7 +1032,7 @@ object WeworkOperationImpl {
* 注:首次为发布 后续为编辑 * 注:首次为发布 后续为编辑
* 注2外部群为edittext 内部群为webview(只能追加文本) * 注2外部群为edittext 内部群为webview(只能追加文本)
*/ */
private fun groupChangeAnnouncement(groupAnnouncement: String? = null): Boolean { private fun groupChangeAnnouncement(groupAnnouncement: String?): Boolean {
if (groupAnnouncement == null) return true if (groupAnnouncement == null) return true
if (WeworkRoomUtil.intoGroupManager()) { if (WeworkRoomUtil.intoGroupManager()) {
val textView = AccessibilityUtil.findOneByText(getRoot(), "群公告", exact = true) val textView = AccessibilityUtil.findOneByText(getRoot(), "群公告", exact = true)
@@ -971,7 +1079,7 @@ object WeworkOperationImpl {
* 注:首次为发布 后续为编辑 * 注:首次为发布 后续为编辑
* 注2外部群为edittext 内部群为webview(只能追加文本) * 注2外部群为edittext 内部群为webview(只能追加文本)
*/ */
private fun groupChangeRemark(groupRemark: String? = null): Boolean { private fun groupChangeRemark(groupRemark: String?): Boolean {
if (groupRemark == null) return true if (groupRemark == null) return true
if (WeworkRoomUtil.intoGroupManager()) { if (WeworkRoomUtil.intoGroupManager()) {
val textView = AccessibilityUtil.findOneByText(getRoot(), "备注", exact = true) val textView = AccessibilityUtil.findOneByText(getRoot(), "备注", exact = true)
@@ -1165,7 +1273,7 @@ object WeworkOperationImpl {
.replace(".jpg", "") .replace(".jpg", "")
LogUtils.v("fileTime: $fileTime") LogUtils.v("fileTime: $fileTime")
if (fileTime.isNotBlank()) { if (fileTime.isNotBlank()) {
if (fileTime.toLong() > currentTime) { if (fileTime.toLongOrNull() ?: 0 > currentTime) {
LogUtils.d("找到最新保存二维码图片: $fileTime") LogUtils.d("找到最新保存二维码图片: $fileTime")
try { try {
val bitmap = ImageUtils.bytes2Bitmap(file.readBytes()) val bitmap = ImageUtils.bytes2Bitmap(file.readBytes())

View File

@@ -8,6 +8,7 @@ import com.hjq.toast.ToastUtils;
import org.yameida.worktool.model.WeworkMessageBean; import org.yameida.worktool.model.WeworkMessageBean;
import org.yameida.worktool.model.WeworkMessageListBean; import org.yameida.worktool.model.WeworkMessageListBean;
import org.yameida.worktool.service.WeworkController;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@@ -140,6 +141,9 @@ public class WebSocketManager {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
Log.e(url, "心跳检测" + df.format(new Date()));// new Date()为获取当前系统时间 Log.e(url, "心跳检测" + df.format(new Date()));// new Date()为获取当前系统时间
if (!connecting && (socket == null || !socket.send(HEARTBEAT))) { if (!connecting && (socket == null || !socket.send(HEARTBEAT))) {
//断开链接后关闭新消息接收
WeworkController.INSTANCE.setEnableLoopRunning(false);
//断开链接后进入重连
reConnect(); reConnect();
} }
ToastUtils.show("机器人运行中 请勿人工操作手机~"); ToastUtils.show("机器人运行中 请勿人工操作手机~");

View File

@@ -104,7 +104,7 @@ object WeworkRoomUtil {
sleep(Constant.CHANGE_PAGE_INTERVAL) sleep(Constant.CHANGE_PAGE_INTERVAL)
//消息页搜索结果列表 //消息页搜索结果列表
val selectListView = findOneByClazz(getRoot(), Views.ListView) val selectListView = findOneByClazz(getRoot(), Views.ListView)
val regex = "^$trimTitle(-.*)?(…)?(\\(.*?\\))?" + if (needTrim) "" else "$" val regex = "^$trimTitle" + if (needTrim) ".*?" else "(-.*)?(…)?(\\(.*?\\))?$"
val searchResult = AccessibilityUtil.findOneByTextRegex( val searchResult = AccessibilityUtil.findOneByTextRegex(
selectListView, selectListView,
regex, regex,

View File

@@ -293,7 +293,7 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="开启自动回复" android:text="开启新消息接收"
android:textColor="@color/color_333333" android:textColor="@color/color_333333"
android:textSize="@dimen/setting_start_font_size" /> android:textSize="@dimen/setting_start_font_size" />