哈哈
This commit is contained in:
39
test.py
39
test.py
@@ -1,5 +1,38 @@
|
||||
import subprocess
|
||||
import time
|
||||
from wxautox4 import WeChat
|
||||
|
||||
wx = WeChat()
|
||||
wx.ChatWith('Rainbow') # 切换到目标聊天
|
||||
# 再通过 UIAutomation 定位并点击语音/视频通话按钮
|
||||
def make_wechat_call(contact_name, retry_times=3):
|
||||
"""
|
||||
可靠的微信拨电话方法
|
||||
|
||||
Args:
|
||||
contact_name: 联系人名称
|
||||
retry_times: 重试次数
|
||||
"""
|
||||
for attempt in range(retry_times):
|
||||
try:
|
||||
# 打开微信应用
|
||||
subprocess.Popen(['/Applications/WeChat.app/Contents/MacOS/WeChat'])
|
||||
time.sleep(2) # 等待微信启动
|
||||
|
||||
# 初始化
|
||||
wx = WeChat()
|
||||
time.sleep(1)
|
||||
|
||||
# 切换聊天
|
||||
wx.ChatWith(contact_name)
|
||||
time.sleep(1)
|
||||
|
||||
print(f"✓ 已切换到 {contact_name} 聊天")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"⚠ 第 {attempt+1} 次尝试失败: {e}")
|
||||
if attempt < retry_times - 1:
|
||||
time.sleep(1)
|
||||
|
||||
return False
|
||||
|
||||
# 使用
|
||||
make_wechat_call('Rainbow')
|
||||
Reference in New Issue
Block a user