微信 好友消息 和已发送 消息读取

This commit is contained in:
shikong 2025-02-04 22:08:27 +08:00
parent f2e6c5ec37
commit 4ee38b642f
Signed by: Shikong
GPG Key ID: BD85FF18B373C341
8 changed files with 96 additions and 10 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

15
.idea/git_toolbox_prj.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxProjectSettings">
<option name="commitMessageIssueKeyValidationOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
<option name="commitMessageValidationEnabledOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
</component>
</project>

8
.idea/misc.xml Normal file
View File

@ -0,0 +1,8 @@
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.10" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="graalvm-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/uiautomator2.iml" filepath="$PROJECT_DIR$/.idea/uiautomator2.iml" />
</modules>
</component>
</project>

9
.idea/uiautomator2.iml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -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")
d.app_start("com.tencent.mm")

View File

@ -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