_smtAccount = $this->getKey($this->_apiCode); //验证是否具有访问这个接口的权限 if( !isset($this->_smtAccount['printSMT']) ){ HelperService::returnJson(['code'=>400,'msg'=>'smt interface unauthorized access','data'=>[]]); } } /** * 打印关西店 */ public function mu(){ $muPath = "static/image/mu"; $fileList = scandir($muPath); foreach($fileList as $fileItem){ if(strpos($fileItem,'.')!==0){ $nameArr = explode("_", $fileItem); $enName = end($nameArr); $this->printMu("$muPath/$fileItem", "$muPath.png", "环贸广场店".current(explode(".", $enName))); //exit; } } } /** * 打印关西店 */ public function bear(){ $muPath = "static/image/xiong"; $fileList = scandir($muPath); foreach($fileList as $fileItem){ if(strpos($fileItem,'.')!==0){ $nameArr = explode("_", $fileItem); $enName = end($nameArr); $this->printBear("$muPath/$fileItem", "$muPath.png", "189店".current(explode(".", $enName))); //exit; } } } /** * 打印扫码贴关西 * @param $fileName * @param $bgName * @param $storeName */ private function printMu($fileName,$bgName,$storeName){ //裁剪 $qrImage = stripos($fileName,'jpg')?imagecreatefromjpeg($fileName): imagecreatefrompng($fileName); $bgImage = stripos($bgName,'jpg')?imagecreatefromjpeg($bgName):imagecreatefrompng($bgName); $width = imagesx($bgImage); $newFileName = str_replace('mu/', 'mu2/', $fileName); //320 imagecopymerge($bgImage, $qrImage, 190, 300, 0, 0, imagesx($qrImage), imagesy($qrImage), 100); stripos($fileName,'jpg')?imagejpeg($bgImage,$newFileName):imagepng($bgImage,$newFileName); $new_bgImage = stripos($newFileName,'jpg')?imagecreatefromjpeg($newFileName):imagecreatefrompng($newFileName); //$white = imagecolorallocate($new_bgImage, 255, 255, 255); $black = imagecolorallocate($new_bgImage, 0, 0, 0); $fontBox = imagettfbbox(18, 0, './font/NotoSansHans-DemiLight.ttf', $storeName);//水平居中实质 imagettftext($new_bgImage,18,0,ceil(($width - $fontBox[2]) / 2)+34,536,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName); imagettftext($new_bgImage,18,0,ceil(($width - $fontBox[2]) / 2)+35,536,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName); //imagettftext($new_bgImage,24,0,30,30,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName); //imagettftext($new_bgImage,50,0,430,420,$white,'./NotoSansHans-DemiLight.ttf',$tableName); stripos($newFileName,'jpg')?imagejpeg($new_bgImage, $newFileName):imagepng($new_bgImage, $newFileName); //system("rm -rf $tableName.png"); //$this->downloadFile($newFileName); } /** * 打印扫码贴关西 * @param $fileName * @param $bgName * @param $storeName */ private function printBear($fileName,$bgName,$storeName){ //裁剪 $qrImage = stripos($fileName,'jpg')?imagecreatefromjpeg($fileName): imagecreatefrompng($fileName); $bgImage = stripos($bgName,'jpg')?imagecreatefromjpeg($bgName):imagecreatefrompng($bgName); $width = imagesx($bgImage); $newFileName = str_replace('xiong/', 'xiong2/', $fileName); //320 imagecopymerge($bgImage, $qrImage, 152, 286, 0, 0, imagesx($qrImage), imagesy($qrImage), 100); stripos($fileName,'jpg')?imagejpeg($bgImage,$newFileName):imagepng($bgImage,$newFileName); $new_bgImage = stripos($newFileName,'jpg')?imagecreatefromjpeg($newFileName):imagecreatefrompng($newFileName); //$white = imagecolorallocate($new_bgImage, 255, 255, 255); $black = imagecolorallocate($new_bgImage, 0, 0, 0); $fontBox = imagettfbbox(20, 0, './font/NotoSansHans-DemiLight.ttf', $storeName);//水平居中实质 imagettftext($new_bgImage,20,0,ceil(($width - $fontBox[2]) / 2),520,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName); imagettftext($new_bgImage,20,0,ceil(($width - $fontBox[2]) / 2)+1,520,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName); //imagettftext($new_bgImage,24,0,30,30,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName); //imagettftext($new_bgImage,50,0,430,420,$white,'./NotoSansHans-DemiLight.ttf',$tableName); stripos($newFileName,'jpg')?imagejpeg($new_bgImage, $newFileName):imagepng($new_bgImage, $newFileName); //system("rm -rf $tableName.png"); //$this->downloadFile($newFileName); } private function downloadFile($file){ $file_name = $file; $mime = 'application/force-download'; header('Pragma: public'); // required header('Expires: 0'); // no cache header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private',false); header('Content-Type: '.$mime); header('Content-Disposition: attachment; filename="'.basename($file_name).'"'); header('Content-Transfer-Encoding: binary'); header('Connection: close'); readfile($file_name); // push it out exit(); } }