From bb73fa6d9e555ed67c387b61223d51cc69174c45 Mon Sep 17 00:00:00 2001 From: zhangkai <2403741920@qq.com> Date: Tue, 16 Sep 2025 21:34:15 +0800 Subject: [PATCH] =?UTF-8?q?20250916-=E6=AD=A3=E5=BC=8F=E4=B8=8A=E7=BA=BF?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/iOSAI.iml | 2 +- .idea/misc.xml | 2 +- .idea/workspace.xml | 15 ++++++++---- Entity/ResultData.py | 6 ++--- Module/FlaskService.py | 22 +++++++++--------- Utils/ControlUtils.py | 29 +++++++++++++++++++++++ script/ScriptManager.py | 51 +++++++++++++++++++++-------------------- 7 files changed, 81 insertions(+), 46 deletions(-) diff --git a/.idea/iOSAI.iml b/.idea/iOSAI.iml index 6cb8b9a..894b6b0 100644 --- a/.idea/iOSAI.iml +++ b/.idea/iOSAI.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index db8786c..c27b771 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d2b75fa..23d048a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,11 +4,14 @@ - + + + + \ No newline at end of file diff --git a/Entity/ResultData.py b/Entity/ResultData.py index f0c19f2..31495c5 100644 --- a/Entity/ResultData.py +++ b/Entity/ResultData.py @@ -2,15 +2,15 @@ import json # 返回数据模型 class ResultData(object): - def __init__(self, code=200, data=None, msg="获取成功"): + def __init__(self, code=200, data=None, massage="获取成功"): super(ResultData, self).__init__() self.code = code self.data = data - self.msg = msg + self.massage = massage def toJson(self): return json.dumps({ "code": self.code, "data": self.data, - "msg": self.msg + "massage": self.massage }, ensure_ascii=False) # ensure_ascii=False 确保中文不会被转义 \ No newline at end of file diff --git a/Module/FlaskService.py b/Module/FlaskService.py index 400b1c6..8ee6c8a 100644 --- a/Module/FlaskService.py +++ b/Module/FlaskService.py @@ -266,8 +266,8 @@ def watchLiveForGrowth(): def stopScript(): body = request.get_json() udid = body.get("udid") - code, msg = ThreadManager.stop(udid) - return ResultData(code=code, data="", msg=msg).toJson() + code, massage = ThreadManager.stop(udid) + return ResultData(code=code, data="", massage=massage).toJson() # 关注打招呼 @@ -320,7 +320,7 @@ def addTempAnchorData(): """ data = request.get_json() if not data: - return ResultData(code=400, msg="请求数据为空").toJson() + return ResultData(code=400, massage="请求数据为空").toJson() # 追加到 JSON 文件 AiUtils.save_aclist_flat_append(data, "log/acList.json") return ResultData(data="ok").toJson() @@ -344,17 +344,17 @@ def getChatTextInfo(): data = [ { - 'type': 'msg', + 'type': 'massage', 'dir': 'in', 'text': '当前页面无法获取聊天记录,请在tiktok聊天页面进行获取!!!' }, { - 'type': 'msg', + 'type': 'massage', 'dir': 'in', 'text': 'Unable to retrieve chat messages on the current screen. Please navigate to the TikTok chat page and try again!!!' } ] - return ResultData(data=data, msg="解析失败").toJson() + return ResultData(data=data, massage="解析失败").toJson() # 监控消息 @@ -381,7 +381,7 @@ def upLoadLogLogs(): if ok: return ResultData(data="日志上传成功").toJson() else: - return ResultData(data="", msg="日志上传失败").toJson() + return ResultData(data="", massage="日志上传失败").toJson() # 获取当前的主播列表数据 @@ -449,8 +449,8 @@ def update_last_message(): multi=False # 只改第一条匹配的 ) if updated_count > 0: - return ResultData(data=updated_count, msg="修改成功").toJson() - return ResultData(data=updated_count, msg="修改失败").toJson() + return ResultData(data=updated_count, massage="修改成功").toJson() + return ResultData(data=updated_count, massage="修改失败").toJson() @app.route("/delete_last_message", methods=['POST']) @@ -466,8 +466,8 @@ def delete_last_message(): multi=False # 只改第一条匹配的 ) if updated_count > 0: - return ResultData(data=updated_count, msg="修改成功").toJson() - return ResultData(data=updated_count, msg="修改失败").toJson() + return ResultData(data=updated_count, massage="修改成功").toJson() + return ResultData(data=updated_count, massage="修改失败").toJson() # @app.route("/killWda", methods=['POST']) diff --git a/Utils/ControlUtils.py b/Utils/ControlUtils.py index 975cb9e..d695646 100644 --- a/Utils/ControlUtils.py +++ b/Utils/ControlUtils.py @@ -150,6 +150,8 @@ class ControlUtils(object): print("没有找到主页的第一个视频") return False, num + + @classmethod def clickFollow(cls, session, aid): # 1) 含“关注/已关注/Follow/Following”的首个 cell @@ -177,6 +179,33 @@ class ControlUtils(object): left_x = max(1, rect.x - 20) center_y = rect.y + rect.height // 2 session.tap(left_x, center_y) + @classmethod + def userClickProfile(cls, session, aid): + try: + user_btn = session.xpath("(//XCUIElementTypeButton[@name='用户' and @visible='true'])[1]") + if user_btn: + user_btn.click() + time.sleep(3) + follow_btn = session.xpath( + "(//XCUIElementTypeTable//XCUIElementTypeButton[@name='关注' or @name='已关注'])[1]" + ).get(timeout=5) + if follow_btn: + x, y, w, h = follow_btn.bounds + # 垂直方向中心 + 随机 3~8 像素偏移 + cy = int(y + h / 2 + random.randint(-8, 8)) + # 横向往左偏移 80~120 像素之间的随机值 + cx = int(x - random.randint(80, 120)) + # 点击 + session.tap(cx, cy) + return True + + return False + except Exception as e: + print(e) + return False + + + # 点击一个随机范围 diff --git a/script/ScriptManager.py b/script/ScriptManager.py index 07d131a..b48a3d4 100644 --- a/script/ScriptManager.py +++ b/script/ScriptManager.py @@ -368,17 +368,19 @@ class ScriptManager(): # 定位 "关注" 按钮 通过关注按钮的位置点击主播首页 - session.appium_settings({"snapshotMaxDepth": 23}) + session.appium_settings({"snapshotMaxDepth": 25}) try: # 点击进入首页 ControlUtils.clickFollow(session, aid) LogManager.method_info("点击进入主播首页", "关注打招呼", udid) except wda.WDAElementNotFoundError: - LogManager.method_info("未找到进入主播首页的按钮,跳过点击。", "关注打招呼", udid) - goBack(2) - session.appium_settings({"snapshotMaxDepth": 15}) - continue + LogManager.method_info("未找到进入主播首页的按钮,使用第二个方案。", "关注打招呼", udid) + enter_room = ControlUtils.userClickProfile(session, aid) + if not enter_room: + goBack(2) + session.appium_settings({"snapshotMaxDepth": 15}) + continue time.sleep(2) @@ -510,26 +512,25 @@ class ScriptManager(): goBack(1) # 点击关注按钮 - followButton = AiUtils.getFollowButton(session).get(timeout=5) - if followButton is not None: - # LogManager.method_info("找到关注按钮了", "关注打招呼", udid) - # followButton.click() - x, y, w, h = followButton.bounds - cx = int(x + w / 2) - cy = int(y + h / 2) - # 随机偏移 ±5 px(可自己改范围) - cx += random.randint(-5, 5) - cy += random.randint(-5, 5) - - ControlUtils.tap_mini_cluster(cx, cy, session) - - - else: - LogManager.method_info("没找到关注按钮", "关注打招呼", udid) - time.sleep(1) - goBack(4) - session.appium_settings({"snapshotMaxDepth": 15}) - continue + # followButton = AiUtils.getFollowButton(session).get(timeout=5) + # if followButton is not None: + # # LogManager.method_info("找到关注按钮了", "关注打招呼", udid) + # # followButton.click() + # x, y, w, h = followButton.bounds + # cx = int(x + w / 2) + # cy = int(y + h / 2) + # # 随机偏移 ±5 px(可自己改范围) + # cx += random.randint(-5, 5) + # cy += random.randint(-5, 5) + # + # ControlUtils.tap_mini_cluster(cx, cy, session) + # + # else: + # LogManager.method_info("没找到关注按钮", "关注打招呼", udid) + # time.sleep(1) + # goBack(4) + # session.appium_settings({"snapshotMaxDepth": 15}) + # continue session.appium_settings({"snapshotMaxDepth": 15}) goBack(3)