python如何发送短信_怎么发送python文件

python如何发送短信_怎么发送python文件发送消息可以通过多种方法实现 以下是几种常见的方法 方法一 使用 win32 API pythonimport win32guiimpo win32conimpo win32clipboa as w def send message receiver name message 设置要发送的消息 msg message 打开聊天窗口 handle

发送消息可以通过多种方法实现,以下是几种常见的方法:

方法一:使用win32 API

python

import win32gui

import win32con

import win32clipboard as w

def send__message(receiver_name, message):

设置要发送的消息

msg = message

打开聊天窗口

handle = win32gui.FindWindow(None, receiver_name)

if handle:

将消息复制到剪贴板

w.OpenClipboard()

w.EmptyClipboard()

w.SetClipboardData(win32con.CF_UNICODETEXT, msg)

w.CloseClipboard()

发送消息

win32gui.SendMessage(handle, win32con.WM_PASTE, 0, 0)

win32gui.SendMessage(handle, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)

else:

print("找不到聊天窗口")

示例使用

send__message("哈哈", "你好,你不好,你好,哈哈哈!")

方法二:使用pyautogui和pyperclip

python

import subprocess

import pyautogui

import pyperclip

def send__message_pyautogui(, text):

打开聊天窗口

subprocess.Popen(f"start tencent://message/?uin={}")

等待窗口打开

pyautogui.sleep(1)

复制文本到剪贴板

pyperclip.copy(text)

模拟粘贴和发送消息

pyautogui.hotkey("ctrl", "v")

pyautogui.hotkey("alt", "s")

示例使用

send__message_pyautogui("", "你好,这是自动发送的消息!")

方法三:使用第三方库bot

python

from bot import Bot

def send__message_bot(bot_token, bot_secret, sender_, receiver_, message):

创建Bot实例

bot = Bot(token=bot_token, secret=bot_secret)

登录

bot.login(sender_, bot_secret)

发送消息

bot.send(receiver_, message)

登出

bot.logout()

示例使用

send__message_bot("your_bot_token", "your_bot_secret", "your__number", "friend__number", "Hello, this is an automated message!")

注意事项

确保聊天窗口在屏幕上,没有被最小化或覆盖。

代码中可能需要根据实际的版本和操作系统进行调整。

如果是在无界面服务器上操作,可能需要先将信息传送到本地电脑,再由本地电脑发送消息。

发送大量消息可能会触发的频率限制,导致发送失败。

请选择适合您需求的方法进行尝试。

编程小号
上一篇 2026-04-05 21:10
下一篇 2025-04-21 12:28

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://sigusoft.com/bj/62217.html