{"id":224,"date":"2018-10-25T17:53:30","date_gmt":"2018-10-25T20:53:30","guid":{"rendered":"http:\/\/hackerzone.com.br\/blog\/?p=224"},"modified":"2022-08-13T00:08:54","modified_gmt":"2022-08-13T03:08:54","slug":"qr-code-com-o-google-e-php","status":"publish","type":"post","link":"http:\/\/hackerzone.com.br\/blog\/qr-code-com-o-google-e-php\/","title":{"rendered":"QR Code com o Google e PHP"},"content":{"rendered":"<p>O Google fornece a API de c\u00f3digo QR. N\u00f3s podemos usar isso usando php. Ao digitalizar o c\u00f3digo QR, obtemos informa\u00e7\u00f5es espec\u00edficas. aqui chl \u00e9 a string codificada em url que voc\u00ea tem que adicionar em um c\u00f3digo QR. O choe \u00e9 a codifica\u00e7\u00e3o (opcional).<\/p>\n<p>Vamos fazer o exemplo seguindo o c\u00f3digo:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html lang=&quot;en&quot;&gt;\r\n    &lt;head&gt;\r\n        &lt;title&gt;Bootstrap Example&lt;\/title&gt;\r\n        &lt;meta charset=&quot;utf-8&quot;&gt;\r\n        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;\r\n        &lt;link rel=&quot;stylesheet&quot; href=&quot;https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.7\/css\/bootstrap.min.css&quot;&gt;\r\n           &lt;script src=&quot;https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.2.1\/jquery.min.js&quot;&gt;&lt;\/script&gt;\r\n        &lt;script src=&quot;https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.7\/js\/bootstrap.min.js&quot;&gt;&lt;\/script&gt;\r\n    &lt;\/head&gt;\r\n    &lt;body&gt;\r\n \r\n        &lt;div class=&quot;container&quot;&gt;\r\n            &lt;img id=&quot;qrcodeimg&quot; \/&gt;\r\n            &lt;form&gt;\r\n                &lt;div class=&quot;form-group&quot;&gt;\r\n                    &lt;label for=&quot;sel1&quot;&gt;Select list (select one):&lt;\/label&gt;\r\n                    &lt;select class=&quot;form-control&quot; id=&quot;sel1&quot; onchange=&quot;getQrData(this.value)&quot;&gt;\r\n                        &lt;option value=&quot;1&quot;&gt;Peter&lt;\/option&gt;\r\n                        &lt;option value=&quot;2&quot;&gt;Gary&lt;\/option&gt;\r\n                    &lt;\/select&gt;\r\n                    &lt;br&gt;\r\n                &lt;\/div&gt;\r\n            &lt;\/form&gt;\r\n        &lt;\/div&gt;\r\n        &lt;script&gt;\r\n            function getQrData(para) {\r\n                $.ajax({\r\n                    type: &quot;POST&quot;,\r\n                    url: &quot;getQrCode.php&quot;,\r\n                    async: false,\r\n                    data: {userId: para},\r\n                    success: function (data) {\r\n                        $('#qrcodeimg').attr('src', data);\r\n                    }\r\n                });\r\n            }\r\n        &lt;\/script&gt;    \r\n     \r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>E aqui est\u00e1 o arquivo PHP para obter a resposta da p\u00e1gina PHP.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n$servername = &quot;localhost&quot;;\r\n$username = &quot;root&quot;;\r\n$password = &quot;&quot;;\r\n$dbname = &quot;albumdb&quot;;\r\n\r\n$userId = $_POST['userId'];\r\n\/\/ Create connection\r\n$conn = new mysqli($servername, $username, $password, $dbname);\r\n\/\/ Check connection\r\nif ($conn-&gt;connect_error) {\r\n    die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);\r\n}\r\n$query = &quot;SELECT *\r\nFROM `user` WHERE userId='&quot; . $userId . &quot;'&quot;;\r\n$result = $conn-&gt;query($query);\r\nif ($result-&gt;num_rows &gt; 0) {\r\n    $row = $result-&gt;fetch_assoc();\r\n    $content = json_encode($row);\r\n    $size = 300;\r\n    $google_api = &quot;http:\/\/chart.apis.google.com\/chart?&quot; . 'chs=' . $size . 'x' . $size . '&amp;cht=qr&amp;chl=' . urlencode($content);\r\n    echo $google_api;\r\n    exit;\r\n}\r\n?&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>O Google fornece a API de c\u00f3digo QR. N\u00f3s podemos usar isso usando php. Ao digitalizar o c\u00f3digo QR, obtemos informa\u00e7\u00f5es espec\u00edficas. aqui chl \u00e9 a string codificada em url que voc\u00ea tem que adicionar em um c\u00f3digo QR. O choe \u00e9 a codifica\u00e7\u00e3o (opcional). Vamos fazer o exemplo seguindo o c\u00f3digo: E aqui est\u00e1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":456,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[100,15,98,99],"class_list":["post-224","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-google-qr-code","tag-php","tag-qr-code","tag-qrcode","cat-12-id","has_thumb"],"_links":{"self":[{"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/posts\/224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/comments?post=224"}],"version-history":[{"count":1,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/posts\/224\/revisions"}],"predecessor-version":[{"id":225,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/posts\/224\/revisions\/225"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/media\/456"}],"wp:attachment":[{"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/media?parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/categories?post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/tags?post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}