<?php
 namespace App\Modules\Sms\Sms77; use App\Core\Sms\AbstractSms; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; class Sms77 extends AbstractSms { public function sendSms(array $params): array { $to = $params['to'] ?? null; $content = $params['content'] ?? null; if (! $to || ! $content) { return ['success' => false, 'error' => 'Required fields missing (to, content)']; } if ($this->isTestMode) { Log::info('seven.io TEST', ['to' => $to]); return ['success' => true, 'message_id' => 'test_seven_'.uniqid()]; } $apiKey = $this->getConfig('api_key'); if (! $apiKey) { return ['success' => false, 'error' => 'seven.io api_key missing']; } try { $resp = Http::withHeaders([ 'X-Api-Key' => $apiKey, 'SentWith' => 'PROCP', 'Accept' => 'application/json', ])->timeout(30)->asForm()->post('https://gateway.seven.io/api/sms', [ 'to' => $this->normalizeMsisdn($to, $this->getConfig('default_country_code')), 'text' => $content, 'from' => $this->getConfig('from'), 'json' => 1, ]); if (! $resp->successful()) { return ['success' => false, 'error' => 'seven.io HTTP '.$resp->status()]; } $data = $resp->json(); $topCode = isset($data['success']) ? (string) $data['success'] : null; if ($topCode !== '100') { return ['success' => false, 'error' => 'seven.io rejected (code '.($topCode ?? 'unknown').')']; } $message = $data['messages'][0] ?? null; if (is_array($message)) { if (isset($message['success']) && $message['success'] !== true) { return ['success' => false, 'error' => 'seven.io message rejected']; } $messageId = $message['id'] ?? null; } else { $messageId = null; } if (! $messageId) { return ['success' => false, 'error' => 'seven.io: no message id in response']; } return ['success' => true, 'message_id' => (string) $messageId]; } catch (\Throwable $e) { return ['success' => false, 'error' => $e->getMessage()]; } } public function testConnection(array $params): array { $apiKey = $params['api_key'] ?? $this->getConfig('api_key'); if (! $apiKey) { return ['success' => false, 'message' => 'api_key required']; } try { $resp = Http::withHeaders([ 'X-Api-Key' => $apiKey, 'Accept' => 'application/json', ])->timeout(15)->get('https://gateway.seven.io/api/balance'); if (! $resp->successful()) { return ['success' => false, 'message' => 'seven.io HTTP '.$resp->status()]; } return ['success' => true, 'message' => 'seven.io connection OK']; } catch (\Throwable $e) { return ['success' => false, 'message' => 'seven.io connection failed']; } } public function getRequiredConfigFields(): array { return ['api_key']; } public function getConfigFields(): array { return [ 'api_key' => ['type' => 'password', 'label' => 'seven.io API Key', 'required' => true, 'encrypted' => true], 'from' => ['type' => 'text', 'label' => 'Sender ID'], 'default_country_code' => ['type' => 'text', 'label' => 'Default Country Code (e.g. 90, 1, 49)', 'required' => false], 'test_mode' => ['type' => 'boolean', 'label' => 'Test Mode', 'default' => true], ]; } } 