久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Python 實(shí)現(xiàn)微信自動(dòng)回復(fù)的方法

瀏覽:52日期:2022-07-11 14:44:49

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

1:安裝itchat

pip install itchat

2:簡(jiǎn)單實(shí)例:

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

import itchatitchat.auto_login()name = itchat.search_friends(name=u’XX’) #XX表示昵稱(chēng)或用戶(hù)名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.textitchat.auto_login()itchat.run()

3:實(shí)現(xiàn)微信自動(dòng)回復(fù)

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

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

#獲取圖靈機(jī)器人回復(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 ’’#正常消息自動(dòng)回復(fù)@itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING])def text_reply(msg):print(msg.type)#設(shè)置默認(rèn)回復(fù)defaultmsg = ’你好’#獲取圖靈機(jī)器人的回復(fù)信息reply = get_msg(msg[’Text’])#如果圖靈機(jī)器人回復(fù)信息有誤則使用默認(rèn)回復(fù)replymsg = reply or defaultmsgreturn replymsg#音頻,圖片自動(dòng)回復(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)#好友請(qǐng)求,自動(dòng)添加并打招呼@itchat.msg_register(FRIENDS)def add_friend(msg): msg.user.verify() msg.user.send(’Nice to meet you!’)#群消息自動(dòng)回復(fù)@itchat.msg_register(TEXT, isGroupChat=True)def text_reply(msg):#設(shè)置默認(rèn)回復(fù)defaultmsg = ’你好’#獲取圖靈機(jī)器人的回復(fù)信息reply = get_msg(msg[’Text’])#如果圖靈機(jī)器人回復(fù)信息有誤則使用默認(rèn)回復(fù)replymsg = reply or defaultmsgreturn replymsgitchat.auto_login(hotReload=True)itchat.run(True)

以上就是Python 實(shí)現(xiàn)微信自動(dòng)回復(fù)的方法的詳細(xì)內(nèi)容,更多關(guān)于python 微信自動(dòng)回復(fù)的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: 微信 Python
相關(guān)文章:
主站蜘蛛池模板: 浪卡子县| 长武县| 井研县| 临湘市| 榆树市| 卢湾区| 五大连池市| 都兰县| 双峰县| 资源县| 卓资县| 长白| 淳安县| 闻喜县| 咸宁市| 潜江市| 福贡县| 松江区| 云和县| 元阳县| 峨山| 辽源市| 莲花县| 长汀县| 奉新县| 新民市| 招远市| 呼和浩特市| 阿城市| 永年县| 凤山市| 新竹市| 修文县| 平果县| 乌兰浩特市| 迁西县| 东明县| 临漳县| 荥阳市| 德格县| 饶阳县|