Get the App
SLTechnology News&Howtos  ›  Servers  › 

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

Shulou Source: shulou.com Published: 2022-06-03 03:37:58 10月17日 Update

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!

Tags: Environment information text machine robot run content Turing individual code function function variable available in command icon desktop script path this is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi NVidia Microsoft Shulou Information Xiaomi