联众打码平台接口调用(初版)

联众打码平台接口调用(初版)

由于工作需要在使用某网站是需要验证码登录,所以选择了打码平台(当然如果有条件,可以使用机器学习),在这里我选择的是联众打码,在联众官网上其实有接口文档(PDF),所以自己写一个初版供自己使用

文件位置

  • 文件名:lianzhong_code.py
  • 配置文件:LZsetting.json
  • 图片:目前版本只支持 base64加密图片,从网站返回链接截取获得,没试过直接上传图片

接口说明

"""
LZsetting.json

    这里是个人软件配置信息
    {
        "msg": "软件配置信息和用户信息",
        "ID": "用户软件ID",
        "Secret": "用户软件Secret",
        "UserName": "用户账号",
        "PassWord": "用户密码",
        "OkoooUser": "Okooo账号",
        "OkoooPassWord": "Okooo密码"

    }


lianzhong_code.py

    verify_code:识别验证码借口
        参数:
            captchaData:验证码参数 base64图片,直接从网站返回链接提取出
                目前只支持 /9j/4AAQSkZJRgABAQAAAQABAAD//gA7......YUUUUAFFFFAH//Z
            captchaType: 验证码类型
    
        {
            "code":0,
            "data":"58F4K",
            "id":"20190214:000000000025750641035",
            "msg":"",
            "text":"当code不为0时,使用id返回调用error_code申请错误!"
        }

    error_code: 验证码识别错误, 申请返回点数
        参数:
            captchaId:识别验证码,网站返回ID
    
    check_lianzhong:检查当前用户的剩余点数以及可用点数
        {
            "code":0,
            "user_points":998,
            "available_points":998,
            "lock_points":0,
            "msg":"user_points:用户总点数, available_points:可用点数, lock_points:锁定点数"
        }

"""

文件源码

接口源码:lianzhong_code.py

# coding: utf-8
"""
LZsetting.json

    这里是个人软件配置信息
    {
        "msg": "软件配置信息和用户信息",
        "ID": "用户软件ID",
        "Secret": "用户软件Secret",
        "UserName": "用户账号",
        "PassWord": "用户密码"
    }


使用说明:

verify_code:识别验证码借口
    参数:
        captchaData:验证码参数
            目前只支持 /9j/4AAQSkZJRgABAQAAAQABAAD//gA7......YUUUUAFFFFAH//Z
        captchaType: 验证码类型

    {
        "code":0,
        "data":"58F4K",
        "id":"20190214:000000000025750641035",
        "msg":"",
        "text":"当code不为0时,使用id返回调用error_code申请错误!"
    }

error_code: 验证码识别错误, 申请返回点数
    参数:
        captchaId:识别验证码,网站返回ID

check_lianzhong:检查当前用户的剩余点数以及可用点数
    {
        "code":0,
        "user_points":998,
        "available_points":998,
        "lock_points":0,
        "msg":"user_points:用户总点数, available_points:可用点数, lock_points:锁定点数"
    }

"""


import json
import requests
from requests.exceptions import Timeout
from useragent import randomUA, UA_TYPE_DESKTOP


class VerifyCode:

    def __init__(self):
        self.session = requests.session()
        self.session.headers['User-Agent'] = randomUA(UA_TYPE_DESKTOP)
        self.session.verify = False
        self.session.headers.update({
            'Host': 'v2-api.jsdama.com',
            'Connection': 'keep-alive',
            'Accept': 'application/json, text/javascript, */*; q=0.01',
            'Content-Type': 'text/json'
        })

        # 读取配置信息
        with open('LZsetting.json', 'r', encoding='utf-8') as f:
            s = f.read()
        setting = json.loads(s)

        self.id = setting['ID']
        self.secret = setting['Secret']
        self.user = setting['UserName']
        self.pwd = setting['PassWord']

    def verify_code(self, captchaData, captchaType):
        """
        验证验证码信息
        :return:
        """
        url = 'https://v2-api.jsdama.com/upload'
        data = {
            'softwareId': self.id,
            'softwareSecret': self.secret,
            'username': self.user,
            'password': self.pwd,
            'captchaData': captchaData,
            'captchaType': captchaType,
            'captchaMinLength': 0,
            'captchaMaxLength': 0,
            'workerTiosId': 0,
        }
        try:
            res = self.session.post(url=url, data=json.dumps(data), timeout=5)
            res_data = json.loads(res.text)
            print(res_data)
            code = res_data['code']
            data = res_data['data']['recognition']
            id = res_data['data']['captchaId']
            msg = res_data['message']
        except Timeout:
            code = 400
            data = ''
            id = id
            msg = '连接超时,检查网络重新请求,无需申请错误'

        text = '当code不为0时,使用id返回调用error_code申请错误!'
        return json.dumps({
            'code': code,
            'data': data,
            'id': id,
            'msg': msg,
            'text': text
        })

    def error_code(self, captchaId):
        """
        申请错误,返回点数,减少支出
        :param id:
        :return:
        """
        url = 'https://v2-api.jsdama.com/report-error'
        data = {
            'softwareId': self.id,
            'softwareSecret': self.secret,
            'username': self.user,
            'password': self.pwd,
            'captchaId': captchaId
        }
        try:
            res = self.session.post(url=url, data=json.dumps(data), timeout=5)
            result = res.text
        except Timeout:
            result = json.dumps({'code': 400, 'msg': '连接超时'})
        return result

    def check_lianzhong(self):
        """
        检查当前账户剩余点数
        :return:
        """
        url = 'https://v2-api.jsdama.com/check-points'
        data = {
            'softwareId': self.id,
            'softwareSecret': self.secret,
            'username': self.user,
            'password': self.pwd,
        }
        try:
            res = self.session.post(url=url, data=json.dumps(data), timeout=5)
            print(res.text)
            response = json.loads(res.text)
            code = response['code']
            msg = response['message']
            if not code == 0:
                result = {'code': code, 'msg': msg}
            else:
                available_points = response['data']['availablePoints']
                user_points = response['data']['userPoints']
                lock_points = response['data']['lockPoints']
                result = {
                    'code': code,
                    'user_points': user_points,
                    'available_points': available_points,
                    'lock_points': lock_points,
                    'msg': 'user_points:用户总点数, available_points:可用点数, lock_points:锁定点数'
                }
        except Timeout:
            result = {'code': 400, 'msg': '请求连接超时'}

        return json.dumps(result)

    def download_img(self):
        pass


if __name__ == '__main__':
    v = VerifyCode()
    # captchaData = '/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAKACWAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldY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Vpr3pUkt9evozGMWnyz0Oq8HeBdH8C2UkGlWxSSch7m6lbfNcv3eRj1JJJ7DJOAK36KK8xtyd2dCVtEFFFFSMKKKKACiiigAooooAKKKKACiiigDjviN8MbL4l2MdpqGoX9tbJg+RbShY2YHIZlI5IrW8IeH7nwxpMenz6pNqsUIVIJLhFEioBgBiuA31wKKKvnk48t9CeVXubdFFFQUZ99o0dzP8Aa4H+yX4AAuEH3wOiyDjeuex9TgjOazFubTSroTatp1vZ3K5xqUUOYmz334zGT6N3IAZjRRSemqOygvbTVKe34o6OiiimcYUUUUAFFFFAH//Z'
    # captchaType = '1038'
    # print(v.verify_code(captchaData=captchaData, captchaType=captchaType))
    # id = '20190214:000000000025751528630'
    # print(v.error_code(captchaId=id))
    print(v.check_lianzhong())

配置文件:LZsetting.json
需要先去联众官网配置软件

{
"msg": "软件配置信息和用户信息",
"ID": "软件ID",
"Secret": "软件配置后分配的Secret",
"UserName": "官网注册用户名",
"PassWord": "用户密码",
"O...User": "登录网站用户名(省略名称)",
"O...PassWord": "登录网站密码"
}

你可能感兴趣的:(打码使用,网站登录验证码处理——打码平台)