Python implements WeChat robot

Recently, in the process of learning python, I accidentally discovered a python library: wxpy, which can realize a series of functions for WeChat to automatically receive, process and reply to messages. It felt very interesting, so I explored and learned on my own and successfully realized its function.

When we open WeChat, we will receive replies from some activists in seconds. Sometimes we feel that the other party’s answer is very reasonable, but sometimes we find that the other party’s answer is actually that the donkey’s lips are not right. After careful study, it turns out that the other party is a robot. .

First, you need to install the wxpy library, and then you need to go to Turing Robot’s official website to register and get a robot API to implement WeChat robots. http://www.turingapi.com/

After the registration is completed, put the obtained apikey into the code fixed interface to realize the WeChat robot.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Seven'

from wxpy import *

# 扫码登陆
bot = Bot()
# 初始化图灵机器人
tuling = Tuling(api_key='your apikey')


# 自动回复所有文字消息
@bot.register(msg_types=TEXT)
def auto_reply_all(msg):
    tuling.do_reply(msg)


# 开始运行
bot.join()

The effect is as follows:

 

Guess you like

Origin blog.csdn.net/gf19960103/article/details/91506975