验证码login

#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2025年6月05日

@author: wangcuimei
'''
import requests
import ddddocr
import re
from requests_toolbelt.multipart.encoder import MultipartEncoder
import json
import pdb

def test_login():
    checkCode, fat_security_checkcode = test_getcode()
    url = 'https://faterp.szlcsc.com/auth/user/login?source=web'
    data = {
        "username": "software",
        "password": "98832d0568e359bdb4498d94e03c8eff4bfdda37ce338a08",
        "isRememberPwd": True,
        "macAddress": "",
        "checkCode": checkCode
    }
    headers = {
        'content-type': "application/x-www-form-urlencoded",
        'Cookie':fat_security_checkcode
    }
    response = requests.post(url, data=data, headers=headers)

    result = json.loads(response.text)
    print(result)

    fat_auth_token = "fat.auth.token="+result['msg']
    return fat_security_checkcode,fat_auth_token




def test_getcode():
    url = 'https://faterp.szlcsc.com/auth/checkcode'
    data = {}
    headers = {
        'content-type': "application/json;charset=utf-8"
    }
    response = requests.get(url, params=data, headers=headers)

    # 打印响应状态码和图片二进制内容
    print('请求状态码:', response.status_code)
    print('请求文件内容,二进制',response.content)

    #处理验证码图片,返回一个字符串
    ocr = ddddocr.DdddOcr()
    checkCode = ocr.classification(response.content)
    print(checkCode)


    #pdb.set_trace()
    setCookie = response.headers['Set-Cookie']

    fat_security_checkcode = (setCookie.split(", ")[1]).split(";")[0]
    return fat_security_checkcode



def lms_detection_delegation_page():
    fat_auth_token = test_login()

    url = 'https://faterp.szlcsc.com/lms/detection/delegation/page'
    data = {
        "currentPage": 1,
        "pageSize": 30
    }
    headers = {
        'content-type': "application/json;charset=utf-8",
        "Cookie": fat_auth_token
    }

    response = requests.get(url, params=data, headers=headers)
    result = json.loads(response.text)
    print(result)




if __name__=='__main__':
    lms_detection_delegation_page()

posted @ 2025-06-05 17:23  呆呆酱  阅读(40)  评论(0)    收藏  举报