欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php二維碼生成

 更新時(shí)間:2015年10月19日 16:28:34   投稿:lijiao  
在二維碼越來越普及之際。我們需要了解一下什么是二維碼,作為了一個(gè)php programer,我們更需要知道如何使用 php生成二維碼。廢話少說,下面說正題。

本文介紹兩種使用 php 生成二維碼的方法。
(1)利用google生成二維碼的開放接口,代碼如下:

/** 
 * google api 二維碼生成【QRcode可以存儲(chǔ)最多4296個(gè)字母數(shù)字類型的任意文本,具體可以查看二維碼數(shù)據(jù)格式】 
 * @param string $data 二維碼包含的信息,可以是數(shù)字、字符、二進(jìn)制信息、漢字。不能混合數(shù)據(jù)類型,數(shù)據(jù)必須經(jīng)過UTF-8 URL-encoded.如果需要傳遞的信息超過2K個(gè)字節(jié),請(qǐng)使用POST方式 
 * @param int $widhtHeight 生成二維碼的尺寸設(shè)置 
 * @param string $EC_level 可選糾錯(cuò)級(jí)別,QR碼支持四個(gè)等級(jí)糾錯(cuò),用來恢復(fù)丟失的、讀錯(cuò)的、模糊的、數(shù)據(jù)。 
 *       L-默認(rèn):可以識(shí)別已損失的7%的數(shù)據(jù) 
 *       M-可以識(shí)別已損失15%的數(shù)據(jù) 
 *       Q-可以識(shí)別已損失25%的數(shù)據(jù) 
 *       H-可以識(shí)別已損失30%的數(shù)據(jù) 
 * @param int $margin 生成的二維碼離圖片邊框的距離 
 */ 
function generateQRfromGoogle($data,$widhtHeight='150',$EC_level='L',$margin='0'){ 
 $url=urlencode($data); 
 echo '<img src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$data.'" widhtHeight="'.$widhtHeight.'" widhtHeight="'.$widhtHeight.'"/>'; 
} 

使用方法:

$data='版權(quán)所有:http://www.dbjr.com.cn'; 
generateQRfromGoogle($data); 

post方法實(shí)現(xiàn)請(qǐng)求google api 生成二維碼的方式:

function qrcode($width,$height,$string){ 
 $post_data=array(); 
 $post_data['cht']='qr'; 
 $post_data['chs']=$width."x".$height; 
 $post_data['chl']=$string; 
 $post_data['choe']="UTF-8"; 
 $url="http://chart.apis.google.com/chart"; 
 $data_Array=array(); 
 foreach($post_data as $key=>$value){ 
  $data_Array[]=$key.'='.$value; 
 } 
 $data=implode("&",$data_Array); 
 $ch=curl_init(); 
 curl_setopt($ch, CURLOPT_POST, 1); 
 curl_setopt($ch, CURLOPT_HEADER, 0); 
 curl_setopt($ch, CURLOPT_URL, $url);  
 curl_setopt($ch, CURLOPT_POSTFIELDS,$data); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
 $result=curl_exec($ch); 
 //echo "<img src =\"data:image/png;base64,".base64_encode($result)."\" >"; 注意,不寫header的寫法 
 return $result; 
} 

使用方法:

header("Content-type:image/png"); 
$width=300; 
$height=300; 
$data='版權(quán)所有:http://www.dbjr.com.cn';
echo qrcode($width,$height,$data); 

當(dāng)然生成的圖片同上面是一樣的。

(2)使用php QR Code類庫生成二維碼
注意使用該類庫必須首先下載類庫包,下載地址:
地址:http://phpqrcode.sourceforge.net/
下載下來的壓縮包里面有很多示例,可以自行研究,下面給出一個(gè)簡單的使用案例(具體參數(shù)的意思和上面大同小異):

<?php 
include "./phpqrcode.php"; 
$data='版權(quán)所有:http://www.dbjr.com.cn'; 
$errorCorrectionLevel="L"; 
$matrixPointSize="4"; 
QRcode::png($data,false,$errorCorrectionLevel,$matrixPointSize);

以上所述就是本文的全部內(nèi)容了,希望對(duì)大家熟練掌握php生產(chǎn)二維碼能夠有所幫助。

相關(guān)文章

最新評(píng)論