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/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/AiUtils.py b/Utils/AiUtils.py index 69c5a47..5cedf6d 100644 --- a/Utils/AiUtils.py +++ b/Utils/AiUtils.py @@ -406,6 +406,7 @@ class AiUtils(object): '分享发布内容', '视频贴纸标签页', '双击发送表情', '贴纸', } SYSTEM_PATTERNS = [ + r"(消息请求已被接受|你开始了和.*的聊天|你打开了这个与.*的聊天).*" r"回复时接收通知", r"开启(私信)?通知", r"开启通知", r"你打开了这个与 .* 的聊天。.*隐私", r"在此用户接受你的消息请求之前,你最多只能发送 ?\d+ 条消息。?", diff --git a/Utils/ControlUtils.py b/Utils/ControlUtils.py index a342860..028983f 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/Utils/Requester.py b/Utils/Requester.py index 1ab6d73..b2039b5 100644 --- a/Utils/Requester.py +++ b/Utils/Requester.py @@ -17,7 +17,7 @@ class Requester(): "vvtoken": token, } url = BaseUrl + cls.prologue - result = requests.get(headers=headers, url=url) + result = requests.get(headers=headers, url=url, verify=False) json = result.json() data = json.get("data") for i in data: @@ -29,14 +29,18 @@ class Requester(): @classmethod def translation(cls, msg, country="英国"): try: + if country == "": + country = "英国" + param = { "msg": msg, "country": country, } url = "https://ai.yolozs.com/translation" - result = requests.post(url=url, json=param) + result = requests.post(url=url, json=param, verify=False) - LogManager.info(f"翻译,状态码:{result.status_code},服务器返回的内容:{result.text}") + LogManager.info(f"翻译 请求的参数:{param}", "翻译") + LogManager.info(f"翻译,状态码:{result.status_code},服务器返回的内容:{result.text}", "翻译") if result.status_code != 200: LogManager.error(f"翻译失败,状态码:{result.status_code},服务器返回的内容:{result.text}") @@ -66,11 +70,9 @@ class Requester(): param["inputs"] = inputs - print(param) - try: url = "https://ai.yolozs.com/chat" - result = requests.post(url=url, json=param) + result = requests.post(url=url, json=param, verify=False) json = result.json() data = json.get("answer", {}) session_id = json.get("conversation_id", {}) diff --git a/script/ScriptManager.py b/script/ScriptManager.py index d9e116e..b48a3d4 100644 --- a/script/ScriptManager.py +++ b/script/ScriptManager.py @@ -368,18 +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) @@ -481,7 +482,8 @@ class ScriptManager(): if isContainChniese: # 翻译成主播国家的语言 - LogManager.method_info(f"需要翻译:{text},参数为:国家为{anchorCountry}, 即将进行翻译", "关注打招呼", udid) + LogManager.method_info(f"需要翻译:{text},参数为:国家为{anchorCountry}, 即将进行翻译", + "关注打招呼", udid) msg = Requester.translation(text, anchorCountry) @@ -510,10 +512,19 @@ class ScriptManager(): goBack(1) # 点击关注按钮 - # followButton = AiUtils.getFollowButton(session) + # followButton = AiUtils.getFollowButton(session).get(timeout=5) # if followButton is not None: - # LogManager.method_info("找到关注按钮了", "关注打招呼", udid) - # followButton.click() + # # 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) @@ -734,7 +745,8 @@ class ScriptManager(): last_msg_text = last_msg else: - LogManager.method_info(f"对方发送的消息不是语言,随机挑选作为最后一条进行回复:{last_msg}", "检测消息", udid) + LogManager.method_info(f"对方发送的消息不是语言,随机挑选作为最后一条进行回复:{last_msg}", + "检测消息", udid) last_msg_text = random.choice(text_list) if AiUtils.contains_chinese(last_msg_text):