黑基Web安全攻防班
安基网 首页 IT技术 编程开发 查看内容

使用python制作微信机器人

2018-2-22 00:18| 投稿: xiaotiger |来自: 互联网


免责声明:本站系公益性非盈利IT技术普及网,本文由投稿者转载自互联网的公开文章,文末均已注明出处,其内容和图片版权归原网站或作者所有,文中所述不代表本站观点,若有无意侵权或转载不当之处请从网站右下角联系我们处理,谢谢合作!

摘要: 上一篇我们用了wxpy 这个第三方库分析了自己的微信,这次我们使用wxpy制作一个会聊天的微信机器人 ,我们快来尝试一下把。 好多朋友问我使用这个会不会封号,我为大家解惑一下 wxpy是封装了,微信网页版的接口 所以不会 ...

上一篇我们用了wxpy 这个第三方库分析了自己的微信,这次我们使用wxpy制作一个会聊天的微信机器人 ,我们快来尝试一下把。

好多朋友问我使用这个会不会封号,我为大家解惑一下 wxpy是封装了,微信网页版的接口 所以不会封号,正常使用,我们先来讲一下机器人实现的方法。

首先wxpy是封装微信的接口,所以他并不提供聊天的功能。我们可以用第三方接口来实现自动聊天,也可以自己设置自动回复,设置关键词,设置自动拉群,还有一种比较高级的用法,就是自己训练自己的聊天机器人,那就需要会机器学习算法了,只是这种难度偏高,我们今天来讲一下使用图灵机器人的接口制作一个聊天机器人吧。

我们先来图灵注册一个账号。

注册完成以后我们找到我的机器人,复制自己的api到代码的APIKey。

代码如下

'''

import requestsfrom wxpy import *import jsondef talks_robot(info = '你叫什么名字'): api_url = 'http://www.tuling123.com/openapi/api' apikey = 'APIKey' data = {'key': apikey, 'info': info} req = requests.post(api_url, data=data).text replys = json.loads(req)['text'] return replysrobot = Robot()@robot.register()def reply_my_friend(msg): message = '{}'.format(msg.text) replys = talks_robot(info=message) return replysrobot.start()

'''

请欣赏两个机器人尬聊。

, groupId: 6524894582096790030, itemId: 6524894582096790030, type: 2, subInfo: { isOriginal: false, source: 我们的征途是日月星辰, time: 2018-02-21 14:43:25 }, tagInfo: { tags: [{"name":"编程语言"},{"name":"Python"},{"name":"微信"},{"name":"机器学习"},{"name":"移动互联网"}], groupId: 6524894582096790030, itemId: 6524894582096790030, repin: 0, }, has_extern_link: 0 }, commentInfo: { groupId: 6524894582096790030, itemId: 6524894582096790030, comments_count: 6, ban_comment: 0 }, mediaInfo: { uid: 92363032393, name: 我们的征途是日月星辰, avatar: //p3.pstatp.com/large/61640003478322532f58, openUrl: /c/user/92363032393/, follow: false }, pgcInfo: {"media_info":{"open_url":"/c/user/92363032393/","avatar_url":"https://p3.pstatp.com/large/61640003478322532f58","media_id":1591914151323661,"name":"我们的征途是日月星辰","user_verified":false},"articles":[{"item_id":"6524894582096790030","url":"/item/6524894582096790030","title":"使用python制作微信机器人"},{"item_id":"6524656152255398414","url":"/item/6524656152255398414","title":"商业修图之彩妆"},{"item_id":"6524655886063895044","url":"/item/6524655886063895044","title":"ps之炫酷合成"},{"item_id":"6524584305648206344","url":"/item/6524584305648206344","title":"婚纱修图之颠覆"}]}, feedInfo: { url: /api/pc/feed/, category: __all__, initList: [{"comments_count":1,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"C语言中字符串常量的好处在哪里?","single_mode":true,"gallary_image_count":3,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524839085490569479/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/5fed000b12d49cd39014","group_id":"6524839085490569479"},{"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"用c++编写的exe文件如何反编译成c?","single_mode":false,"gallary_image_count":0,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524837008920019208/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"comments_count":0,"group_id":"6524837008920019208"},{"comments_count":6,"media_avatar_url":"//p1.pstatp.com/large/1a6a0009fd9833c7dd77","is_feed_ad":false,"is_diversion_page":false,"title":"什么是Cython?让Python有C语言的速度","single_mode":true,"gallary_image_count":2,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524649296455795208/","source":"云技术","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p1.pstatp.com/list/190x124/66a20005446fadea853c","group_id":"6524649296455795208","is_related":true,"media_url":"/c/user/5750790801/"},{"comments_count":1,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"为什么pc版wifi万能钥匙破解不了wifi密码而手机版都可以破解?","single_mode":true,"gallary_image_count":1,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524820103102464269/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/5fed000b0ad6cda4763d","group_id":"6524820103102464269"},{"comments_count":32,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"为什么微软、苹果甚至linux都在逐渐剔除java编程呢?","single_mode":true,"gallary_image_count":4,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6523341394172444931/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/666d0001d1ba3c39db07","group_id":"6523341394172444931"},{"comments_count":4,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"既然Python解释器是单线程的,还有进行多线程编程的必要吗?","single_mode":true,"gallary_image_count":3,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524124693740388621/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p1.pstatp.com/list/190x124/666d0002a3c87d5e0b81","group_id":"6524124693740388621"},{"comments_count":25,"media_avatar_url":"//p9.pstatp.com/large/d2a0017cc843933b79d","is_feed_ad":false,"is_diversion_page":false,"title":"如何正确地写出单例模式","single_mode":true,"gallary_image_count":7,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6521176834061632007/","source":"采蘑菇的小明","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/616b0001654cd4ee044e","group_id":"6521176834061632007","is_related":true,"media_url":"/c/user/51178602223/"},{"comments_count":9,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"jdk8、jdk8u、jdk9、jdk10的侧重和区别是什么?","single_mode":true,"gallary_image_count":3,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524258819055288579/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p1.pstatp.com/list/190x124/666d0002d4d0133d17d5","group_id":"6524258819055288579"},{"comments_count":6,"media_avatar_url":"//p3.pstatp.com/large/5935000137bed70a8c60","is_feed_ad":false,"is_diversion_page":false,"title":"你知道什么是DTO吗","single_mode":true,"gallary_image_count":7,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6523856963548217864/","source":"石头大V","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p1.pstatp.com/list/190x124/61750002a3246cddbea6","group_id":"6523856963548217864","is_related":true,"media_url":"/c/user/59909877329/"},{"comments_count":10,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"JAVA的内存是如何划分的?","single_mode":true,"gallary_image_count":2,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6523857040622747918/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/666d0002615790a52a0a","group_id":"6523857040622747918"},{"comments_count":2,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"php执行shell时,如何异步调用使得不会超时?","single_mode":true,"gallary_image_count":5,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524477546556293379/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p1.pstatp.com/list/190x124/666f0002fad1a2399ed7","group_id":"6524477546556293379"},{"comments_count":0,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"如何学好java?","single_mode":true,"gallary_image_count":2,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524949463969038595/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/5fed000b3e899981c0cc","group_id":"6524949463969038595"},{"comments_count":2,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"为什么现在这么多人开始学习Python?","single_mode":true,"gallary_image_count":3,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524520584250917134/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p1.pstatp.com/list/190x124/5fee000ab969de3181b1","group_id":"6524520584250917134"},{"comments_count":21,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"为什么国人不用易语言编程?","single_mode":true,"gallary_image_count":0,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6523162533992333575/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/5fed00094dd09052666e","group_id":"6523162533992333575"},{"comments_count":3,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"自学编程多久可以找工作?","single_mode":true,"gallary_image_count":2,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524832294266470670/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/666b0003638fb49e111d","group_id":"6524832294266470670"},{"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"如何销毁从JavaScript里new出来的对象?","single_mode":false,"gallary_image_count":0,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524909905726406919/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"comments_count":0,"group_id":"6524909905726406919"},{"comments_count":10,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"交换机的端口设置为VLAN Trunk模式时,在转发数据包时插入了什么信息?","single_mode":true,"gallary_image_count":6,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524205273484099853/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p9.pstatp.com/list/190x124/666f0002bb70ea3645d0","group_id":"6524205273484099853"},{"comments_count":11,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"Python如何实现图形化界面制作为桌面软件?","single_mode":true,"gallary_image_count":7,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6524515172264968455/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/666d00030f1c71d8f0fa","group_id":"6524515172264968455"},{"comments_count":18,"media_avatar_url":"//p6.pstatp.com/large/66a60002be3795604d12","is_feed_ad":false,"is_diversion_page":false,"title":"分享股票主图显示筹码的源码,比较简单明了,好不好自己看看","single_mode":true,"gallary_image_count":4,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6523683686708150791/","source":"爆笑街拍","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/6173000554f0904f04e8","group_id":"6523683686708150791","is_related":true,"media_url":"/c/user/87993298432/"},{"comments_count":9,"media_avatar_url":"//p9.pstatp.com/large/2c5e0001864c88f09e40","is_feed_ad":false,"is_diversion_page":false,"title":"来试试这个真正的 JavaScript 调试器吧!","single_mode":true,"gallary_image_count":5,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6523469398185869828/","source":"前端圈","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p9.pstatp.com/list/190x124/66a40000e860a10847aa","group_id":"6523469398185869828","is_related":true,"media_url":"/c/user/51181806849/"}] }, shareInfo: { shareUrl: https://m.toutiao.com/item/6524894582096790030/, abstract: 上一篇我们用了wxpy这个第三方库分析了自己的微信,这次我们使用wxpy制作一个会聊天的微信机器人,我们快来尝试一下把。

小编推荐:欲学习电脑技术、系统维护、网络管理、编程开发和安全攻防等高端IT技术,请 点击这里 注册账号,公开课频道价值万元IT培训教程免费学,让您少走弯路、事半功倍,好工作升职加薪!



免责声明:本站系公益性非盈利IT技术普及网,本文由投稿者转载自互联网的公开文章,文末均已注明出处,其内容和图片版权归原网站或作者所有,文中所述不代表本站观点,若有无意侵权或转载不当之处请从网站右下角联系我们处理,谢谢合作!


鲜花

握手

雷人

路过

鸡蛋

相关阅读

发表评论

最新评论

最新

返回顶部