下载qrcode包
官网下载:http://phpqrcode.sourceforge.net/
解压出来:
tp中生成
把phpqrcode
文件夹复制到vendor
文件夹:
代码实现:
<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
class Index extends Controller
{
public function index()
{
Vendor('phpqrcode.qrlib');
$content = "BEGIN:VCARD\n";
$content .= "VERSION:4.0\n";
$content .= "N:光\n"; //姓
$content .= "FN:头强\n"; //名字
$content .= "EMAIL:[email protected]\n"; //电子邮箱
$content .= "ORG:山东砍树集团有限公司\n"; //组织
$content .= "TEL;WORK;VOICE:18888888888\n"; //工作电话
// $content .= "TEL;HOME;VOICE:18888888888\n"; //家庭电话
// $content .= "TEL;TYPE=cell:18888888888\n"; //移动电话
$content .= "ADR;HOME:;;山东熊出没集团;市中区;济南市;山东省;374400;中国\n";
$content .= "URL:http://www.wangchuangcode.cn\n";
$content .= "END:VCARD\n";
$object = new \QRcode();
$object->png($content);
die;
}
}
如果,想把电子名片的二维码保存到本地,可给
png
方法加第二个参数:
$object->png($content,'code.png');
默认就保存到了public
文件夹下。
浏览器中显示:
php中生成
新建一个qrcode
目录(可自定义目录名),把下载好的qrcode文件夹复制到新建的目录下,在新建的目录下在新建一个index.php
文件:
index.php:
<?php
include './phpqrcode/qrlib.php';
$content = "BEGIN:VCARD\n";
$content .= "VERSION:4.0\n";
$content .= "N:光\n"; //姓
$content .= "FN:头强\n"; //名字
$content .= "EMAIL:[email protected]\n"; //电子邮箱
$content .= "ORG:山东砍树集团有限公司\n"; //组织
$content .= "TEL;WORK;VOICE:18888888888\n"; //工作电话
// $content .= "TEL;HOME;VOICE:18888888888\n"; //家庭电话
// $content .= "TEL;TYPE=cell:18888888888\n"; //移动电话
$content .= "ADR;HOME:;;山东熊出没集团;市中区;济南市;山东省;374400;中国\n";
$content .= "URL:http://www.wangchuangcode.cn\n";
$content .= "END:VCARD\n";
QRcode::png($content);
浏览器中生成:
微信上扫描结果: