个人微信接入图灵机器人(基于Python)
编程语言:Python2.7
1.在图灵机器人官网(http://www.tuling123.com)注册账号, 创建机器人, 如果只是学习的话,可以使用2免费版 , 一个账号最多可以创建5个机器人 , 一个机器人日调用接口数5000次
2.安装 itchat 和 pillow : sudo pip install itchat pillow
3.编写代码
1 import itchat, time, re 2 from itchat.content import * 3 import urllib2, urllib 4 import json 5 6 @itchat.msg_register([TEXT]) 7 def text_reply(msg): 8 info = msg["Text"].encode("utf-8") 9 url = "http://www.tuling123.com/openapi/api" 10 data = {u"key":"5a1f91fxxxxxxxxxxxxxxxxxxxx", "info":info, u"loc":"", "userid":""} 11 data = urllib.urlencode(data) 12 url2 = urllib2.Request(url, data) 13 response = urllib2.urlopen(url2) 14 15 apicontent = response.read() 16 s = json.loads(apicontent, encoding="utf-8") 17 print "s==",s 18 if s["code"] == 100000: 19 itchat.send(s["text"], msg["FromUserName"]) 20 21 itchat.auto_login(enableCmdQR=2, hotReload=True) 22 itchat.run(debug=True)
编写代码