利用phpqrcode库生成二维码:
1 /* 2 *二维码添加 3 */ 4 ////////////////////////////////////// 5 /*引入文件*/ 6 @include(APP_DIR.'/include/lib/weixin/phpqrcode.php'); 7 /*默认存放路径*/ 8 $save_path = PUBLIC_DIR.'/weixin/';//储存地址 9 if (!file_exists($save_path)) { 10 mkdir($save_path); 11 } 12 $path = $save_path.$deptId.'.png '; 13 $path = strstr($path, '/'); 14 $errorCorrectionLevel = "H"; 15 $matrixPointSize = "4"; 16 if(!file_exists($path)){ 17 $c = 'www.baidu.com'; 18 QRcode::png($c, $save_path.$deptId.'.png',$errorCorrectionLevel,$matrixPointSize); 19 } 20 $this->pagedata['img'] = kernel::base_url(1).'/weixin/'.$deptId.'.png'; 21 ///////////////////////////////////////
利用google接口生成二维码:
1 /* 2 * 生成二维码调用google接口 3 * @var array $params 4 * @access public 5 * @return string 6 */ 7 function generateQRfromGoogle($data,$widhtHeight='205',$EC_level='H',$margin='0'){ 8 9 $url=urlencode($data); 10 11 return '<img src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$url.'" widhtHeight="'.$widhtHeight.'" widhtHeight="'.$widhtHeight.'"/>'; 12 13 }//End Function
还有一种方法:调用jquery.qrcode.js库生成二维码:具体实例就不写了