联众验证码 - 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'))
---------------------
作者:henye007
来源:CSDN
原文:https://blog.csdn.net/henye007/article/details/88954149
版权声明:本文为博主原创文章,转载请附上博文链接!