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

Python 實現(xiàn)微信自動回復(fù)的方法

 更新時間:2020年09月11日 10:45:02   作者:王建  
這篇文章主要介紹了Python 實現(xiàn)微信自動回復(fù)的方法,幫助大家更好的理解和使用python,感興趣的朋友可以了解下

眾所周知QQ上面是可以設(shè)置自動回復(fù)的,但是微信上面并不可以。最近在學(xué)習Python,發(fā)現(xiàn)Python的適用范圍是真的很廣,這里使用itchat組件實現(xiàn)微信的自動回復(fù)

1:安裝itchat

pip install itchat

2:簡單實例:

(1):發(fā)送信息

import itchat
itchat.auto_login()
name = itchat.search_friends(name=u'XX') #XX表示昵稱或用戶名
userName = name[0]["UserName"]
print(userName )
itchat.send_msg('。。。', toUserName=userName)

(2):回復(fù)發(fā)給自己的文本消息

import itchat
@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
  return msg.text
itchat.auto_login()
itchat.run()

3:實現(xiàn)微信自動回復(fù)

這里使用到了圖靈機器人 http://www.tuling123.com/

注冊一個賬號添加一個機器人然后根據(jù)api文檔使用接口即可獲得機器人返回值

#獲取圖靈機器人回復(fù)信息
def get_msg(msg):
apiUrl = 'http://openapi.tuling123.com/openapi/api/v2'
data = {
  "perception": {
    "inputText": {
      "text": msg
    },
  },
  "userInfo": {
    "apiKey": "cfada3289203426f842746afdc5c0806",
    "userId": "demo"
  }
}
data = json.dumps(data)
try:
r = requests.post(apiUrl,data = data).json()
return r['results'][0]['values']['text']
except:
return ''
#正常消息自動回復(fù)
@itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING])
def text_reply(msg):
print(msg.type)
#設(shè)置默認回復(fù)
defaultmsg = '你好'
#獲取圖靈機器人的回復(fù)信息
reply = get_msg(msg['Text'])
#如果圖靈機器人回復(fù)信息有誤則使用默認回復(fù)
replymsg = reply or defaultmsg
return replymsg
#音頻,圖片自動回復(fù)
@itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
def download_files(msg):
  msg.download(msg.fileName)
  typeSymbol = {
    PICTURE: 'img',
    VIDEO: 'vid', }.get(msg.type, 'fil')
  return '@%s@%s' % (typeSymbol, msg.fileName)
#好友請求,自動添加并打招呼
@itchat.msg_register(FRIENDS)
def add_friend(msg):
  msg.user.verify()
  msg.user.send('Nice to meet you!')
#群消息自動回復(fù)
@itchat.msg_register(TEXT, isGroupChat=True)
def text_reply(msg):
#設(shè)置默認回復(fù)
defaultmsg = '你好'
#獲取圖靈機器人的回復(fù)信息
reply = get_msg(msg['Text'])
#如果圖靈機器人回復(fù)信息有誤則使用默認回復(fù)
replymsg = reply or defaultmsg
return replymsg
itchat.auto_login(hotReload=True)
itchat.run(True)

以上就是Python 實現(xiàn)微信自動回復(fù)的方法的詳細內(nèi)容,更多關(guān)于python 微信自動回復(fù)的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論