- <?php
- //@author wangbing www.bcty365.com
- namespace Common\Lib;
- class PhpQRCode{
- private $errorCorrectionLevel = 'H';// L M Q H// 纠错级别:L、M、Q、H
- private $matrixPointSize = 3;// 1 2 3 4 5 6 7 8 9 10// 点的大小
- private $date = 'dbuluo';
- private $pngTempDir = '';
- private $pngTempName = '';
- /**
- * 设置
- */
- public function set($key,$value){
- $this->$key = $value;
- }
- public function __construct() {
- vendor("phpqrcode.qrlib");
- }
- public function init(){
- //ofcourse we need rights to create temp dir
- if (!file_exists($this->pngTempDir)){
- mkdir($this->pngTempDir,0755,true);
- }
- if ($this->date != 'dbuluo') {
- // user data
- if ($this->pngTempName != '') {
- $filename = $this->pngTempDir.$this->pngTempName;
- } else {
- $filename = $this->pngTempDir.md5($this->date.'|'.$this->errorCorrectionLevel.'|'.$this->matrixPointSize).'.png';
- }
- \QRcode::png($this->date, $filename, $this->errorCorrectionLevel, $this->matrixPointSize, 2);
- }
- return basename($filename);
- \QRtools::timeBenchmark();
- }
- }
- $qrcode = new \Common\Lib\PhpQrcode ();
- $qrcode->set ( 'pngTempDir', C ( 'CFG_UPLOAD_ROOTPATH' ) . 'likecloth/' . date ( 'Ymd' ) . '/' . $this->uid . '/' );//生成的目录
- $qrcode->set ( 'date', U ( MODULE_NAME . '/Public/qrcode', 'sample_id=' . $sampleid, 'html', true ) );//需要生成的链接url
- $qrcode->set ( 'pngTempName', $this->uid . '.png' );//生成图片的名称
- $prcodeurl = $qrcode->init ();
如果你还有不懂的地方,可以联系头部站长QQ