update 兼容企微4.1.8;好友信息/群信息/拉人/踢人

This commit is contained in:
gallonyin
2023-08-26 12:58:01 +08:00
parent 4a6284a71d
commit 746d7919d5
4 changed files with 97 additions and 14 deletions

View File

@@ -554,7 +554,6 @@ object WeworkController {
/** /**
* 获取好友信息 * 获取好友信息
* @see WeworkMessageBean.GET_FRIEND_INFO * @see WeworkMessageBean.GET_FRIEND_INFO
* TODO
* @param message#selectList 好友名列表 * @param message#selectList 好友名列表
*/ */
@RequestMapping @RequestMapping

View File

@@ -18,6 +18,7 @@ object WeworkGetImpl {
/** /**
* 获取群信息 * 获取群信息
* @see WeworkMessageBean.GET_GROUP_INFO
* @param selectList 群名列表 为空时去群管理页查询并返回群聊页 * @param selectList 群名列表 为空时去群管理页查询并返回群聊页
*/ */
fun getGroupInfo(message: WeworkMessageBean, selectList: List<String>): Boolean { fun getGroupInfo(message: WeworkMessageBean, selectList: List<String>): Boolean {
@@ -32,6 +33,7 @@ object WeworkGetImpl {
/** /**
* 获取好友信息 * 获取好友信息
* @see WeworkMessageBean.GET_FRIEND_INFO
* @param selectList 好友名列表 * @param selectList 好友名列表
*/ */
fun getFriendInfo(message: WeworkMessageBean, selectList: List<String>): Boolean { fun getFriendInfo(message: WeworkMessageBean, selectList: List<String>): Boolean {
@@ -340,14 +342,15 @@ object WeworkGetImpl {
val count = tvCount.text.toString().replace("", "") val count = tvCount.text.toString().replace("", "")
weworkMessageBean.groupNumber = count.toIntOrNull() weworkMessageBean.groupNumber = count.toIntOrNull()
} }
val gridView = AccessibilityUtil.findOneByClazz(getRoot(), Views.GridView) val gridView = AccessibilityUtil.findOnceByClazz(getRoot(), Views.GridView)
if (gridView != null && gridView.childCount >= 2) { if (gridView != null && gridView.childCount >= 2) {
LogUtils.i("获取群成员 使用GridView")
val tvOwnerName = AccessibilityUtil.findOnceByClazz(gridView.getChild(0), Views.TextView) val tvOwnerName = AccessibilityUtil.findOnceByClazz(gridView.getChild(0), Views.TextView)
if (tvOwnerName != null && tvOwnerName.text != null) { if (tvOwnerName != null && tvOwnerName.text != null) {
LogUtils.d("群主: " + tvOwnerName.text) LogUtils.d("群主: " + tvOwnerName.text)
weworkMessageBean.groupOwner = tvOwnerName.text.toString() weworkMessageBean.groupOwner = tvOwnerName.text.toString()
} }
if (weworkMessageBean.groupNumber ?: 0 <= 8) { if ((weworkMessageBean.groupNumber ?: 0) <= 8) {
val set = linkedSetOf<String>() val set = linkedSetOf<String>()
for (i in 0 until gridView.childCount) { for (i in 0 until gridView.childCount) {
val item = gridView.getChild(i) val item = gridView.getChild(i)
@@ -358,6 +361,28 @@ object WeworkGetImpl {
LogUtils.d("群成员: ${set.joinToString()}") LogUtils.d("群成员: ${set.joinToString()}")
weworkMessageBean.nameList = set.toList() weworkMessageBean.nameList = set.toList()
} }
} else {
LogUtils.i("获取群成员 使用RecyclerView")
val recyclerViewList = AccessibilityUtil.findAllOnceByClazz(getRoot(), Views.RecyclerView)
if (recyclerViewList.size >= 2 && recyclerViewList[1].childCount >= 2) {
val rvList = recyclerViewList[1]
val tvOwnerName = AccessibilityUtil.findOnceByClazz(rvList.getChild(0), Views.TextView)
if (tvOwnerName != null && tvOwnerName.text != null) {
LogUtils.d("群主: " + tvOwnerName.text)
weworkMessageBean.groupOwner = tvOwnerName.text.toString()
}
if ((weworkMessageBean.groupNumber ?: 0) <= 8) {
val set = linkedSetOf<String>()
for (i in 0 until rvList.childCount) {
val item = rvList.getChild(i)
val name = AccessibilityUtil.findOnceByClazz(item, Views.TextView)?.text?.toString()
?: continue
set.add(name)
}
LogUtils.d("群成员: ${set.joinToString()}")
weworkMessageBean.nameList = set.toList()
}
}
} }
val tvAnnouncementFlag = AccessibilityUtil.findOnceByText(getRoot(), "群公告", exact = true) val tvAnnouncementFlag = AccessibilityUtil.findOnceByText(getRoot(), "群公告", exact = true)
val tvAnnouncement = AccessibilityUtil.findBackNode(tvAnnouncementFlag) val tvAnnouncement = AccessibilityUtil.findBackNode(tvAnnouncementFlag)

View File

@@ -2100,7 +2100,9 @@ object WeworkOperationImpl {
): Boolean { ): Boolean {
if (selectList.isNullOrEmpty()) return true if (selectList.isNullOrEmpty()) return true
if (WeworkRoomUtil.intoGroupManager()) { if (WeworkRoomUtil.intoGroupManager()) {
val gridView = AccessibilityUtil.findOneByClazz(getRoot(), Views.GridView) AccessibilityUtil.findOneByText(getRoot(), "全部群成员", "微信用户创建", timeout = Constant.CHANGE_PAGE_INTERVAL)
?: return false
val gridView = AccessibilityUtil.findOnceByClazz(getRoot(), Views.GridView)
if (gridView != null && gridView.childCount >= 2) { if (gridView != null && gridView.childCount >= 2) {
val tvEmptySize = AccessibilityUtil.findAllOnceByClazz(gridView, Views.TextView) val tvEmptySize = AccessibilityUtil.findAllOnceByClazz(gridView, Views.TextView)
.filter { it.text == null }.size .filter { it.text == null }.size
@@ -2108,12 +2110,30 @@ object WeworkOperationImpl {
if (tvEmptySize == 0) { if (tvEmptySize == 0) {
return true return true
} else if (tvEmptySize == 1 || tvEmptySize == 2) { } else if (tvEmptySize == 1 || tvEmptySize == 2) {
LogUtils.d("点击拉人按钮")
AccessibilityUtil.performClick(gridView.getChild(gridView.childCount - tvEmptySize)) AccessibilityUtil.performClick(gridView.getChild(gridView.childCount - tvEmptySize))
} }
} else { } else {
LogUtils.e("未找到添加成员按钮") val recyclerViewList = AccessibilityUtil.findAllOnceByClazz(getRoot(), Views.RecyclerView)
error("未找到添加成员按钮") if (recyclerViewList.size >= 2 && recyclerViewList[1].childCount >= 2) {
return false val rvList = recyclerViewList[1]
var ivEmptySize = 0
for (i in 0 until rvList.childCount) {
if (rvList.getChild(i).childCount == 1) {
ivEmptySize++
}
}
if (ivEmptySize == 0) {
return true
} else if (ivEmptySize == 1 || ivEmptySize == 2) {
LogUtils.d("点击拉人按钮")
AccessibilityUtil.performClick(rvList.getChild(rvList.childCount - ivEmptySize))
}
} else {
LogUtils.e("未找到添加成员按钮")
error("未找到添加成员按钮")
return false
}
} }
//群详情列表 //群详情列表
val list = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView) val list = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView)
@@ -2223,7 +2243,10 @@ 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) AccessibilityUtil.findOneByText(getRoot(), "全部群成员", "微信用户创建", timeout = Constant.CHANGE_PAGE_INTERVAL)
?: return false
var ivEmptySize = 0
val gridView = AccessibilityUtil.findOnceByClazz(getRoot(), Views.GridView)
if (gridView != null && gridView.childCount >= 2) { if (gridView != null && gridView.childCount >= 2) {
val tvEmptySize = AccessibilityUtil.findAllOnceByClazz(gridView, Views.TextView) val tvEmptySize = AccessibilityUtil.findAllOnceByClazz(gridView, Views.TextView)
.filter { it.text == null }.size .filter { it.text == null }.size
@@ -2233,12 +2256,31 @@ object WeworkOperationImpl {
error("未找到踢人按钮") error("未找到踢人按钮")
return true return true
} else if (tvEmptySize == 2) { } else if (tvEmptySize == 2) {
LogUtils.d("点击踢人按钮")
AccessibilityUtil.performClick(gridView.getChild(gridView.childCount - 1)) AccessibilityUtil.performClick(gridView.getChild(gridView.childCount - 1))
} }
} else { } else {
LogUtils.e("未找到删除成员按钮") val recyclerViewList = AccessibilityUtil.findAllOnceByClazz(getRoot(), Views.RecyclerView)
error("未找到删除成员按钮") if (recyclerViewList.size >= 2 && recyclerViewList[1].childCount >= 2) {
return false val rvList = recyclerViewList[1]
for (i in 0 until rvList.childCount) {
if (rvList.getChild(i).childCount == 1) {
ivEmptySize++
}
}
if (ivEmptySize <= 1) {
LogUtils.e("未找到踢人按钮")
error("未找到踢人按钮")
return true
} else if (ivEmptySize == 2) {
LogUtils.d("点击踢人按钮")
AccessibilityUtil.performClick(rvList.getChild(rvList.childCount - 1))
}
} else {
LogUtils.e("未找到删除成员按钮")
error("未找到删除成员按钮")
return false
}
} }
//群详情列表 //群详情列表
val list = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView) val list = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView)
@@ -2246,7 +2288,7 @@ object WeworkOperationImpl {
val frontNode = AccessibilityUtil.findFrontNode(list, 2) val frontNode = AccessibilityUtil.findFrontNode(list, 2)
val textViewList = AccessibilityUtil.findAllOnceByClazz(frontNode, Views.TextView) val textViewList = AccessibilityUtil.findAllOnceByClazz(frontNode, Views.TextView)
if (textViewList.size >= 2) { if (textViewList.size >= 2) {
val multiButton = textViewList.lastOrNull() val multiButton = if (ivEmptySize == 0) textViewList.lastOrNull() else textViewList[textViewList.size - 2]
var count = 0 var count = 0
for (select in LinkedHashSet(removeList)) { for (select in LinkedHashSet(removeList)) {
val needTrim = select.contains(Constant.regTrimTitle) val needTrim = select.contains(Constant.regTrimTitle)

View File

@@ -184,7 +184,7 @@ object WeworkRoomUtil {
* @return true 成功进入好友详情页 * @return true 成功进入好友详情页
*/ */
fun intoFriendDetail(): Boolean { fun intoFriendDetail(): Boolean {
if (AccessibilityUtil.findOnceByText(getRoot(), "设置聊天背景") != null) { if (AccessibilityUtil.findOneByText(getRoot(), "设置聊天背景", timeout = Constant.CHANGE_PAGE_INTERVAL) != null) {
return true return true
} }
//同群详情列表 //同群详情列表
@@ -211,14 +211,31 @@ object WeworkRoomUtil {
fun getFriendName(): ArrayList<String> { fun getFriendName(): ArrayList<String> {
val titleList = arrayListOf<String>() val titleList = arrayListOf<String>()
if (intoFriendDetail()) { if (intoFriendDetail()) {
val gridView = findOneByClazz(getRoot(), Views.GridView) if (AccessibilityUtil.findOneByText(getRoot(), "设置聊天背景", timeout = Constant.CHANGE_PAGE_INTERVAL) != null) {
LogUtils.e("获取好友名称失败 校验未进入好友详情页")
return titleList
}
val gridView = AccessibilityUtil.findOnceByClazz(getRoot(), Views.GridView)
if (gridView != null && gridView.childCount >= 2) { if (gridView != null && gridView.childCount >= 2) {
LogUtils.i("获取好友名称 使用GridView")
val tvList = findAllOnceByClazz(gridView.getChild(0), Views.TextView) val tvList = findAllOnceByClazz(gridView.getChild(0), Views.TextView)
for (textView in tvList) { for (textView in tvList) {
if (textView.text != null) { if (textView.text != null) {
titleList.add(textView.text.toString()) titleList.add(textView.text.toString())
} }
} }
} else {
LogUtils.i("获取好友名称 使用RecyclerView")
val recyclerViewList = AccessibilityUtil.findAllOnceByClazz(getRoot(), Views.RecyclerView)
if (recyclerViewList.size >= 2 && recyclerViewList[1].childCount >= 2) {
val rvList = recyclerViewList[1]
val tvList = findAllOnceByClazz(rvList.getChild(0), Views.TextView)
for (textView in tvList) {
if (textView.text != null) {
titleList.add(textView.text.toString())
}
}
}
} }
backPress() backPress()
LogUtils.d("获取好友名称成功 ${titleList.joinToString()}") LogUtils.d("获取好友名称成功 ${titleList.joinToString()}")