py验证码-联众验证码接入

本文介绍了一个使用Python3对接联众打码平台的验证码解析方法。通过上传验证码图片到指定API接口,实现对复杂字体点击验证码的自动识别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

联众验证码 - python3接入

在处理字体点击的验证码时,采用联众的打码平台,用Py3的接入

import requests
from base64 import b64encode
import os


class CaptchaApi:

    def __init__(self, username, password):
        self.__username = username
        self.__password = password
        self.__software_id = ' 软件 ID'
        self.__software_secret = '软件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()# {'data': {'captchaId': '20190401:000000000027213672156', 'recognition': '266,94|153,219'}, 'code': 0, 'message': ''}
        if response['code'] == 0:
            groups = response.get('data').get('recognition').split('|')
            code = [[int(number) for number in group.split(',')] for group in groups]
            self.__captcha_id = response['data']['captchaId']
            print(code)# 266,94|153,219
            return code # [[118, 277], [253, 211], [198, 94]]
            # 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__':
    ans = jsdati.decode(os.path.join(os.path.dirname(__file__), 'xq.png'))
    print(os.path.join(os.path.dirname(__file__), 'xq.png'))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值