-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtencent_captcha.py
More file actions
39 lines (34 loc) · 1.43 KB
/
tencent_captcha.py
File metadata and controls
39 lines (34 loc) · 1.43 KB
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
from flask import current_app, request
from everyclass.rpc.http import HttpRpc
class TencentCaptcha:
@classmethod
def _verify(cls, ticket: str, rand_str: str, user_ip: str) -> bool:
params = {
"aid" : current_app.config['TENCENT_CAPTCHA_AID'],
"AppSecretKey": current_app.config['TENCENT_CAPTCHA_SECRET'],
"Ticket" : ticket,
"Randstr" : rand_str,
"UserIP" : user_ip
}
resp = HttpRpc.call(method="GET",
url='https://ssl.captcha.qq.com/ticket/verify',
params=params,
retry=True)
return bool(resp["response"])
@classmethod
def verify(cls):
if not all(map(request.json.get, ["captcha_ticket", "captcha_rand"])):
return False
else:
return cls._verify(request.json["captcha_ticket"],
request.json["captcha_rand"],
request.json["remote_addr"])
# identity 服务上线前这个方法要被 server 调,先留着
@classmethod
def verify_old(cls):
if not all(map(request.form.get, ["captcha-ticket", "captcha-rand"])):
return False
else:
return cls._verify(request.form["captcha-ticket"],
request.form["captcha-rand"],
request.remote_addr)