博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
云打码识别验证码
阅读量:4952 次
发布时间:2019-06-12

本文共 4307 字,大约阅读时间需要 14 分钟。

import http.client, mimetypes, urllib, json, time, requests ###################################################################### class YDMHttp:     apiurl = 'http://api.yundama.com/api.php'     username = ''     password = ''     appid = ''     appkey = ''     def __init__(self, username, password, appid, appkey):         self.username = username         self.password = password         self.appid = str(appid)         self.appkey = appkey     def request(self, fields, files=[]):         response = self.post_url(self.apiurl, fields, files)         response = json.loads(response)         return response     def balance(self):         data = {'method': 'balance', 'username': self.username, 'password': self.password, 'appid': self.appid,                 'appkey': self.appkey}         response = self.request(data)         if (response):             if (response['ret'] and response['ret'] < 0):                 return response['ret']             else:                 return response['balance']         else:             return -9001     def login(self):         data = {'method': 'login', 'username': self.username, 'password': self.password, 'appid': self.appid,                 'appkey': self.appkey}         response = self.request(data)         if (response):             if (response['ret'] and response['ret'] < 0):                 return response['ret']             else:                 return response['uid']         else:             return -9001     def upload(self, filename, codetype, timeout):         data = {'method': 'upload', 'username': self.username, 'password': self.password, 'appid': self.appid,                 'appkey': self.appkey, 'codetype': str(codetype), 'timeout': str(timeout)}         file = {'file': filename}         response = self.request(data, file)         if (response):             if (response['ret'] and response['ret'] < 0):                 return response['ret']             else:                 return response['cid']         else:             return -9001     def result(self, cid):         data = {'method': 'result', 'username': self.username, 'password': self.password, 'appid': self.appid,                 'appkey': self.appkey, 'cid': str(cid)}         response = self.request(data)         return response and response['text'] or ''     def decode(self, filename, codetype, timeout):         cid = self.upload(filename, codetype, timeout)         if (cid > 0):             for i in range(0, timeout):                 result = self.result(cid)                 if (result != ''):                     return cid, result                 else:                     time.sleep(1)             return -3003, ''         else:             return cid, ''     def report(self, cid):         data = {'method': 'report', 'username': self.username, 'password': self.password, 'appid': self.appid,                 'appkey': self.appkey, 'cid': str(cid), 'flag': '0'}         response = self.request(data)         if (response):             return response['ret']         else:             return -9001     def post_url(self, url, fields, files=[]):         for key in files:             files[key] = open(files[key], 'rb')         res = requests.post(url, files=files, data=fields)         return res.text ###################################################################### # 用户名 username = 'nickshen' # 密码 password = '********' # 软件ID,开发者分成必要参数。登录开发者后台【我的软件】获得! appid = 8063  # 对应的在平台中创建的软件id # 软件密钥,开发者分成必要参数。登录开发者后台【我的软件】获得! appkey = 'ae377936180901fd4bd7d1a62aa8360c' # 超时时间,秒 timeout = 20 # 封装调用接口--image_decode() def image_decode(filename, codetype=3000):     # 检查     if (username == 'username'):         print('请设置好相关参数再测试')     else:         # 初始化         yundama = YDMHttp(username, password, appid, appkey)         # 登陆云打码         uid = yundama.login()         print('uid: %s' % uid)         # 查询余额         balance = yundama.balance()         print('balance: %s' % balance)         # 开始识别,图片路径,验证码类型ID,超时时间(秒),识别结果         cid, result = yundama.decode(filename, codetype, timeout)         print('cid: %s, result: %s' % (cid, result))         return result ###################################################################### if __name__ == '__main__':     image_decode('../image_file/a.png')

转载于:https://www.cnblogs.com/nickshen/p/11064149.html

你可能感兴趣的文章
Android NDK builder for Eclipse in Windows
查看>>
wildfly 在 jee war 外部写配置文件
查看>>
白牌交换机现状分析zz
查看>>
数据表示和基本运算第一弹
查看>>
用 LaTeX 排版编程技术书籍的一些个人经验
查看>>
Unity3D笔记十九 持久化数据
查看>>
TensorFlow笔记-01-开篇概述
查看>>
phpunit——执行测试文件和测试文件中的某一个函数
查看>>
jquery.cookie.js 的配置
查看>>
序列化,json pickle,shelve
查看>>
【C#】C#格式化文件大小
查看>>
eclipse中的快捷键
查看>>
接口与继承:方法覆盖(super)
查看>>
php设计模式-原型模式
查看>>
重写Repeater,使其支持空模版(列表为空时显示)
查看>>
打造自己的html5视频播放器
查看>>
spark-submit 提交任务
查看>>
POI读取Excel(xls、xlsx均可以)——(四)
查看>>
struts集合类型封装
查看>>
Cassandra issue - "The clustering keys ordering is wrong for @EmbeddedId"
查看>>