非官方接口登陆微信公众号平台

通过接口登陆微信公众号平台并保存登陆状态
通过测试,微信公众号登陆状态,过期时长为3天
注意这里通过账号密码登陆,仍然要求扫码功能,这个安全限制绕不过去
本篇文章基于python语言开发,其他的语言一样的方式,直接存储cookie即可,不需要拘泥于语言

直接上代码

"""
微信公众号模拟登录
"""
import json
import os
import pickle
import time
import random
import hashlib
import requests

from wechat_automation.config import SERVER_DOMAIN
from .PushplusNotifier import PushplusNotifier
from ..utils import saveImage, showImage, removeImage
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)


'''PC端登录微信公众号'''
class mpweixinPC:
    is_callable = True

    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            setattr(self, key, value)
        self.info = 'login in mpweixin in pc mode'
        self.cur_path = os.getcwd()
        self.session = requests.Session()
        self.__initialize()
        self.storage_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../shared/storage'))

    """获取cookie文件的存储路径"""
    def get_cookie_path(self, username):
        return os.path.join(self.storage_dir, f'{
     username}.pkl')

    '''登录函数'''
    def login(self, username, password, crack_captcha_func=None, **kwargs):
        cookie_path = self.get_cookie_path(username)
        user_info_path = os.path.join(self.storage_dir, f'{
     username}.txt')

        if os.path.exists(cookie_path):
            with open(cookie_path, 'rb') as f:
                self.session.cookies

你可能感兴趣的:(Python,微信非官方接口,微信公众平台)