前期准備:
1.phpqrcode類文件下載,下載地址:https://sourceforge.net/projects/phpqrcode/
2.PHP環境必須開啟支持GD2擴展庫支持(一般情況下都是開啟狀態);
生成圖片文件
$data = $wechat['code_url']; url路徑
$level = 'Q';// 糾錯級別:L、M、Q、H
$size = 10;// 1到10,用於手機端4就可以了
include IA_ROOT.'/phpqrcode.php'; 類文件
$QRcode = new QRcode();
ob_start();
$QRcode->png($data,false,$level,$size);
$imageString = base64_encode(ob_get_contents());
ob_end_clean();
$path= IA_ROOT.'/images/';
$num = rand(10000, 99999);
$fileName = time().$num. '.png';
$QRcode->png($data,$path.$fileName,$level,$size);// 生成本地圖片
$wechat['code_url'] = '/images/'.$fileName;
echo json_encode(['code'=>1,'message'=>'二維碼生成成功','wechat'=>$wechat]);
生成原始的二維碼(不生成圖片文件)
function
scerweima2(
$url
=
''
){
require_once
'phpqrcode.php'
;
$value
=
$url
;
//二維碼內容
$errorCorrectionLevel
=
'L'
;
//容錯級別
$matrixPointSize
= 5;
//生成圖片大小
//生成二維碼圖片
$QR
= QRcode::png(
$value
,false,
$errorCorrectionLevel
,
$matrixPointSize
, 2);
}
//調用查看結果