-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
43 lines (35 loc) · 1.32 KB
/
Copy pathapi.php
File metadata and controls
43 lines (35 loc) · 1.32 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
<?php
// api.php - API برای ارتباط با ربات
header('Content-Type: application/json');
// فعال کردن نمایش خطاها برای دیباگ
error_reporting(E_ALL);
ini_set('display_errors', 1);
// دریافت ورودی
$input = json_decode(file_get_contents('php://input'), true);
$username = $input['username'] ?? '';
if (empty($username)) {
echo json_encode(['status' => 'error', 'message' => 'نام کاربری وارد نشده']);
exit;
}
// ارسال به ربات پایتون
$ch = curl_init('http://localhost:8000/api/repo-info');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['url' => $username]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);
curl_close($ch);
if ($curlError) {
echo json_encode(['status' => 'error', 'message' => "خطا در اتصال به ربات: $curlError"]);
exit;
}
if ($httpCode !== 200) {
echo json_encode(['status' => 'error', 'message' => "ربات با خطا پاسخ داد (کد: $httpCode)"]);
exit;
}
// پاسخ ربات رو مستقیم برگردون
echo $response;
exit;