Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement a Wechat chat Robot in python

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report