Python學習--打碼平臺
阿新 • • 發佈:2019-01-28
back appid 充值 ava .com width ret mar 等等
打碼平臺介紹
作用:可以通過第三方平臺進行智能識別或者人工識別圖片。
優點:1. 價格便宜; 2. 使用簡單; 3. 識別率高
平臺介紹:
- 雲打碼(推薦) [http://www.yundama.com/]
- 極驗驗證碼智能識別輔助 [http://jiyandoc.c2567.com/]
- 超級鷹
- 打碼兔
- 若快打碼
- 等等
流程圖:
雲打碼需要註冊開發者賬號和用戶賬號,註冊地址:[http://www.yundama.com/]
開發者賬號用於,下載DEMO,調試自己的軟件
用戶賬號用於登錄,充值,平臺是收費的(1元=1000分)
【開發者】
添加我的軟件,獲取通信秘鑰
查看驗證碼類型:
http://www.yundama.com/price.html
題分價格:
【用戶】
充值
12306的驗證碼Demo
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 = ‘username ‘ # 密碼 password = ‘password‘ # 軟件ID,開發者分成必要參數。登錄開發者後臺【我的軟件】獲得! appid = 6795 # 軟件密鑰,開發者分成必要參數。登錄開發者後臺【我的軟件】獲得! appkey = ‘62a672323232323218be141d9a77463c5‘ # 圖片文件,上傳12306的圖片 filename = ‘dignshuji.jpg‘ # 驗證碼類型,# 例:1004表示4位字母數字,不同類型收費不同。請準確填寫,否則影響識別率。 # 在此查詢所有類型 http://www.yundama.com/price.html # 12306的驗證碼類型是6701 codetype = 6701 # 超時時間,秒 timeout = 60 # 檢查 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)) ######################################################################
12306圖片
返回結果表示: 第2,7,8張圖是訂書機
Python學習--打碼平臺