美文网首页
云打码通过直接传入byte数据识别验证码

云打码通过直接传入byte数据识别验证码

作者: Odven | 来源:发表于2020-03-26 09:18 被阅读0次

# -*- coding: utf-8  -*-

import platform

from ctypes  import *

plf = platform.architecture()[0]

# print(plf)

if plf =="32bit":

    YDMApi = windll.LoadLibrary('yundamaAPI')

else:

    YDMApi = windll.LoadLibrary('yundamaAPI-x64')

appId = 123456  # 软件ID,开发者分成必要参数。登录开发者后台【我的软件】获得!

appKey =b'65146549846516489'    # 软件密钥,开发者分成必要参数。登录开发者后台【我的软件】获得!

username = b'root'

password = b'123456'

if username == b'test':

    exit('\r\n>>>请先设置用户名密码')

########################## 普通识别函数 YDM_DecodeByPath #########################

# 第一步:初始化云打码,只需调用一次即可

YDMApi.YDM_SetAppInfo(appId, appKey)

# 第二步:登陆云打码账号,只需调用一次即可

uid = YDMApi.YDM_Login(username, password)

class YunDaMaApi(object):

    def get_code(self, im_bytes, im_len, codetype=1004):

        """

        im_bytes: 为图片的byte类型数据

        im_len: 为图片byte数据的长度

        codetype: 为识别的验证码的类型  默认为1004表示识别4个英文字母  1005表示识别5个英文字母  可查看云打码的文档

        """

        if uid >0:

            balance = YDMApi.YDM_GetBalance(username, password)

            print('登陆成功,用户名:%s,剩余题分:%d' % (username, balance))

            # 分配30个字节存放识别结果

            result = c_char_p(b"                              ")

            # 普通识别函数,需先调用 YDM_SetAppInfo 和 YDM_Login 初始化

            captchaId = YDMApi.YDM_DecodeByBytes(im_bytes, im_len,  codetype, result)

            print("普通识别:验证码ID:%d,识别结果:%s" % (captchaId, result.value))

            return {"code": result.value.decode()}

        else:

            print('登陆失败,错误代码:%d' % uid)

            return {"code":0}

################################################################################

if __name__ =='__main__':

    import requests

    from fake_useragentimport UserAgent

    from PILimport Image

    from ioimport BytesIO

    ua = UserAgent()

    headers = {

        "User-Agent": ua.chrome,

    }

    url ="https://ding.svnup.cn/api/v1.0/image_codes/123456789"

    # 发送请求得到验证码图片

    response = requests.get(url, headers=headers)

    # 利用PIL显示验证码图片

    im = Image.open(BytesIO(response.content))

    print(im.size)

    im.show()

    # 利用yundama识别验证码

    yundama = YunDaMaApi()

    code = yundama.get_code(response.content, len(response.content))

    print(code)

相关文章

网友评论

      本文标题:云打码通过直接传入byte数据识别验证码

      本文链接:https://www.haomeiwen.com/subject/fkrquhtx.html