forked from chyroc/WechatSogou
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rk.py
61 lines (49 loc) · 1.75 KB
/
rk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
import os
from hashlib import md5
import requests
class RClient(object):
def __init__(self, username, password, soft_id, soft_key):
self.base_params = {
'username': username,
'password': md5(password.encode('utf-8')).hexdigest(),
'softid': soft_id,
'softkey': soft_key,
}
self.headers = {
'Connection': 'Keep-Alive',
'Expect': '100-continue',
'User-Agent': 'ben',
}
def rk_create(self, im, im_type, timeout=60):
params = {
'typeid': im_type,
'timeout': timeout,
}
params.update(self.base_params)
files = {'image': ('a.jpg', im)}
r = requests.post('http://api.ruokuai.com/create.json', data=params, files=files, headers=self.headers)
return r.json()
def rk_report_error(self, im_id):
params = {
'id': im_id,
}
params.update(self.base_params)
r = requests.post('http://api.ruokuai.com/reporterror.json', data=params, headers=self.headers)
return r.json()
def __identify_image_callback(img, code):
try:
username = os.environ['rk_username']
password = os.environ['rk_password']
id_ = os.environ['rk_id']
key = os.environ['rk_key']
rc = RClient(username, password, id_, key)
result = rc.rk_create(img, code)
print('验证码:', result['Result'])
return result['Result']
except Exception:
raise Exception('识别验证码错误')
def identify_image_callback_ruokuai_sogou(img):
return __identify_image_callback(img, 3060)
def identify_image_callback_ruokuai_weixin(img):
return __identify_image_callback(img, 3040)