api_url = getenv('SMM_API_URL'); $this->api_key = getenv('SMM_API_KEY'); if (!$this->api_url || !$this->api_key) { throw new Exception('API configuration missing'); } } /* ================= SERVICES ================= */ public function services(): array { return $this->request(['action' => 'services']); } public function balance(): array { return $this->request(['action' => 'balance']); } /* ================= ORDER ================= */ public function order(array $data): array { $this->validateOrder($data); return $this->request(array_merge(['action' => 'add'], $data)); } public function status(int $orderId): array { return $this->request([ 'action' => 'status', 'order' => $orderId ]); } public function multiStatus(array $orderIds): array { return $this->request([ 'action' => 'status', 'orders' => implode(',', array_map('intval', $orderIds)) ]); } public function cancel(array $orderIds): array { return $this->request([ 'action' => 'cancel', 'orders' => implode(',', array_map('intval', $orderIds)) ]); } /* ================= REFILL ================= */ public function refill(int $orderId): array { return $this->request([ 'action' => 'refill', 'order' => $orderId ]); } public function multiRefill(array $orderIds): array { return $this->request([ 'action' => 'refill', 'orders' => implode(',', array_map('intval', $orderIds)) ]); } public function refillStatus(int $refillId): array { return $this->request([ 'action' => 'refill_status', 'refill' => $refillId ]); } public function multiRefillStatus(array $refillIds): array { return $this->request([ 'action' => 'refill_status', 'refills' => implode(',', array_map('intval', $refillIds)) ]); } /* ================= CORE REQUEST ================= */ private function request(array $data): array { $payload = http_build_query(array_merge([ 'key' => $this->api_key ], $data)); $ch = curl_init($this->api_url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, CURLOPT_TIMEOUT => $this->timeout, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_HTTPHEADER => [ 'Accept: application/json', 'User-Agent: SecureSMMClient/2.0' ] ]); $response = curl_exec($ch); if ($response === false) { throw new Exception('Curl error: ' . curl_error($ch)); } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode !== 200) { throw new Exception('API HTTP error: ' . $httpCode); } return json_decode($response, true, 512, JSON_THROW_ON_ERROR); } /* ================= VALIDATION ================= */ private function validateOrder(array $data): void { if (empty($data['service']) || !is_numeric($data['service'])) { throw new Exception('Invalid service ID'); } if (!empty($data['quantity'])) { $qty = (int)$data['quantity']; if ($qty < 1 || $qty > 100000) { throw new Exception('Invalid quantity range'); } } if (!empty($data['link'])) { if (!filter_var($data['link'], FILTER_VALIDATE_URL)) { throw new Exception('Invalid link'); } } foreach (['comments','usernames','groups','hashtags'] as $field) { if (isset($data[$field])) { $data[$field] = trim(strip_tags((string)$data[$field])); } } } }