当前位置:   article > 正文

云打码实现验证码识别_云打码官网登录

云打码官网登录

云打码官网:http://www.yundama.com/

API接口:http://www.yundama.com/apidoc/YDM_SDK.html#DEMO

以下验证码识别使用的”pythonHTTP“方法:

1.注册开发者账号,进入开发者中心,点击”我的软件“→”添加新软件“,获取软件代码和通讯密钥;

2.调用示例:

  1. import http.client, mimetypes, urllib, json, time, requests
  2. ######################################################################
  3. class YDMHttp:
  4. apiurl = 'http://api.yundama.com/api.php'
  5. username = '' #用户名
  6. password = '' #用户密码
  7. appid = '' #填写开发者软件代码
  8. appkey = '' #填写开发者通讯密钥
  9. def __init__(self, username, password, appid, appkey):
  10. self.username = username
  11. self.password = password
  12. self.appid = str(appid)
  13. self.appkey = appkey
  14. def request(self, fields, files=[]):
  15. response = self.post_url(self.apiurl, fields, files)
  16. response = json.loads(response)
  17. return response
  18. def balance(self):
  19. data = {'method': 'balance', 'username': self.username, 'password': self.password, 'appid': self.appid, 'appkey': self.appkey}
  20. response = self.request(data)
  21. if (response):
  22. if (response['ret'] and response['ret'] < 0):
  23. return response['ret']
  24. else:
  25. return response['balance']
  26. else:
  27. return -9001
  28. def login(self):
  29. data = {'method': 'login', 'username': self.username, 'password': self.password, 'appid': self.appid, 'appkey': self.appkey}
  30. response = self.request(data)
  31. if (response):
  32. if (response['ret'] and response['ret'] < 0):
  33. return response['ret']
  34. else:
  35. return response['uid']
  36. else:
  37. return -9001
  38. def upload(self, filename, codetype, timeout):
  39. data = {'method': 'upload', 'username': self.username, 'password': self.password, 'appid': self.appid, 'appkey': self.appkey, 'codetype': str(codetype), 'timeout': str(timeout)}
  40. file = {'file': filename}
  41. response = self.request(data, file)
  42. if (response):
  43. if (response['ret'] and response['ret'] < 0):
  44. return response['ret']
  45. else:
  46. return response['cid']
  47. else:
  48. return -9001
  49. def result(self, cid):
  50. data = {'method': 'result', 'username': self.username, 'password': self.password, 'appid': self.appid, 'appkey': self.appkey, 'cid': str(cid)}
  51. response = self.request(data)
  52. return response and response['text'] or ''
  53. def decode(self, filename, codetype, timeout):
  54. cid = self.upload(filename, codetype, timeout)
  55. if (cid > 0):
  56. for i in range(0, timeout):
  57. result = self.result(cid)
  58. if (result != ''):
  59. return cid, result
  60. else:
  61. time.sleep(1)
  62. return -3003, ''
  63. else:
  64. return cid, ''
  65. def report(self, cid):
  66. data = {'method': 'report', 'username': self.username, 'password': self.password, 'appid': self.appid, 'appkey': self.appkey, 'cid': str(cid), 'flag': '0'}
  67. response = self.request(data)
  68. if (response):
  69. return response['ret']
  70. else:
  71. return -9001
  72. def post_url(self, url, fields, files=[]):
  73. for key in files:
  74. files[key] = open(files[key], 'rb');
  75. res = requests.post(url, files=files, data=fields)
  76. return res.text
  77. ######################################################################
  78. # 用户名
  79. username = 'username'
  80. # 密码
  81. password = 'password'
  82. # 软件ID,开发者分成必要参数。登录开发者后台【我的软件】获得!
  83. appid = 1
  84. # 软件密钥,开发者分成必要参数。登录开发者后台【我的软件】获得!
  85. appkey = '22cc5376925e9387a23cf797cb9ba745'
  86. # 图片文件
  87. filename = 'getimage.jpg'
  88. # 验证码类型,# 例:1004表示4位字母数字,不同类型收费不同。请准确填写,否则影响识别率。在此查询所有类型 http://www.yundama.com/price.html
  89. codetype = 1004
  90. # 超时时间,秒
  91. timeout = 60
  92. # 检查
  93. if (username == 'username'):
  94. print('请设置好相关参数再测试')
  95. else:
  96. # 初始化
  97. yundama = YDMHttp(username, password, appid, appkey)
  98. # 登陆云打码
  99. uid = yundama.login();
  100. print('uid: %s' % uid)
  101. # 查询余额
  102. balance = yundama.balance();
  103. print('balance: %s' % balance)
  104. # 开始识别,图片路径,验证码类型ID,超时时间(秒),识别结果
  105. cid, result = yundama.decode(filename, codetype, timeout);
  106. print('cid: %s, result: %s' % (cid, result))
  107. ######################################################################

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/287401
推荐阅读
相关标签
  

闽ICP备14008679号