import
numpy as np
from
uiautomation
import
WindowControl
import
requests
import
json
import
time
wx
=
WindowControl(
Name
=
'微信'
,
searchDepth
=
1
)
wx.SwitchToThisWindow()
hw
=
wx.ListControl(Name
=
'会话'
)
def
is_group_chat(contact_name):
group_keywords
=
[
'工作'
,
'团队'
,
'群'
]
for
keyword
in
group_keywords:
if
keyword
in
contact_name:
return
True
return
False
while
True
:
we
=
hw.TextControl(searchDepth
=
4
)
while
not
we.Exists():
pass
if
we.Name:
we.Click(simulateMove
=
False
)
contact_name
=
wx.ListControl(Name
=
'消息'
).GetChildren()[
-
1
].Name
print
(f
"当前会话: {contact_name}"
)
if
is_group_chat(contact_name):
print
(
"检测到群聊,跳过自动回复"
)
continue
last_msg
=
wx.ListControl(Name
=
'消息'
).GetChildren()[
-
1
].Name
print
(f
"收到消息: {last_msg}"
)
sess
=
requests.get(
(
'http://route.showapi.com/60-27?&showapi_appid=102421&userid=userid&showapi_sign=77760de9bbc640f68433718f807b3e42&info='
+
last_msg))
js
=
sess.text
js
=
json.loads(js)
replyMsg
=
'原主人不在机器人自动回复:'
+
js[
'showapi_res_body'
][
'text'
]
result
=
replyMsg
print
(f
"回复内容: {result}"
)
time.sleep(
3
)
wx.SendKeys(result.replace(
'{br}'
,
'{Shift}{Enter}'
), waitTime
=
1
)
time.sleep(
2
)
wx.SendKeys(
'{Enter}'
, waitTime
=
1
)
wx.TextControl(SubName
=
result[:
5
]).RightClick()
time.sleep(
5
)