天天看點

python—微信

pip install itchat

注意這裡的微信的掃碼登陸時屬于網頁端登陸,如果是最近新注冊的微信号就沒有網頁端登入了,我應該是14年左右注冊的,是可以的

最好不要涉及太多群的操作,操作不能太頻繁,否則網頁端微信可能被封

登入

import itchat

itchat.auto_login()
#itchat.auto_login(hotReload=True)
itchat.send("Hello,filehelper", toUserName = 'filehelper')
           
itchat.auto_login(hotReload=True)  可以不用一次次的重複登入了就
python—微信
python—微信
python—微信

發送回複給自己的文本消息

import itchat

@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
    return msg['Text']

itchat.auto_login()
itchat.run()
           
python—微信
python—微信
python—微信

@itchat.msg_register(itchat.content.TEXT)

itchat将根據接收到的消息類型尋找對應的已經注冊的方法

python—微信

reply_text=msg['Text']

設定一個reply_text儲存我們的回複内容. msg[Text]是我們收到的文本消息内容,即預設回複收到的文本内容

根據微信文本内容回複消息

import itchat

@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
    reply_text = msg['Text']
    if msg['Text'] == '你好':
        reply_text = '不好!'
    elif msg['Text'] == '你是誰':
        reply_text = "hxx!"
    return reply_text

itchat.auto_login()
itchat.run()
           
python—微信
python—微信
python—微信
如果不是if else裡面寫的回複内容,就預設重複對方的話