gpt4 book ai didi

使用python接入微信聊天机器人

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 28 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章使用python接入微信聊天机器人由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

本文实例为大家分享了python接入微信聊天机器人的具体代码,供大家参考,具体内容如下 。

1.安装库wxpy:

?
1
pip install - u wxpy

or 。

?
1
pip install - u wxpy - i https: / / pypi.doubanio.com / simple /

2.简单操作上手:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from wxpy import *
bot = bot(cache_path = true) #扫码登录验证
friends_stat = bot.friends().stats()
 
friend_loc = [] # 每一个元素是一个二元列表,分别存储地区和人数信息
for province, count in friends_stat[ "province" ].items():
   if province ! = "":
     friend_loc.append([province, count])
 
# 对好友人数倒序排序
friend_loc.sort(key = lambda x: x[ 1 ], reverse = true)
# 打印好友人数最多的10个地区:
for item in friend_loc[: 10 ]:
   print (item[ 0 ], item[ 1 ])
 
#打印好友男女比例:
for sex, count in friends_stat[ "sex" ].items():
   # 1代表male, 2代表female
   if sex = = 1 :
     print ( "male %d" % count)
   elif sex = = 2 :
     print ( "female %d" % count)

3.聊天机器人,一起来调戏好友吧 。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
from wxpy import *
bot = bot(cache_path = true)
my_friend = bot.friends().search( '好友昵称' )[ 0 ] #定位好友
my_friend.send( 'hello!' ) #发送“hello!”测试一下对接是否成功。
group = bot.groups().search( '群名' )[ 0 ] #定位群
 
#接入图灵api:需要去下述网址申请:
tuling = tuling(api_key = '在http://www.tuling123.com/申请' )
 
# 使用图灵机器人自动与指定好友聊天
@bot .register(my_friend)
def reply_my_friend(msg):
   tuling.do_reply(msg)

reference:

[1] wxpy: 用 python 玩微信 。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.

原文链接:https://blog.csdn.net/Maverick_7/article/details/79686700 。

最后此篇关于使用python接入微信聊天机器人的文章就讲到这里了,如果你想了解更多关于使用python接入微信聊天机器人的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com