python3打造微信聊天機器人僅需20行代碼

#測試可以使用微信聊天

import itchat
import requests
def get_response(msg):
    apiUrl = 'http://www.tuling123.com/openapi/api'
    data = {
        'key': 'c82721e27003495fa974e59878943f4a',  # Tuling Key,替換爲你自己的
        'info': msg,  # 這是我們發出去的消息
        'userid': 'wechat-robot',  # 這裏你想改什麼都可以
    }
    # 我們通過如下命令發送一個 post 請求
    r = requests.post(apiUrl, data=data).json()
    return r.get('text')
@itchat.msg_register(itchat.content.TEXT)
def print_content(msg):
    return get_response(msg['Text'])
@itchat.msg_register([itchat.content.TEXT], isGroupChat=True)
def print_content(msg):
    return get_response(msg['Text'])
itchat.auto_login(True)
itchat.run()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章