基于图灵机器人的微信自动回复(个人娱乐)

基于py3

相信自己,每天多学一点。


本文代码有参考网上,仅供娱乐自学,谢谢。

参考推荐文章:http://wxpy.readthedocs.io/zh/latest/

                        http://blog.csdn.net/jiangop/article/details/77992740

                        http://wxpy.readthedocs.io/zh/latest/chats.html



首先我们运用了wxpy这个模块。


登陆的动作。


这边需要写一个自定义识别好友发来微信的方法。


然后需要接入图灵的机器人。

图灵的机器人需要去官网注册一个,

网址:http://openapi.tuling123.com,

可以上传资料自己完善基本的信息。

下面的一个今日新闻的思想源于网友的代码,

很棒的想法。


 def talks_robot(info='你好啊'):
     api_url = 'http://openapi.tuling123.com/openapi/api'
     apikey = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
     data = {'key':apikey,'info':info}
     req = requests.post(api_url,data).text
     n = 0
     replys = ''
     print(info)
     if '今日新闻' in info:
         re_data = json.loads(req)['list']
         for x in re_data:
             n = n+1
             replys = (replys+str(n)+':'+x['article']+'\n'+x['detailurl']+'\n')
     else:
         replys = json.loads(req)['text']

     return replys


最后一步,保持整个微信的登陆跟运行状态,最后一栏会显示好友发来的信息。



猜你喜欢

转载自blog.csdn.net/nicky_1218/article/details/79614014