_Account = $this->getKey($this->_apiCode); //验证是否具有访问这个接口的权限 if(!isset($this->_Account['isQrcode'])){ HelperService::returnJson(['code'=>400,'msg'=>'isQrcode interface unauthorized access','data'=>[]]); } } /** * 产生二维码的案例 */ public function QR(){ header( "Content-Type:text/html;charset=UTF-8"); $params = $this->_sysParams; $rule = [ 'content|内容'=>'require', 'level|大小的level【LMQH】'=>'require', 'size|大小'=>'require|number', 'is_down|是否下载'=>'require|number', ]; $validate = new Validate($rule); if(!$validate->check($params)){ HelperService::returnJson(['code'=>400,'msg'=>$validate->getError(),'data'=>[]]); } $content = $params['content']; $level = $params['level']; $size = $params['size']; vendor("phpqrcode.phpqrcode"); $png = false; if($params['is_down']){ $time = time().rand(1000,9999); $png = "./qrcode/{$time}.png"; } \QRcode::png($content,$png,$level,min(max($size,4),10),2); if(isset($params['note']) && !empty($params['note'])){ $fontSize = 18; $noteArr = explode(',',$params['note']); //以每行行高22px计算+20的空间 $total_lineHeight = count($noteArr)*30-0; $imageSource = imagecreatefrompng($png); $width = imagesx($imageSource); $height = imagesy($imageSource); //创建画板 $Palette = @imagecreate($width,$height+$total_lineHeight); //填充白色背景 imagecolorallocate($Palette,255,255,255); imagecopyresized($Palette,$imageSource,0,0,0,0,$width,$height,$width,$height); //指定字体的颜色 $color = imagecolorallocate($Palette,0,0,0); $i = 0; foreach($noteArr as $noteLine){ $fontBox = imagettfbbox($fontSize, 0, './font/NotoSansHans-DemiLight.ttf', $noteLine);//水平居中实质 imagettftext($Palette,14,0,ceil(($width - $fontBox[2]) / 2),$height+30*($i++)+15,$color,'./font/NotoSansHans-DemiLight.ttf',$noteLine); } imagepng($Palette, $png); } $note = isset($params['note'])?$params['note']:''; Log::record("old input:\n". json_encode(HelperService::$_sysParams)."\n note: \n".$note); if($params['is_down']) { HelperService::downloadFile($png); } exit; } }