Home php教程 php手册 利用google api生成二维码名片例子

利用google api生成二维码名片例子

May 25, 2016 pm 04:45 PM
api google

二维条码/二维码可以分为堆叠式/行排式二维条码和矩阵式二维条码,堆叠式/行排式二维条码形态上是由多行短截的一维条码堆叠而成,矩阵式二维条码以矩阵的形式组成,在矩阵相应元素位置上用"点"表示二进制"1",用"空"表示二进制"0","点"和"空"的排列组成代码.

堆叠式/行排式二维条码,如,Code 16K、Code 49、PDF417等.

矩阵式二维码,最流行莫过于QR CODE.

矩阵式二维码存储的数据量更大,可以包含数字、字符,及中文文本等混合内容,有一定的容错性(在部分损坏以后可以正常读取),空间利用率高等.

PHP实例代码如下:

<?php
$vname = &#39;test&#39;;
$vtel = &#39;13800000000&#39;;
generateQRfromGoogle($vname, $vtel);
function generateQRfromGoogle($vname, $vtel, $widhtHeight = &#39;150&#39;, $EC_level = &#39;L&#39;, $margin = &#39;0&#39;) {
    if ($vname && $vtel) {
        $chl = "BEGIN:VCARDnVERSION:3.0" . //vcard头信息
        "nFN:$vname" . "nTEL:$vtel" . "nEND:VCARD"; //vcard尾信息
        echo &#39;<img src="/static/imghw/default1.png"  data-src="http://chart.apis.google.com/chart?chs=&#39; . $widhtHeight . &#39;x&#39; . $widhtHeight . &#39;&cht=qr&chld=&#39; . $EC_level . &#39;|&#39; . $margin . &#39;&chl=&#39; . urlencode($chl) . &#39;"  class="lazy"   alt="QR code" widhtHeight="&#39; . $size . &#39;" widhtHeight="&#39; . $size . &#39;"/>&#39;;
    }
}
?>
Copy after login

php生成网址二维码,代码如下:

<?php
$url = "http://www.google.com.hk";
generateQRfromGoogle($url);
function generateQRfromGoogle($chl, $widhtHeight = &#39;150&#39;, $EC_level = &#39;L&#39;, $margin = &#39;0&#39;) {
    echo &#39;<img src="/static/imghw/default1.png"  data-src="http://chart.apis.google.com/chart?chs=&#39; . $widhtHeight . &#39;x&#39; . $widhtHeight . &#39;&cht=qr&chld=&#39; . $EC_level . &#39;|&#39; . $margin . &#39;&chl=&#39; . urlencode($chl) . &#39;"  class="lazy"   alt="QR code" widhtHeight="&#39; . $size . &#39;" widhtHeight="&#39; . $size . &#39;"/>&#39;;
}
?>
Copy after login

//例子代码如下:

<?php
/*
 * php 生成二维码名片 
 * api Google 
 * google api 二维码生成【QRcode可以存储最多4296个字母数字类型的任意文本,具体可以查看二维码数据格式】 
 * @param string $chl 二维码包含的信息,可以是数字、字符、二进制信息、汉字。不能混合数据类型,数据必须经过UTF-8 URL-encoded.如果需要传递的信息超过2K个字节,请使用POST方式 
 * @param int $widhtHeight 生成二维码的尺寸设置 
 * @param string $EC_level 可选纠错级别,QR码支持四个等级纠错,用来恢复丢失的、读错的、模糊的、数据。 
 *                         L-默认:可以识别已损失的7%的数据 
 *                         M-可以识别已损失15%的数据 
 *                         Q-可以识别已损失25%的数据 
 *                         H-可以识别已损失30%的数据 
 * @param int $margin 生成的二维码离图片边框的距离 
 * 二维码名片的格式---vcard 
 * 格式参考如下: 
  BEGIN:VCARD 
  VERSION:3.0 
  FN:用户名 
  TEL;CELL;VOICE:0571-00000000 
  TEL;WORK;VOICE:0571-00000000 
  TEL;WORK;FAX:0571-00000000 
  EMAIL;PREF;INTERNET:361way 
  URL:http://www.111cn.net 
  orG:361way运维之路 
  ROLE:研发部 
  TITLE:CTO 
  ADR;WORK;POSTAL:杭州市西湖区XXX号;310000 
  REV:2014-2-26T08:30:02Z 
  END:VCARD 
  如果你想更详细的定制所需要的格式,则需要详细的了解vcard的格式标准。 
*/
$vcard = array(
    &#39;vname&#39; => &#39;用户名&#39;,
    &#39;vtel&#39; => &#39;13800000000&#39;,
    &#39;vemail&#39; => &#39;aaaaa@163.com&#39;,
    &#39;vaddress&#39; => &#39;杭州市西湖区&#39;,
);
generateQRfromGoogle($vcard);
Copy after login

function generateQRfromGoogle($vcard, $widhtHeight = '150', $EC_level = 'L', $margin = '0') {

    if ($vcard) {

        $chl = "BEGIN:VCARDnVERSION:3.0" . //vcard头信息

        "nFN:" . $vcard['vname'] . "nTEL:" . $vcard['vtel'] . "nEMAIL:" . $vcard['vemail'] . "nADR:" . $vcard['vaddress'] . "nEND:VCARD"; //vcard尾信息

        echo 'QR code';

    }

}

?>

如果想实现中间有logo的效果,需要通过另外一个logo小图进行拼接即可,这里只提供一种实现方法,也可以通过QRcode的方式进行生成.

vcode的标准信息可以参看维基百科.

注:有些生成的图片经扫描没有的数据的原因是编码导致的,该问题在windows下较常见,由于很多编辑器默认提供的是ANSI编码,更改成utf8就OK了.


本文地址:

转载随意,但请附上文章地址:-)

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Google Pixel 9 and Pixel 9 Pro rumoured to gain Creative Assistant AI upon release Google Pixel 9 and Pixel 9 Pro rumoured to gain Creative Assistant AI upon release Jun 22, 2024 am 10:50 AM

Currently, four new Pixel smartphones are anticipated to land this autumn. To recap, the series is rumoured to feature thePixel 9 and Pixel 9 Pro at launch. However, the Pixel 9 Pro will be a rival to the iPhone 16 Pro rather than a Pixel 8 Pro (curr

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Jul 01, 2024 am 07:22 AM

Google AI has started to provide developers with access to extended context windows and cost-saving features, starting with the Gemini 1.5 Pro large language model (LLM). Previously available through a waitlist, the full 2 million token context windo

Google app beta APK teardown reveals new extensions coming to Gemini AI assistant Google app beta APK teardown reveals new extensions coming to Gemini AI assistant Jul 30, 2024 pm 01:06 PM

Google's AI assistant, Gemini, is set to become even more capable, if the APK teardown of the latest update (v15.29.34.29 beta) is to be considered. The tech behemoth's new AI assistant could reportedly get several new extensions. These extensions wi

Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact Aug 24, 2024 am 06:43 AM

Google recently responded to the performance concerns about the Tensor G4 of the Pixel 9 line. The company said that the SoC wasn't designed to beat benchmarks. Instead, the team focused on making it perform well in the areas where Google wants the c

Google Pixel 9 Pro XL gets tested with desktop mode Google Pixel 9 Pro XL gets tested with desktop mode Aug 29, 2024 pm 01:09 PM

Google has introduced DisplayPort Alternate Mode with the Pixel 8 series, and it's present on the newly launched Pixel 9 lineup. While it's mainly there to let you mirror the smartphone display with a connected screen, you can also use it for desktop

Google Pixel 9 smartphones will not launch with Android 15 despite seven-year update commitment Google Pixel 9 smartphones will not launch with Android 15 despite seven-year update commitment Aug 01, 2024 pm 02:56 PM

The Pixel 9 series is almost here, having been scheduled for an August 13 release. Based on recent rumours, the Pixel 9, Pixel 9 Pro and Pixel 9 Pro XL will mirror the Pixel 8 and Pixel 8 Pro (curr. $749 on Amazon) by starting with 128 GB of storage.

New Google Pixel desktop mode showcased in fresh video as possible Motorola Ready For and Samsung DeX alternative New Google Pixel desktop mode showcased in fresh video as possible Motorola Ready For and Samsung DeX alternative Aug 08, 2024 pm 03:05 PM

A few months have passed since Android Authority demonstrated a new Android desktop mode that Google had hidden away within Android 14 QPR3 Beta 2.1. Arriving hot on the heels of Google adding DisplayPort Alt Mode support for the Pixel 8 and Pixel 8

Google opens AI Test Kitchen & Imagen 3 to most users Google opens AI Test Kitchen & Imagen 3 to most users Sep 12, 2024 pm 12:17 PM

Google's AI Test Kitchen, which includes a suite of AI design tools for users to play with, has now opened up to users in well over 100 countries worldwide. This move marks the first time that many around the world will be able to use Imagen 3, Googl

See all articles