Posted in

Generar QR con PHP + Google Charts


private $apiUrl = 'http://chart.apis.google.com/chart';

// Para generar una targeta de visita (para incluir a Contactos)
$string = 'MECARD:N:' . $data->customer->firstname . ' ' . $data->customer->lastname . ';TEL:' . $data->customer->phone . ';EMAIL:' . $data->customer->email . ';';

// Para generar un SMS
$string = "SMSTO:945454545:Hola soy un mensaje";

// Para llamar
$string = "TEL:9348976897";

// Para enviar un email
$string = "MATMSG:TO:to@domain.com;SUB:Subject;BODY:message;";

// O simplemente un texto o URL
$string = "https://google.com";

$ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $this->apiUrl);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, "chs=400x400&cht=qr&chl=" . urlencode($string));
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_TIMEOUT, 30);
                $img = curl_exec($ch);
                curl_close($ch);
                if ($img) {
                    $filename = "codigo.png";
                    file_put_contents('img/qrs/' . $filename, $img);
                }
Tagged

Deixa un comentari

L'adreça electrònica no es publicarà. Els camps necessaris estan marcats amb *


The reCAPTCHA verification period has expired. Please reload the page.