+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..4f2ea69
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..1358530
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiautomator2.iml b/.idea/uiautomator2.iml
new file mode 100644
index 0000000..1270544
--- /dev/null
+++ b/.idea/uiautomator2.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/api/wechat.py b/api/wechat.py
index 709234d..a144307 100644
--- a/api/wechat.py
+++ b/api/wechat.py
@@ -18,15 +18,17 @@ class WechatSearchInput(Device):
input_text: str
-@router.post("/search/input")
+@router.post("/search/chat")
async def wechat_search_task(item: WechatSearchInput):
if item.serial not in devices:
return Response(code=500, msg="设备 {} 不存在".format(item.serial))
d = devices[item.serial]
+ d.app_start("com.tencent.mm")
+
tasks.wechat.click_search_btn(d)
tasks.wechat.input_search_text(d, item.search_keyword)
tasks.wechat.click_search_result(d)
- tasks.wechat.get_last_chat_text(d)
+ print(tasks.wechat.get_last_friend_text_msg(d))
# tasks.wechat.input_chat_text(d, time.strftime("[AI] %Y-%m-%d %H:%M:%S", time.localtime()))
tasks.wechat.input_chat_text(d, item.input_text)
@@ -36,4 +38,5 @@ def wechat_launch(item: Device):
return Response(code=500, msg="设备 {} 不存在".format(item.serial))
d = devices[item.serial]
- d.app_start("com.tencent.mm")
\ No newline at end of file
+ d.app_start("com.tencent.mm")
+
diff --git a/tasks/wechat/__init__.py b/tasks/wechat/__init__.py
index 1465467..4225205 100644
--- a/tasks/wechat/__init__.py
+++ b/tasks/wechat/__init__.py
@@ -9,6 +9,8 @@ def click_search_btn(d: Device):
selector.click()
else:
logging.warning("未找到组件")
+ d.press("back")
+ click_search_btn(d)
def input_search_text(d: Device, text: str):
@@ -50,11 +52,38 @@ def input_chat_text(d: Device, text: str):
selector.click()
-def get_last_chat_text(d: Device):
- selector = (d.xpath('//*[@resource-id="com.tencent.mm:id/bn1"]')
- .child('//*[@resource-id="com.tencent.mm:id/bkl"]'))
- elements = selector.all()
- if len(elements) > 0:
- last_element = elements[-1]
- print(last_element.text)
+
+def get_friend_text_msgs(d: Device):
+ selector = d.xpath('//*[@resource-id="com.tencent.mm:id/bp0"]/android.widget.RelativeLayout')
+
+ elements = selector.all()
+ msg = []
+ for item in elements:
+ # 好友消息
+ el = item.elem.xpath("android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.TextView")
+ if len(el) > 0 :
+ msg.append(el[0].get("text"))
+
+ return msg
+
+def get_last_friend_text_msg(d: Device):
+ msgs = get_friend_text_msgs(d)
+ return msgs[-1] if len(msgs) > 0 else None
+
+def get_my_text_msgs(d: Device):
+ selector = d.xpath('//*[@resource-id="com.tencent.mm:id/bp0"]/android.widget.RelativeLayout')
+
+ elements = selector.all()
+ msg = []
+ for item in elements:
+ # 自己的消息
+ el = item.elem.xpath("android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]android.widget.TextView")
+ if len(el) > 0 :
+ msg.append(el[0].get("text"))
+
+ return msg
+
+def get_last_my_text_msg(d: Device):
+ msgs = get_friend_text_msgs(d)
+ return msgs[-1] if len(msgs) > 0 else None
\ No newline at end of file