python微信图灵机器人
2018-12-20 本文已影响18人
倪大头
需要在图灵官网注册一个机器人,拿到key,然后通过wxpy框架扫码登录网页版微信,就可以玩耍了
from wxpy import *
import requests
import json
robot = Bot()
def talk_robot(info='你好,旅行者!'):
api_url = 'http://www.tuling123.com/openapi/api'
api_key = 'dadfajldfjanoalabnaljblabbab'//这个key是我瞎打的,填图灵官网拿到的key
data = {'key': api_key, 'info': info}
r = requests.post(api_url, data=data).text
response = json.loads(r)['text']
return response
# @robot.register()
# def print_group_msg(msg):
# if msg.is_at:
# message = '{}'.format(msg.text)
# response = talk_robot(info=message)
# return response
@robot.register()
def print_group_msg(msg):
# 如果是群聊,但没有被 @,则不回复
if isinstance(msg.chat, Group) and not msg.is_at:
return
else:
message = '{}'.format(msg.text)
response = talk_robot(info=message)
return response
embed()