欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python3操作微信itchat實現(xiàn)發(fā)送圖片

 更新時間:2018年02月24日 10:05:01   作者:小彌彌子  
這篇文章主要為大家詳細(xì)介紹了python3操作微信itchat實現(xiàn)發(fā)送圖片,具有一定的參考價值,感興趣的小伙伴們可以參考一下

兩個代碼,一個是把python當(dāng)微信操作,可以查看自己的好友信息,群信息等。還可以定時發(fā)送文本,文件等。效果就和你本人操作一樣,沒差別。

還有一個是連接你的微信和圖靈機器人,別人和你說話可以自動回復(fù)(非常愚蠢)。

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 "呵呵" #出問題就回復(fù)“呵呵”


@itchat.msg_register(itchat.content.TEXT)
def tuling_reply(msg):
 defaultReply = 'I received: ' + msg['Text'] #一個默認(rèn)回復(fù)
 reply = get_response(msg['Text']) 
 return reply or defaultReply

itchat.auto_login(hotReload=True) #熱啟動,不需要多次掃碼登錄
itchat.run()

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論