个人微信接入图灵机器人(基于Python)

时间:2021-06-16 18:51:26

编程语言:Python2.7

1.在图灵机器人官网(http://www.tuling123.com)注册账号, 创建机器人, 如果只是学习的话,可以使用2免费版 , 一个账号最多可以创建5个机器人 , 一个机器人日调用接口数5000次

2.安装 itchat 和 pillow :  sudo pip install itchat pillow

3.编写代码

 import  itchat, time, re
from itchat.content import *
import urllib2, urllib
import json @itchat.msg_register([TEXT])
def text_reply(msg):
info = msg["Text"].encode("utf-8")
url = "http://www.tuling123.com/openapi/api"
data = {u"key":"5a1f91fxxxxxxxxxxxxxxxxxxxx", "info":info, u"loc":"", "userid":""}
data = urllib.urlencode(data)
url2 = urllib2.Request(url, data)
response = urllib2.urlopen(url2) apicontent = response.read()
s = json.loads(apicontent, encoding="utf-8")
print "s==",s
if s["code"] == 100000:
itchat.send(s["text"], msg["FromUserName"]) itchat.auto_login(enableCmdQR=2, hotReload=True)
itchat.run(debug=True)

编写代码