Forgets commited on
Commit
a94347b
·
verified ·
1 Parent(s): 1225e8e

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -118
app.py DELETED
@@ -1,118 +0,0 @@
1
- from fastapi import FastAPI, HTTPException
2
- import cv2
3
- import numpy as np
4
- import httpx
5
- import uvicorn
6
- import base64
7
- import re
8
-
9
- app = FastAPI()
10
-
11
- # RSCaptcha API Endpoints
12
- RS_GET_URL = "https://rscaptcha.com/captcha/v5/get"
13
- RS_VERIFY_URL = "https://rscaptcha.com/captcha/v5/verify"
14
-
15
- def solve_distance(bg_b64, target_b64):
16
- """
17
- Logika AI untuk menghitung jarak geser menggunakan Canny Edge Detection
18
- """
19
- # Decode Base64 ke OpenCV format
20
- bg_bytes = base64.b64decode(re.sub(r'^data:image/\w+;base64,', '', bg_b64))
21
- target_bytes = base64.b64decode(re.sub(r'^data:image/\w+;base64,', '', target_b64))
22
-
23
- bg_img = cv2.imdecode(np.frombuffer(bg_bytes, np.uint8), cv2.IMREAD_COLOR)
24
- target_img = cv2.imdecode(np.frombuffer(target_bytes, np.uint8), cv2.IMREAD_COLOR)
25
-
26
- # Preprocessing: Grayscale
27
- bg_gray = cv2.cvtColor(bg_img, cv2.COLOR_BGR2GRAY)
28
- target_gray = cv2.cvtColor(target_img, cv2.COLOR_BGR2GRAY)
29
-
30
- # Canny Edge Detection untuk akurasi tinggi pada puzzle
31
- bg_edge = cv2.Canny(bg_gray, 100, 200)
32
- target_edge = cv2.Canny(target_gray, 100, 200)
33
-
34
- # Template Matching pada hasil Edges
35
- res = cv2.matchTemplate(bg_edge, target_edge, cv2.TM_CCOEFF_NORMED)
36
- _, _, _, max_loc = cv2.minMaxLoc(res)
37
-
38
- # Koordinat X (jarak geser) adalah max_loc[0]
39
- return float(max_loc[0])
40
-
41
- @app.get("/")
42
- async def root():
43
- return {"status": "running", "message": "DAN AI Solver is Ready"}
44
-
45
- @app.post("/bypass")
46
- async def bypass(app_id: str, public_key: str, cookies: str = ""):
47
- async with httpx.AsyncClient(timeout=30.0) as client:
48
- try:
49
- # Headers wajib agar tidak dianggap bot oleh server RSCaptcha
50
- headers_rs = {
51
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
52
- "Origin": "https://99faucet.com",
53
- "Referer": "https://99faucet.com/",
54
- "Cookie": cookies, # Meneruskan cookie dari PHP
55
- "Content-Type": "application/x-www-form-urlencoded"
56
- }
57
-
58
- # LANGKAH 1: Ambil Gambar dari RSCaptcha
59
- payload_get = {
60
- 'app_id': app_id,
61
- 'public_key': public_key,
62
- 'version': 'v5'
63
- }
64
-
65
- resp_get = await client.post(RS_GET_URL, data=payload_get, headers=headers_rs)
66
- data = resp_get.json()
67
-
68
- if 'data' not in data or 'tile_image_base64' not in data['data']:
69
- return {
70
- "status": "error",
71
- "message": "Gagal fetch puzzle (Cookie mungkin invalid atau IP diblokir)",
72
- "raw_response": data
73
- }
74
-
75
- captcha_key = data['data']['captcha_key']
76
- display_y = data['data']['display_y']
77
- master_img = data['data']['master_image_base64']
78
- tile_img = data['data']['tile_image_base64']
79
-
80
- # LANGKAH 2: Hitung Jarak Geser dengan OpenCV
81
- distance = solve_distance(master_img, tile_img)
82
-
83
- # LANGKAH 3: Verifikasi Langsung ke RSCaptcha Server
84
- # Format response: "x,y" (koordinat horizontal,koordinat vertikal)
85
- response_val = f"{distance},{display_y}"
86
-
87
- verify_payload = {
88
- 'app_id': app_id,
89
- 'public_key': public_key,
90
- 'version': 'v5',
91
- 'token': captcha_key,
92
- 'response': response_val
93
- }
94
-
95
- resp_verify = await client.post(RS_VERIFY_URL, data=verify_payload, headers=headers_rs)
96
- v_data = resp_verify.json()
97
-
98
- # LANGKAH 4: Kirim hasil final balik ke PHP
99
- # Beberapa server RSCaptcha mengembalikan 'result' (token terenkripsi)
100
- if v_data.get('data') == 'ok' or 'result' in v_data:
101
- return {
102
- "status": "success",
103
- "rscaptcha_token": captcha_key,
104
- "rscaptcha_response": v_data.get('result') or response_val,
105
- "distance": distance
106
- }
107
- else:
108
- return {
109
- "status": "fail",
110
- "message": "Verifikasi RSCaptcha ditolak",
111
- "details": v_data
112
- }
113
-
114
- except Exception as e:
115
- return {"status": "error", "message": f"Server Error: {str(e)}"}
116
-
117
- if __name__ == "__main__":
118
- uvicorn.run(app, host="0.0.0.0", port=7860)