How to implement a Wechat chat Robot in python
This article shows you how to achieve a Wechat chat robot in python, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
To be a Wechat chat robot, the steps are as follows:
1. Get the right to use Wechat, that is, python scripts can control Wechat to send and receive messages.
2. After receiving the chat message, the python script will deal with the message and return the response information of the robot.
In one, two and two steps, various components in the wxpy library are used to send and receive messages and monitor Wechat activities. In addition, the robot also uses the api of the Turing robot.
Let's go to Turing Robot to register an account.
Create a Turing robot
To choose Custom (do not choose Wechat or qq or other)
Remember the api address and apikey, which will be used later
Import requests
From wxpy import *
Import json
Import json
# Turing robot
Def talks_robot (info = 'what's your name'): 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 replys
# Wechat automatic reply
Robot = Robot ()
# reply to messages from other friends, group chats and official accounts
@ robot.register ()
Def reply_my_friend (msg): message ='{} '.format (msg.text) replys = talks_robot (info=message)
Return replys
# start monitoring and automatic processing of messages
Robot.start ()
Running effect diagram
The above is how to implement a Wechat chat robot in python. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.