from wxpy import *
from PIL import ImageGrab
import os
img_path_name='1.jpg'
def jiepin(img_path=img_path_name):
try:
# 删除此文件
os.remove(img_path)
except:
print('无此文件:'+img_path)
#无参数,默认全屏截图
ImageGrab.grab().save(img_path)
bot = Bot()
# 获取好友
my_friend = bot.friends().search('小和')[0]
# 搜索信息
messages = bot.messages.search(keywords='测试', sender=bot.self)
for message in messages:
print(message)
# 发送文本
my_friend.send('Hello, WeChat!')
# 发送图片
# my_friend.send_image(img_path_name)
# 删除此文件
# os.remove(img_path_name)
# 发送视频
# my_friend.send_video('my_video.mov')
# 发送文件
# my_friend.send_file('my_file.zip')
# 以动态的方式发送图片
# my_friend.send('@img@my_picture.png')
# # 发送公众号
# my_friend.send_raw_msg(
# # 名片的原始消息类型
# raw_type=42,
# # 注意 `username` 在这里应为微信 ID,且被发送的名片必须为自己的好友
# raw_content='<msg username="wxpy_bot" nickname="wxpy 机器人"/>'
# )
# 消息接收监听器
@bot.register()
def print_others(msg):
print('消息:',msg)
print(msg.chat)
# print(len(chat_name['Friend']))
print(msg.text)
# print(len(msg.text))
print('__'*10)
# if chat_name['Friend'].index('qq496631085'):
# r_mes = msg.text
# print(r_mes)
# if str(r_mes)=='1':
# jiepin()
# msg.reply_image(img_path_name)
# if str(r_mes)=='2':
# msg.reply('该指令没指定功能')
# 输出监听到的消息
# try:
# chat_name = msg.chat
# print(chat_name['Friend'])
# if 'qq496631085'==chat_name['Friend']:
# r_mes = msg.text
# print(r_mes)
# if str(r_mes)=='1':
# jiepin()
# msg.reply_image(img_path_name)
# if str(r_mes)=='2':
# msg.reply('该指令没指定功能')
# except:
# print(msg)
# 回复消息
# msg.reply()
# msg.reply("收到")
embed()