Files
codex_jxs_code/test.py

38 lines
991 B
Python
Raw Normal View History

2026-02-28 16:43:38 +08:00
import subprocess
import time
2026-02-28 13:10:47 +08:00
from wxautox4 import WeChat
2026-02-28 16:43:38 +08:00
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')