2021-10-15

使用wxpy打造微信客服系统

(可以发送任何形式的消息,无障碍沟通)
功能描述
以1个客服微信操控10个微信客户端为例。将10个客户端微信分别安装到10部手机上,客服微信单独安装在一部手机上。当10个客户端微信的好友咨询时,此客户端微信会将接收到的消息(文本、图片、视频、语音等)消息原封不动的转发到客户微信上,客服微信也可以进行任何形式的消息回复给客户端微信,这户端微信再将客服微信发回来的消息原封不动的转发给客服端微信上的好友。这样便实现了一个客服统一管理10个客户端微信的消息的功能。

所需工具
1、wxpy模块
2、python
3、手机
4、电脑

源代码分享

from wxpy import *
import time
bot = Bot(cache_path=True,console_qr=2)
bot.enable_puid('wxpy_puid.pkl')
friends = bot.friends()
puid_dcit = {}
for friend in friends:
    puid_dcit[friend.puid] = friend
kefu = ensure_one(bot.friends().search('客服微信名称'))
#验证信息
def valid_msg(msg):
    if msg.type == 'Text':
        if '@' in msg.text.lower():
            return True
#         elif '入群' in msg.text.lower(): #现在邀您入群,安排设计师帮您设计。
#             return False
# # 定义邀请入群的方法
# def invite(user):
#     group =  ensure_one(bot.groups(contact_only=True).search('客户服务群'))
#     group.add_members(user, use_invitation=True)
#转发消息
friend = None
@bot.register(friends)
def forward_friends_message(msg):
    global friend
    if msg.sender == kefu:        
        if valid_msg(msg):            
            friend = puid_dcit[msg.text[1:]]
        # elif not valid_msg(msg):
        #     invite(friend)
        else:
            msg.forward(friend)
    else:
        msg.forward(kefu,prefix=f"{msg.sender.puid}")
embed()

使用规则
客户端微信好友发来消息,在客户端微信转发到客服微信时,会自动备注咨询客户的puid,当客服微信回复消息时,要先发送一条@+puid的信息到客户端微信,然后再发送正常的消息内容。

使用操作步骤
1、将这行代码中kefu = ensure_one(bot.friends().search(‘客服微信名称’))的客服微信名称修改成你要作为客服微信的名称。
2、将客户微信分别加10个客户端微信为好友
3、使用vscode运行以上代码,会跳出一个二维码,用客户端微信扫描二维码,登陆到微信网页版进行消息监控。
2、将上述代码文件再复制9份,按照步聚1登陆其它9个客户端微信。

希望这段代码能帮助到有共同需求的人

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值