forked from WebStackPage/WebStackPage.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjd.php
108 lines (90 loc) · 2.91 KB
/
jd.php
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
100
101
102
103
104
105
106
107
108
<?php
function generateDeviceId() {
$prefix = "001168.";
$id = $prefix . bin2hex(random_bytes(16));
return $id;
}
function loginAndGetToken($loginUrl, $deviceId) {
$headers = [
'Content-Type: application/json; charset=utf-8',
'User-Agent: BeesVPN/2 CFNetwork/1568.100.1 Darwin/24.0.0',
'Accept: */*',
'Accept-Language: zh-CN,zh-Hans;q=0.9'
];
$payload = [
"invite_token" => "",
"device_id" => $deviceId
];
$ch = curl_init($loginUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'cURL error: ' . curl_error($ch);
return null;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode != 200) {
echo 'Failed to login, HTTP status code: ' . $httpCode;
return null;
}
$result = json_decode($response, true);
return $result['data']['token'] ?? null;
}
function fetchAndProcessSubscription($subscribeUrl, $token) {
$headers = [
'Accept: */*',
'User-Agent: BeesVPN/2 CFNetwork/1568.100.1 Darwin/24.0.0'
];
$ch = curl_init($subscribeUrl . '?token=' . $token);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'cURL error: ' . curl_error($ch);
return null;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode != 200) {
echo 'Failed to fetch subscription, HTTP status code: ' . $httpCode;
return null;
}
$result = json_decode($response, true);
$urls = [];
foreach ($result['data'] as $item) {
foreach ($item['list'] as $subItem) {
$url = str_replace('vless:/\\/', 'vless://', $subItem['url'] ?? '');
if ($url) {
$urls[] = $url;
}
}
}
return $urls;
}
function main() {
$apiUrl = 'https://94.74.97.241/api/v1';
$loginEndpoint = '/passport/auth/loginByDeviceId';
$subscribeEndpoint = '/client/appSubscribe';
$deviceId = generateDeviceId();
$token = loginAndGetToken($apiUrl . $loginEndpoint, $deviceId);
if (!$token) {
return;
}
$urls = fetchAndProcessSubscription($apiUrl . $subscribeEndpoint, $token);
if (!$urls) {
return;
}
$content = implode("\n", $urls);
$encodedContent = base64_encode($content);
header('Content-Type: text/plain');
echo $encodedContent;
}
main();