63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
# coding=utf-8
|
|
import asyncio
|
|
import logging
|
|
import os
|
|
import time
|
|
import uiautomator2 as u2
|
|
from Apps.AiTeJiYiChong.Kit import click_image_template
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
logger = logging.getLogger("OpenAiTeJiYiChong")
|
|
|
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
async def open_mini_program():
|
|
"""
|
|
异步形式的进入微信小程序: 艾特吉易充
|
|
"""
|
|
d = u2.connect()
|
|
logger.info("执行进入小程序: 艾特吉易充")
|
|
|
|
# 1. 启动微信
|
|
logger.info("启动微信...")
|
|
d.app_start("com.tencent.mm", stop=True)
|
|
await asyncio.sleep(5)
|
|
|
|
# 2. 确保在消息列表页并点击搜索
|
|
logger.info("尝试查找并点击 '搜索按钮'...")
|
|
# 优先尝试从 XinDianTu 的模板中复用 SearchButton.jpg (如果存在)
|
|
search_template = os.path.join(os.path.dirname(BASE_DIR), "XinDianTu", "Templates", "SearchButton.jpg")
|
|
if not os.path.exists(search_template):
|
|
search_template = os.path.join(BASE_DIR, "Templates", "SearchButton.jpg")
|
|
|
|
if click_image_template(d, search_template):
|
|
logger.info("点击了搜索按钮")
|
|
else:
|
|
logger.warning("未找到搜索按钮,使用坐标点击 (84%, 8%)")
|
|
w, h = d.window_size()
|
|
d.click(int(w * 0.84), int(h * 0.08))
|
|
|
|
await asyncio.sleep(2)
|
|
|
|
# 3. 输入搜索内容
|
|
logger.info("输入搜索内容: 艾特吉易充")
|
|
d.send_keys("艾特吉易充")
|
|
await asyncio.sleep(3)
|
|
|
|
# 4. 点击小程序
|
|
logger.info("点击搜索结果中的小程序...")
|
|
# 这里由于没有模板,先使用坐标点击作为第一版的测试逻辑 (通常第一个结果在 50%, 18%)
|
|
# 后续有了截图后再补充模板匹配
|
|
w, h = d.window_size()
|
|
d.click(int(w * 0.5), int(h * 0.18))
|
|
logger.info("已点击搜索结果第一项")
|
|
|
|
await asyncio.sleep(8)
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(open_mini_program())
|