예제 #1
0
 /**
  * 生成订单二维码
  */
 public function actionGetcode()
 {
     //得到传输过来的字符串
     $string = \Yii::$app->session->getFlash('userbookingstring');
     //使用传输中的KEY值来加密数据
     $tokenString = \Yii::$app->security->encryptByKey(json_encode($string), $string['tokenstring']);
     $url = '1' . ',' . $string['id'] . ',' . urlencode($tokenString);
     //$url = 'http://' . $_SERVER['HTTP_HOST'] . '/member/logistics/fitlogs.html?token=' . $tokenString;
     header("Content-type: image/jpeg");
     $QR = './date/qrcode/qrcode_get' . $string['id'] . '.png';
     $logo = './date/qrcode/logo.png';
     QrCode::png($url, $QR, 0, 3, 2);
     $QR = imagecreatefromstring(file_get_contents($QR));
     $logo = imagecreatefromstring(file_get_contents($logo));
     $QR_width = imagesx($QR);
     //二维码图片宽度
     $QR_height = imagesy($QR);
     //二维码图片高度
     $logo_width = imagesx($logo);
     //logo图片宽度
     $logo_height = imagesy($logo);
     //logo图片高度
     $logo_qr_width = $QR_width / 5;
     $scale = $logo_width / $logo_qr_width;
     $logo_qr_height = $logo_height / $scale;
     $from_width = ($QR_width - $logo_qr_width) / 2;
     //重新组合图片并调整大小
     imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
     imagepng($QR);
     \Yii::$app->end();
 }
예제 #2
0
 public function actionQrcode()
 {
     $key = $this->getCookie("qrcode", "no");
     $domains = Yii::$app->params['domains'];
     $url = $domains["blog"] . "/demo/login?key={$key}";
     header('Content-type: image/png');
     QrCode::png($url, false, Enum::QR_ECLEVEL_H, 8, 0, false);
     exit;
 }
예제 #3
0
 public function actionQrcode($url = '')
 {
     return QrCode::png($url);
 }
예제 #4
0
 public function actionQrcode()
 {
     $qr_text = $this->get("qr_text", GlobalUrlService::buildBlogUrl("/"));
     header('Content-type: image/png');
     QrCode::png($qr_text, false, Enum::QR_ECLEVEL_H, 5, 0, false);
     exit;
 }
예제 #5
0
파일: OtpInit.php 프로젝트: sam002/yii2-otp
 /**
  * @param string $text
  * @return array|int
  * @throws InvalidConfigException
  */
 private function generateQr($text = '')
 {
     $image = null;
     $outfile = false;
     $level = Enum::QR_ECLEVEL_L;
     $size = 3;
     $margin = 4;
     $save = false;
     $type = Enum::QR_FORMAT_JPG;
     foreach ($this->QrParams as $name => $param) {
         switch ($name) {
             case 'outfile':
                 $outfile = $this->checkParamOutfile($param);
                 break;
             case 'level':
                 $level = $this->checkParamLevel($param);
                 break;
             case 'size':
                 $size = $this->checkParamSize($param);
                 break;
             case 'margin':
                 $margin = $this->checkParamMargin($param);
                 break;
             case 'save':
                 $save = $this->checkParamSave($param);
                 break;
             case 'type':
                 $type = $this->checkParamType($param);
                 break;
         }
     }
     QrCode::encode($text, $outfile, $level, $size, $margin, false, $type);
     if (is_file($outfile)) {
         $image = file_get_contents($outfile);
     }
     if (!$save) {
         unlink($outfile);
     }
     return $image;
 }
예제 #6
0
 public function actionPrint()
 {
     set_time_limit(0);
     $cardList = Card::find()->newCard()->all();
     $qrCode = new QrCode();
     $zip = new \ZipArchive();
     $zipFile = Card::CARD_DIR . '/card-files-' . date('dmYHis') . '.zip';
     if ($zip->open($zipFile, \ZipArchive::CREATE)) {
         foreach ($cardList as $card) {
             $filename = Card::CARD_DIR . '/' . $card->cvcode . '.png';
             $qrCode->png($card->fullurl, $filename);
             $card->toPrint();
             $baseName = basename($filename);
             $zip->addFile($filename, $baseName);
         }
         $zip->close();
     }
     Yii::$app->response->sendFile($zipFile, basename($zipFile));
 }