From 97f9fcbbcb1cf95aaa9bf346f70fffa58d443877 Mon Sep 17 00:00:00 2001 From: taskmgr818 Date: Sun, 3 Nov 2024 18:47:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=AF=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 33 ++++++++++++++++-------------- crack.py | 32 ++++++++++++++++++----------- main.py | 52 +++++++++++++++++++++++++++--------------------- requirements.txt | 2 +- 4 files changed, 68 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 90a9432..24ebde5 100644 --- a/README.md +++ b/README.md @@ -34,21 +34,24 @@ model = Model() crack.gettype() crack.get_c_s() crack.ajax() -pic_content = crack.get_pic() -# 检测文字位置 -small_img, big_img = model.detect(pic_content) -# 判断点选顺序 -result_list = model.siamese(small_img, big_img) -point_list = [] -for i in result_list: - left = str(round((i[0] + 30) / 333 * 10000)) - top = str(round((i[1] + 30) / 333 * 10000)) - point_list.append(f"{left}_{top}") -# 验证请求 -# 注意 请求此函数时请确保全过程时间大于等于4s -# 否则会报 duration short -result = crack.verify(point_list) -print(result) +for retry in range(6): + pic_content = crack.get_pic(retry) + # 检测文字位置 + small_img, big_img = model.detect(pic_content) + # 判断点选顺序 + result_list = model.siamese(small_img, big_img) + point_list = [] + for i in result_list: + left = str(round((i[0] + 30) / 333 * 10000)) + top = str(round((i[1] + 30) / 333 * 10000)) + point_list.append(f"{left}_{top}") + # 验证请求 + # 注意 请确保验证与获取图片间隔不小于2s + # 否则会报 duration short + result = crack.verify(point_list) + print(result) + if eval(result)["data"]["result"] == "success": + break ``` # 协议 diff --git a/crack.py b/crack.py index ef06812..0942aa0 100644 --- a/crack.py +++ b/crack.py @@ -417,27 +417,35 @@ Bm1Zzu+l8nSOqAurgQIDAQAB resp = self.session.get("https://api.geetest.com/ajax.php", params=params).text return json.loads(resp[22:-1])["data"] - def get_pic(self): + def get_pic(self,retry=0): params = { - "is_next": "true", "type": "click", "gt": self.gt, "challenge": self.challenge, "lang": "zh-cn", - "https": "true", - "protocol": "https://", - "offline": "false", - "product": "float", - "api_server": "api.geevisit.com", - "isPC": True, - "autoReset": True, - "width": "100%", "callback": "geetest_" + str(int(round(time.time() * 1000))), } - resp = self.session.get("https://api.geevisit.com/get.php", params=params).text + if retry == 0: + url = "https://api.geevisit.com/get.php" + params.update( + { + "is_next": "true", + "https": "true", + "protocol": "https://", + "offline": "false", + "product": "float", + "api_server": "api.geevisit.com", + "isPC": True, + "autoReset": True, + "width": "100%", + } + ) + else: + url = "https://api.geetest.com/refresh.php" + resp = self.session.get(url, params=params).text data = json.loads(resp[22:-1])["data"] self.pic_path = data["pic"] - pic_url = "https://" + data["resource_servers"][0][:-1] + data["pic"] + pic_url = "https://" + data["image_servers"][0][:-1] + data["pic"] return self.session.get(pic_url).content def verify(self, points: list): diff --git a/main.py b/main.py index 4b71bcc..d3b3785 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,9 @@ import httpx t = time.time() tt = time.time() -reg = httpx.get(f"https://www.geetest.com/demo/gt/register-click-official?t={str(round(time.time()))}").json() +reg = httpx.get( + f"https://www.geetest.com/demo/gt/register-click-official?t={str(round(time.time()))}" +).json() print(time.time() - tt) crack = Crack(reg["gt"], reg["challenge"]) @@ -29,28 +31,32 @@ print(time.time() - tt) model = Model() -tt = time.time() -pic_content = crack.get_pic() -print(time.time() - tt) +for retry in range(6): + tt = time.time() + pic_content = crack.get_pic(retry) + print(time.time() - tt) -tt = time.time() -small_img, big_img = model.detect(pic_content) -print(f"检测到小图: {len(small_img.keys())}个,大图: {len(big_img)} 个,用时: {time.time() - tt}s") -tt = time.time() -result_list = model.siamese(small_img, big_img) -print(f"文字配对完成,用时: {time.time() - tt}") -point_list = [] -# print(result_list) -for i in result_list: - left = str(round((i[0] + 30) / 333 * 10000)) - top = str(round((i[1] + 30) / 333 * 10000)) - point_list.append(f"{left}_{top}") -wait_time = 4.0 - (time.time() - t) -time.sleep(wait_time) -tt = time.time() -result = json.loads(crack.verify(point_list)) -print(result) -print(time.time() - tt) + ttt = tt = time.time() + small_img, big_img = model.detect(pic_content) + print( + f"检测到小图: {len(small_img.keys())}个,大图: {len(big_img)} 个,用时: {time.time() - tt}s" + ) + tt = time.time() + result_list = model.siamese(small_img, big_img) + print(f"文字配对完成,用时: {time.time() - tt}") + point_list = [] + # print(result_list) + for i in result_list: + left = str(round((i[0] + 30) / 333 * 10000)) + top = str(round((i[1] + 30) / 333 * 10000)) + point_list.append(f"{left}_{top}") + wait_time = 2.0 - (time.time() - ttt) + time.sleep(wait_time) + tt = time.time() + result = json.loads(crack.verify(point_list)) + print(result) + print(time.time() - tt) + if result["data"]["result"] == "success": + break total_time = time.time() - t print(f"总计耗时(含等待{wait_time}s): {total_time}") - diff --git a/requirements.txt b/requirements.txt index d20360e..28031cf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -httpx~=0.27.2 +httpx[http2]~=0.27.2 cryptography~=43.0.0 onnxruntime~=1.19.0 opencv-python~=4.10.0.84