本代码来自网络搜索,在此只做参考并无他用,方便自己作为笔记收藏
需要在(1)Python3的平台下安装wxpy模块
(2)在图灵机器人网站注册账号,申请微信机器人。建立一个机器人得到其api_key=“xxxxxxxxxxxxx”
#!/usr/bin/env python3
#__*__coding=utf-8__*__
import requests
from wxpy import *
import json
def talks_robot(info = '你叫什么名字'):
api_url = 'http://www.tuling123.com/openapi/api'
#在这里插入你的API_KEY即可
api_key = 'xxxxxxxxxxxxx'
data = {'key': api_key,
'info': info}
req = requests.post(api_url, data=data).text
replys = json.loads(req)['text']
return replys
robot = Robot()
@robot.register()
def reply_my_friend(msg):
message = '{}'.format(msg.text)
replys = talks_robot(info=message)
return replys
robot.start()
值得注意的是前一天还能好好运行,第二天再次运行时显示
这是what ~~???说“Root”没有定义,我也没懂,明明wxpy模块里面有这个的,而且也是导入了的,想了好些调试的办法也没成功,难道我前一天的正常运行是无意的???