SoFunction
Updated on 2024-12-10

Python use itcaht library to realize wechat automatic send and receive messages function

itchat library

  • Simulate WeChat Web Login
  • Receive/send wechat messages via python code
  • Realize WeChat chatbot: call the chatbot api, pass the received WeChat messages to the api, then pass the messages returned by the api to WeChat

Demonstrate how to send WeChat messages using itchat

# !pip install itchat
import itchat

Generate a QR code image in the current folder, WeChat scanning code can log in the web version of WeChat

itchat.auto_login()

Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
Loading the contact, this may take a little while.
Login successfully as young white

Find the recipient of a message by WeChat name

users = itchat.search_friends(name="Whitey.") # Here's a message for yourself #
user_name = users[0]["UserName"]

The object is represented as a string like this

user_name

'@40f90812b2233588e8ebda1e8d8f01d48d32a384e31f0a96yaa4859a41123456'

toUserNameSpecify the object to receive the message; send "hello world" every 10s, 3 times.

import time

for i in range(3):
 ("hello, world", toUserName=user_name)
 (10)

summarize

to this article on the Python use itcaht library to achieve WeChat automatically send and receive messages to this article, more related python itcaht library WeChat automatically send and receive messages content please search my previous posts or continue to browse the following articles hope that you will support me in the future more!