-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path1.php
More file actions
217 lines (181 loc) · 9.78 KB
/
1.php
File metadata and controls
217 lines (181 loc) · 9.78 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
function handle_follow_profile($cookies, $object_slug) {
try {
// Trích xuất CSRF token từ cookie (nên tìm token thực sự)
$csrfToken = '';
if (preg_match('/JSESSIONID="([^"]+)/', $cookies, $matches) ||
preg_match('/JSESSIONID=([^;]+)/', $cookies, $matches)) {
$csrfToken = $matches[1];
} else {
throw new Exception("JSESSIONID not found in cookie");
}
$headers = [
'accept: application/vnd.linkedin.normalized+json+2.1',
'accept-language: en-US,en;q=0.9,vi;q=0.8',
'content-type: application/json; charset=UTF-8',
'cookie: ' . $cookies,
'csrf-token: ' . $csrfToken,
'origin: https://www.linkedin.com',
'priority: u=1, i',
'referer: https://www.linkedin.com/in/'.$object_slug.'/',
'sec-ch-ua: "Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
'sec-ch-ua-mobile: ?0',
'sec-ch-ua-platform: "Windows"',
'sec-fetch-dest: empty',
'sec-fetch-mode: cors',
'sec-fetch-site: same-origin',
'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
'x-li-lang: en_US',
'x-li-page-instance: urn:li:page:d_flagship3_profile_view_base;FfVsnUDBSeKbxF4QglwA+w==',
'x-li-pem-metadata: Voyager - Follows=follow-action,Voyager - Profile Actions=topcard-overflow-follow-action-click',
'x-li-track: {"clientVersion":"1.13.34103","mpVersion":"1.13.34103","osName":"web","timezoneOffset":7,"timezone":"Asia/Saigon","deviceFormFactor":"DESKTOP","mpName":"voyager-web","displayDensity":1.25,"displayWidth":1920,"displayHeight":1080}',
'x-restli-protocol-version: 2.0.0',
];
// Bước 1: Lấy thông tin profile
$url = "https://www.linkedin.com/voyager/api/identity/profiles/$object_slug";
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FAILONERROR => true
]);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception("Profile info request failed: " . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
throw new Exception("Profile info request returned HTTP $httpCode");
}
curl_close($ch);
$json = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception("Invalid JSON response");
}
// Tìm dashFollowingStateUrn trong response
$slug = null;
if (isset($json['included'])) {
foreach ($json['included'] as $item) {
if (isset($item['dashEntityUrn'])) {
$slug = $item['dashEntityUrn'];
break;
}
}
}
if (!$slug) {
throw new Exception("Could not find follow state URN in response");
}
// Bước 2: Gửi request follow
$url = "https://www.linkedin.com/voyager/api/feed/dash/followingStates/urn:li:fsd_followingState:" . urlencode($slug);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => '{"patch":{"$set":{"following":true}}}',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FAILONERROR => true
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($response === false) {
throw new Exception("Follow request failed: " . curl_error($ch));
}
curl_close($ch);
return $httpCode === 200;
} catch (Exception $e) {
error_log("Follow job error: " . $e->getMessage());
return false;
}
}
function handle_follow_company($cookies, $object_slug) {
try {
// Trích xuất CSRF token từ cookie (nên tìm token thực sự)
$csrfToken = '';
if (preg_match('/JSESSIONID="([^"]+)/', $cookies, $matches) ||
preg_match('/JSESSIONID=([^;]+)/', $cookies, $matches)) {
$csrfToken = $matches[1];
} else {
throw new Exception("JSESSIONID not found in cookie");
}
$headers = [
'accept: application/vnd.linkedin.normalized+json+2.1',
'accept-language: vi,en-US;q=0.9,en;q=0.8',
'content-type: application/json; charset=UTF-8',
'cookie: ' . $cookies,
'csrf-token: ' . $csrfToken,
// ... các headers khác giữ nguyên
];
// Bước 1: Lấy thông tin công ty
$url = "https://www.linkedin.com/voyager/api/organization/companies?q=universalName&universalName=" . urlencode($object_slug);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FAILONERROR => true
]);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception("Company info request failed: " . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
throw new Exception("Company info request returned HTTP $httpCode");
}
curl_close($ch);
$json = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception("Invalid JSON response");
}
// Tìm dashFollowingStateUrn trong response
$slug = null;
if (isset($json['included'])) {
foreach ($json['included'] as $item) {
if (isset($item['dashFollowingStateUrn'])) {
$slug = $item['dashFollowingStateUrn'];
break;
}
}
}
if (!$slug) {
throw new Exception("Could not find follow state URN in response");
}
// Bước 2: Gửi request follow
$url = "https://www.linkedin.com/voyager/api/feed/dash/followingStates/" . urlencode($slug);
$json_data = json_encode(['patch' => ['$set' => ['following' => true]]]);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $json_data,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FAILONERROR => true
]);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception("Follow request failed: " . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode === 200;
} catch (Exception $e) {
error_log("Follow job error: " . $e->getMessage());
return false;
}
}
$cookies = 'bcookie="v=2&469bfb67-116c-4adf-8cfc-7df6d342eebe"; bscookie="v=1&202411171638416a6da6a5-58bf-4925-8d77-677207068e83AQGZFZzYAaZjRGDZCGmAp2O0e4Bmng3J"; g_state={"i_l":0}; li_theme=light; li_theme_set=app; dfpfpt=3a1f494707eb4600bc6bce1a8c693f34; liap=true; JSESSIONID="ajax:-8186210034699348562"; _guid=9ded3c8d-1631-47ed-ac26-62caf2f98ba7; li_sugr=61361c4f-86e4-4fd9-ab26-4c44fd805f8e; aam_uuid=41882750100633849512606982873384629387; _gcl_au=1.1.1231553654.1740401150; timezone=Asia/Saigon; AMCV_14215E3D5995C57C0A495C55%40AdobeOrg=-637568504%7CMCIDTS%7C20185%7CMCMID%7C42380486836294581082657952953036228416%7CMCAAMLH-1744525794%7C3%7CMCAAMB-1744525794%7C6G1ynYcLPuiQxYZrsz_pkqfLG9yMXBpb2zX5dvJdYQJzPXImdj0y%7CMCOPTOUT-1743928194s%7CNONE%7CvVersion%7C5.1.1%7CMCCIDH%7C239376730; lang=v=2&lang=en-us; li_at=AQEDAVEmboQByTgFAAABkzr9ty8AAAGWb85YG00AxoUIY7ylsVknU-GVeLYtzMOj2dIguPIi11II6T2rLYP3SEIbkl91bWtQvtbHKqgb6AAxVwIeKsNxvVK-XFB7pUtqXFB-1uKzvipMH38hNHjnmNIv; AnalyticsSyncHistory=AQIbTYZ476EEWAAAAZZLweE6zrZi9zx_ckx9WNXSZJ287_mBjQ3rXcCexrQu9KJn3RlqjWJDV7Hr9P6LO3yznA; lms_ads=AQF3Bjl1SP0H2AAAAZZLweMmFpZ7ypdZ5We90hL7K2ijB87cyfOizsB0QZI29kFf5DlhouUAndDgafK74jD9mkzKIdPan7QL; lms_analytics=AQF3Bjl1SP0H2AAAAZZLweMmFpZ7ypdZ5We90hL7K2ijB87cyfOizsB0QZI29kFf5DlhouUAndDgafK74jD9mkzKIdPan7QL; fptctx2=taBcrIH61PuCVH7eNCyH0AHEYHVht29NHm46S5qgUjYSseYfCv7DMOrgDapNUR3973SJShxZ%252fJGpwVeKHLGMxjVPRUTb6OaaWl0lfHANweGpV9h0TD49bBGBfFQSwLnIyrhvD%252feeROQfI%252bOvZip33p%252fk3vHoaffdV5br6uIpc88EFI89LNuJcmHNvD5zwmCGxuLuddUQbVh82%252bT1EnSw3zN7YmhX1zu9JistcLyiyUB0nQhtN70FFGjMbtPh8ALnn4vch4kw%252bGFdu4%252fK4Mt%252fMgB7h0esnPTuhVmD35XHwOuyA71zFR%252ftHykJqSB4AwTWvqhXd42hhc%252ffr7hELPUReXzLkNY7axbRNpSSuAJ%252fxQ8%253d; UserMatchHistory=AQKZFIFsTwfFZQAAAZZLxVvLzAbrr02DFbpm5oRQedPOZ3tZ1gQTyuEvKCK2p7RY1yM44bvIJ2WlpiHaoQp4rroNJRrGdmnVeY6uli8ls4QV-1VSS-_ol9wWQ7SVD3PJIRd85YHzGhMMqSsi6p54KkdYtX7CEpnBsI6hD7N1m4AzYurTDhEwsGvEeAUJ-GRqA5m5zvXOQYkhOydyotqxFZM-I6eFs7ZMJNFytI-rRsjGhQFFXsbxDS4CUxvvvwjH4K6L199FYd5atBJ23jQLarv8iukx6TYM5Wi5qmUxJgyPKoyur7JaCvSO8rPvPZfTBgCssOnFDs-LLvjcIdj78DdXY4h4XVeGebUAVyo4DtlaEvZoZg; lidc="b=TB56:s=T:r=T:a=T:p=T:g=5049:u=18:x=1:i=1745027949:t=1745114116:v=2:sig=AQE-42b3ApekuZ7qrARvurQvM-09iX6_';
$object_slug = 'omersuzer';
$result = handle_follow_profile($cookies, $object_slug);
if ($result) {
echo "Follow thành công!";
} else {
$result1 = handle_follow_company($cookies, $object_slug);
if($result1){
echo "Follow thành công!";
}
}