Current location - Quotes Website - Signature design - How to use Python to implement the automatic check-in function of WeChat
How to use Python to implement the automatic check-in function of WeChat

Author: LittleCoder

Link: /question/51160419/answer/124460961

Source: Zhihu

The copyright belongs to the author. Please contact the author for permission to reprint.

Ordinary web page clicks:

1. It is recommended to analyze message interaction through a browser or Wireshark.

2. Then simulate through requests.

Since there is no specific URL, I cannot give the specific code.

Send specific questions to the official account:

1. It is recommended to use Python’s WeChat API (pip install itchat)

2. Since there is no Python version provided, I give a compatible solution here

#coding=utf8

import threading

import itchat

SIGN_IN_MP_DICT = {

u'School WeChat official account': u'School sign-in password',

u'Company WeChat official account': u'Company sign-in password', }

def get_day(timeGap):

return int(time.strftime('%y%m%d', time.localtime(time.time() + timeGap)))

NEXT_SIGN_DATE = get_day(60*60*24)

def sign_in_thread():

''' Sign-in thread

If the date that needs to be signed in has not yet arrived, continue Loop

If the date that needs to be signed in is reached, complete the sign-in of the two official accounts and update the date

'''

while 1:

if get_day < NEXT_SIGN_DATE:

time.sleep(30)

else:

for k, v in SIGN_IN_MP_DICT.items():< /p>

itchat.send(msg=v,

toUserName=itchat.search_mps(name=k)[0]['UserName'])

NEXT_SIGN_DATE = get_day (60*60*24)

itchat.auto_login(True)

# Test whether a specific official account exists

for mpName in SIGN_IN_MP_DICT.keys():

mpList = itchat.search_mps(name=mpName)

if len(mpList) != 1:

print(u'No public account detected" %s", please check the name')

break

else:

signInThread = threading.Thread(target=sign_in_thread)

signInThread.setDaemon(True)

signInThread.start()

itchat.run()