python3操作微信itchat实现发送图片 两个代码,一个是把python当微信操作,可以查看自己的好友信息,群信息等。还可以定时发送文本,文件等。效果就和你本人操作一样,没差别。 还有一个是连接你的微信和图灵机器人,别人和你说话可以自动回复(非常愚蠢)。 itchat.search_friends(name=r' ‘) 是找到某好友 itchat.get_chatrooms(update=True)是获得所有群。同类。 #coding=utf8 import itchat itchat.auto_login(hotReload=True) #热启动你的微信 #itchat.run() rooms=itchat.get_chatrooms(update=True) for i in range(len(rooms)): print(rooms[i]) #查看你多有的群 room = itchat.search_friends(name=r' ') #这里输入你好友的名字或备注。 print(room) userName = room[0]['UserName'] f="C:\文件/lh.jpg" #图片地址 try: itchat.send_image(f,toUserName=userName) 如果是其他文件可以直接send_file print("success") except: print("fail") 二、首先去图灵机器人注册账号,查看api接口和key: #coding=utf8 import requests import itchat def get_response(msg): apiUrl = 'http://www.tuling123.com/openapi/api' data = { 'key' : '', #这里自行输入key 'info' : msg, 'userid' : '175007', #这是我的账号 } try: r = requests.post(apiUrl, data=data).json() return r.get('text') except: return "呵呵" #出问题就回复“呵呵” @itchat.msg_register(itchat.content.TEXT) def tuling_reply(msg): defaultReply = 'I received: ' + msg['Text'] #一个默认回复 reply = get_response(msg['Text']) return reply or defaultReply itchat.auto_login(hotReload=True) #热启动,不需要多次扫码登录 itchat.run() 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持中文源码网。