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

A detailed tutorial on the implementation of Wechat automatic reply Robot by Python

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

First, we need to install and configure the Python environment, and install the requests and itchat packages. I use the Windows7 environment!

Https://www.python.org/ python official website

download

Then open the installation directly.

Select the path option and check the box (directly add environment variables and path) directly to the next step until the installation is complete.

Run cmd

Then cmd command line input

Pip install itchat requests

Waiting for the installation to complete, now we have installed the environment.

Then the new text on the desktop ends with .py copying the following code into it and running it.

The value of KEY is obtained from the new robot on Turing's official website.

Here is the content of the script

# coding = utf8

Import requests

Import itchat

# registering at the Turing Robot website http://www.tuling123.com/ will generate an apikey, which can be viewed in the personal center

KEY = 'enter Turing Robot KEY' here

Def get_response (msg):

ApiUrl = 'http://www.tuling123.com/openapi/api'

Data = {

'key': KEY

Info': msg, # this is the message to be sent

Userid': 'wechat-rebot', # whatever you want to write here

}

Try:

Send a post request r = requests.post (apiUrl, data = data) .json () # to get the text message. If there is no 'Text' value, it will return Nonoe return r.get (' text') except: return

# get the registration text information @ itchat.msg_register (itchat.content.TEXT) br/ > @ itchat.msg_register (itchat.content.TEXT) by defining the tuling_reply (msg) function of the decorator

Set a default reply, and the reply message defaultReply ='I received:'+ msg ['Text'] reply = get_response (msg [' Text']) # an or b indicates that if a has content, return a, otherwise return breturn reply or defaultReply

# use hot boot, no need to scan code multiple times

Itchat.auto_login (hotReload=True)

Itchat.run ()

Then if the environment is normal, the text will become this icon!

After running, you will get a QR code Wechat scan and login, and you can start to reply automatically by chatting with yourself with other Wechat!

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

Servers

Wechat

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

12
Report