$numero, 'mensaje' => $mensaje, ], JSON_UNESCAPED_UNICODE); $endpoint = $baseUrl . '/api/sms/send'; $ch = curl_init($endpoint); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Authorization: Bearer ' . $key, ], CURLOPT_TIMEOUT => 15, CURLOPT_SSL_VERIFYPEER => true, ]); $raw = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $err = curl_error($ch); curl_close($ch); if ($err) jsonError('Error de conexión: ' . $err, 502); if (!$raw) jsonError('Sin respuesta del servidor SMS.', 502); $resp = json_decode($raw, true); if ($code >= 200 && $code < 300 && !empty($resp['ok'])) { jsonOk(['id' => $resp['id'] ?? null]); } $msg = $resp['error'] ?? "Error HTTP {$code}"; jsonError($msg, 502);