-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneofollower.php
More file actions
104 lines (84 loc) · 2.43 KB
/
Copy pathneofollower.php
File metadata and controls
104 lines (84 loc) · 2.43 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
<?php
/**
* Minimal NeoFollower Reseller API client.
*
* Run:
* NEOFOLLOWER_API_KEY="YOUR_API_KEY" php neofollower.php
*/
final class NeoFollowerApi
{
private string $endpoint = 'https://panel.neofollower.com/api/v1';
private string $apiKey;
public function __construct(string $apiKey)
{
$this->apiKey = $apiKey;
}
private function request(array $payload): array
{
$payload['key'] = $this->apiKey;
$ch = curl_init($this->endpoint);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($payload),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
'Content-Type: application/x-www-form-urlencoded',
'Accept: application/json',
],
]);
$body = curl_exec($ch);
if ($body === false) {
throw new RuntimeException(curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status < 200 || $status >= 300) {
throw new RuntimeException("NeoFollower API HTTP error: {$status}");
}
$data = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
return $data;
}
public function services(): array
{
return $this->request(['action' => 'services']);
}
public function addOrder(
int $service,
string $link,
int $quantity,
array $extra = []
): array {
return $this->request(array_merge([
'action' => 'add',
'service' => $service,
'link' => $link,
'quantity' => $quantity,
], $extra));
}
public function status(int $orderId): array
{
return $this->request([
'action' => 'status',
'order' => $orderId,
]);
}
public function multipleStatus(array $orderIds): array
{
return $this->request([
'action' => 'status',
'orders' => implode(',', $orderIds),
]);
}
public function balance(): array
{
return $this->request(['action' => 'balance']);
}
}
$apiKey = getenv('NEOFOLLOWER_API_KEY');
if (!$apiKey) {
throw new RuntimeException('Set NEOFOLLOWER_API_KEY first.');
}
$api = new NeoFollowerApi($apiKey);
print_r($api->balance());