-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsms.php
More file actions
53 lines (43 loc) · 1.29 KB
/
sms.php
File metadata and controls
53 lines (43 loc) · 1.29 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
<?php
class APIClient
{
private const API_URL = 'https://hustlers.ly/api/api';
private const API_KEY = '95e7b2cb83ef7f2c638eb88b839a49c0';
private const USER_AGENT = 'Hustlers/1.0';
public function sendRequest(array $data): ?string
{
$ch = curl_init(self::API_URL);
if ($ch === false) {
throw new RuntimeException('Failed to initialize cURL.');
}
$data['key'] = self::API_KEY;
$postData = http_build_query($data);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => self::USER_AGENT,
]);
$response = curl_exec($ch);
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
throw new RuntimeException("cURL request failed: $error");
}
curl_close($ch);
return $response;
}
}
try {
$apiClient = new APIClient();
$data = [
'From' => 'Name',
'phone' => '44xxxxxxxxxx',
'message' => 'Your message here.',
];
$response = $apiClient->sendRequest($data);
echo $response;
} catch (RuntimeException $e) {
error_log($e->getMessage());
}
?>