python微信聊天机器人源码_8.【代码】微信聊天机器人(API的应用) - Python网络爬虫实战...
本文檔僅作為視頻學習過程中的參考
不可用于非法途徑
'''
編程目的:編寫微信機器人
時間:2018-2-25
作者:劉宇
V:1.0
'''
import urllib.request
import urllib.parse
import json
import itchat
# 自動聊天
def autoChat(input_data,userid):
api_url = "http://www.tuling123.com/openapi/api"
post_data = {
"key": "",
"info": input_data,
"loc": "北京市中關村",
"userid": userid,
}
re_content = json.loads(urllib.request.urlopen(urllib.request.Request(url=api_url,data=urllib.parse.urlencode(post_data).encode("utf-8"))).read().decode("utf-8"))["text"]
return re_content
# 自動回復
@itchat.msg_register('Text', isGroupChat=False)
def text_reply(msg):
content = msg["Content"]
fromuser = msg["FromUserName"]
message = autoChat(content,fromuser)
itchat.send(message,fromuser)
# itchat.send(content,我們自己的現在用的微信id)
itchat.login()
itchat.run()
總結
以上是生活随笔為你收集整理的python微信聊天机器人源码_8.【代码】微信聊天机器人(API的应用) - Python网络爬虫实战...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: testmeshpro合批_TextMe
- 下一篇: linux cat cd,linux 文