利用itchat可扩展微信功能
http://python.jobbole.com/86532/
http://www.jianshu.com/u/f6bd2daa7862
itchat基础新手入门:
http://itchat.readthedocs.io/zh/latest/tutorial/tutorial0/
1.安装 itchat
pip install itchat
2.启动
itchat.auto_login()
itchat.run()
3.发送信息
itchat.send(‘msg’,toUserName = ‘Username’)
向 ‘Username’ 发送信息
4.与账号通信(我自己个人账号不能和自己通信)
@itchat.msg_register(itchat.content.TEXT)
def uer_reply(msg):
# msg[‘ToUserName’] 为通信人名
print(msg[‘Text’])
将接收到的信息打印出来
5.实现一个微信机器人
1.调用图灵机器人接口
教程:http://itchat.readthedocs.io/zh/latest/tutorial/tutorial0/
2.实现与图灵机器人的通信
def get_tuling_respones(msg):
url = ‘http://www.tuling123.com/openapi/api’
data = {
‘key’:’eb720a8970964f3f855d863d24406576’,
‘info’:msg,
‘userid’:’wechat-robot’
}
try:
r = requests.post(url,data=data).json()
return r.get(‘text’)
except:
return
@itchat.msg_register(itchat.content.TEXT)
def tuling_reply(msg):
# 此处判断是否与文件传输助手进行通信。
if msg[‘ToUserName’] != ‘filehelper’:
return 0
default_reply = ‘I received:’ + msg[‘Text’]
reply = get_tuling_respones(msg[‘Text’])
itchat.send(reply,’filehelper’)
return reply or default_reply