-
Notifications
You must be signed in to change notification settings - Fork 0
/
shangcaptcha.py
executable file
·59 lines (51 loc) · 1.82 KB
/
shangcaptcha.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
"""
这个文件,是用于上层调用的, 用于识别米游社签到而准备的
"""
import json
import os
import random
import sys
import time
import requests
from loguru import logger
from twocaptcha import TwoCaptcha
try:
from captchakey import apikey
except:
try:
from mhylogin.captchakey import apikey
logger.warning("找到环境变量中的APIKEY_2CAPTCHA")
except:
apikey = None
logger.warning("未找到验证码APIKEY, 请在环境变量中设置APIKEY_2CAPTCHA")
api_key = os.getenv('APIKEY_2CAPTCHA', apikey)
solver = TwoCaptcha(api_key)
def game_captcha2(gt: str, challenge: str):
logger.warning("开始验证验证码1")
logger.info(f"gt: {gt}")
logger.info(f"challenge: {challenge}")
time.sleep(random.randint(3, 6))
result = solver.geetest(gt=gt,
apiServer='api.geetest.com',
challenge=challenge,
url='https://2captcha.com/demo/geetest'
)
logger.warning(f"验证码 1 返回的结果 result: {result}")
rep = json.loads(result["code"])
logger.warning(f"验证码 1 返回的结果rep: {rep}")
return rep["geetest_validate"]
# return None # 失败返回None 成功返回validate
def bbs_captcha2(gt: str, challenge: str):
logger.warning("开始验证验证码2")
logger.info(f"gt: {gt}")
logger.info(f"challenge: {challenge}")
time.sleep(random.randint(3, 6))
result = solver.geetest(gt=gt,
apiServer='api.geetest.com',
challenge=challenge,
url='https://2captcha.com/demo/geetest'
)
logger.warning(f"验证码 2 返回的结果 result: {result}")
rep = json.loads(result["code"])
logger.warning(f"验证码 2 返回的结果rep: {rep}")
return rep["geetest_validate"]