联众打码

captcha.py

import requests
from base64 import b64encode


class CaptchaApi:

    def __init__(self, username, password):
        self.__username = username
        self.__password = password
        self.__software_id = 联众软件ID
        self.__software_secret = 联众软件秘钥
        self.__captcha_id = None
        self.__type = {
            '12306': '1303',
        }

    def decode(self, file_name, mark=None):
        url = 'https://v2-api.jsdama.com/upload'
        with open(file_name, 'rb') as f:
            captcha = b64encode(f.read()).decode()
        mark = mark or self.__type['12306']
        data = {
            'softwareId': self.__software_id,
            'softwareSecret': self.__software_secret,
            'username': self.__username,
            'password': self.__password,
            'captchaData': captcha,
            'captchaType': mark
            # 'captchaMinLength': 1,
            # 'captchaMaxLength': 8,
        }
        response = requests.post(url, json=data).json()
        if response['code'] == 0:
            code = response['data']['recognition']
            self.__captcha_id = response['data']['captchaId']
            return ','.join(code.split('|'))
        else:
            print(response['message'])

    def report_error(self):
        url = 'https://v2-api.jsdama.com/report-error'
        data = {
            'softwareId': self.__software_id,
            'softwareSecret': self.__software_secret,
            'username': self.__username,
            'password': self.__password,
            'captchaId': self.__captcha_id,
        }
        response = requests.post(url, json=data).json()
        if response['data']['result']:
            print('报错成功!')


jsdati = CaptchaApi('联众账号', '联众密码')

if __name__ == '__main__':
    import os

    ans = jsdati.decode(os.path.join(os.path.dirname(__file__), 'code.png'))
    print(ans)

你可能感兴趣的:(联众打码)