token = $token; $this->baseUrl = rtrim($baseUrl, '/'); $this->headers = [ 'Authorization: Bearer ' . $this->token, 'Content-Type: application/json', 'Accept: application/json', ]; } // ── Messages ── /** * Send an SMS message */ public function sendSMS(array $body = []): array { return $this->request('POST', '/send', [], $body); } /** * Get delivery status of a message */ public function getMessageStatus(string $id): array { return $this->request('GET', '/messages/' . urlencode($id) . ''); } // ── HTTP helpers ── private function request(string $method, string $path, array $query = [], array $body = []): array { $url = $this->baseUrl . $path; if (!empty($query)) { $url .= '?' . http_build_query($query); } $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => $method, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $this->headers, CURLOPT_TIMEOUT => 30, ]); if (!empty($body) && in_array($method, ['POST', 'PUT', 'PATCH'])) { curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); } $response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return ['status' => $status, 'data' => json_decode($response, true)]; } }