'cURL não disponível neste servidor']); exit; } $SB_URL = 'https://yprpvpkdromuthkkdas.supabase.co'; $SB_KEY = 'sb_publishable_c48azbRk83lRQkFuycm9Xw_fgaB18o6'; $action = $_GET['action'] ?? ''; if (!$action) { echo json_encode(['error' => 'nenhuma action', 'status' => 'proxy online']); exit; } $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'apikey: ' . $SB_KEY, 'Authorization: Bearer ' . $SB_KEY, 'Content-Type: application/json', 'Prefer: return=representation' ]); if ($action === 'get_clientes') { curl_setopt($ch, CURLOPT_URL, $SB_URL . '/rest/v1/clientes?select=*'); } elseif ($action === 'update_status') { $body = json_decode(file_get_contents('php://input'), true); curl_setopt($ch, CURLOPT_URL, $SB_URL . '/rest/v1/clientes?id=eq.' . $body['id']); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['status' => $body['status']])); } elseif ($action === 'update_cliente') { $body = json_decode(file_get_contents('php://input'), true); $id = $body['id']; unset($body['id']); curl_setopt($ch, CURLOPT_URL, $SB_URL . '/rest/v1/clientes?id=eq.' . $id); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); } elseif ($action === 'get_mensagens') { $id = $_GET['cliente_id'] ?? ''; curl_setopt($ch, CURLOPT_URL, $SB_URL . '/rest/v1/mensagens?cliente_id=eq.' . $id . '&order=enviado_em.asc'); } else { echo json_encode(['error' => 'action invalida: ' . $action]); exit; } $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlError = curl_error($ch); curl_close($ch); if ($curlError) { echo json_encode(['error' => 'cURL error: ' . $curlError]); exit; } http_response_code($httpCode); echo $response; ``` Salva e acessa de novo: ``` https://sistemia.com.br/supabase-proxy.php?action=get_clientes