-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_server.php
More file actions
100 lines (85 loc) · 2.82 KB
/
Copy pathverify_server.php
File metadata and controls
100 lines (85 loc) · 2.82 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET,POST');
header('Access-Control-Allow-Headers: Content-Type');
// 数据库连接(Termux 修复版 TCP)
$host = '127.0.0.1';
$user = 'root';
$pass = '';
$dbname = 'yzzip_db';
$port = 3306;
$conn = new mysqli($host, $user, $pass, $dbname, $port);
if($conn->connect_error){
die(json_encode(['code'=>500,'msg'=>'数据库错误']));
}
$action = $_GET['action'] ?? '';
// =============================================
// 后端环境校验(机器人直接拒绝)
// =============================================
function checkEnv() {
$ua = $_GET['ua'] ?? '';
$sw = (int)$_GET['sw'] ?? 0;
$canvas = $_GET['canvas'] ?? '';
if(strlen($ua) < 20) return false;
if($sw < 200 || $sw > 4000) return false;
if(strlen($canvas) < 5) return false;
return true;
}
// =============================================
// 生成验证令牌(完整版风控)
// =============================================
if($action === 'get_alpcat_token'){
if(!checkEnv()){
echo json_encode(['code'=>403,'msg'=>'非法访问']);
exit;
}
$token = bin2hex(random_bytes(16));
$expire = time() + 300;
$stmt = $conn->prepare("INSERT INTO verify(token,status,expire_time) VALUES(?,0,?)");
$stmt->bind_param("si", $token, $expire);
if($stmt->execute()){
echo json_encode(['code'=>200,'msg'=>'获取令牌成功','token'=>$token]);
} else {
echo json_encode(['code'=>500,'msg'=>'生成失败']);
}
$stmt->close();
exit;
}
// =============================================
// 验证令牌
// =============================================
if($action === 'verify_alpcat'){
$token = $_GET['token'] ?? '';
$now = time();
$stmt = $conn->prepare("SELECT * FROM verify WHERE token=? AND status=0 AND expire_time>?");
$stmt->bind_param("si", $token, $now);
$stmt->execute();
$r = $stmt->get_result();
if($r->num_rows > 0){
$up = $conn->prepare("UPDATE verify SET status=1 WHERE token=?");
$up->bind_param("s", $token);
$up->execute();
echo json_encode(['code'=>200,'msg'=>'验证成功']);
} else {
echo json_encode(['code'=>403,'msg'=>'验证失败']);
}
exit;
}
// =============================================
// 默认TOKEN校验
// =============================================
$token = $_GET['token'] ?? '';
if(empty($token)){
echo json_encode(['code'=>400,'msg'=>'请传入token']);
exit;
}
$stmt = $conn->prepare("SELECT * FROM verify WHERE token=? AND status=1");
$stmt->bind_param("s", $token);
$stmt->execute();
$r = $stmt->get_result();
echo $r->num_rows>0
? '{"code":200,"msg":"验证成功"}'
: '{"code":403,"msg":"验证失败"}';
$conn->close();
?>