Endroid\QrCode\QrCode::getContentType PHP Method

getContentType() public method

Returns the content type corresponding to the image type.
public getContentType ( ) : string
return string
    public function getContentType()
    {
        $contentType = 'image/' . $this->image_type;
        return $contentType;
    }

Usage Example

Example #1
0
 public function qrAction()
 {
     // 生成二维码
     $username = urlencode('账号:') . '*****@*****.**';
     $secretKey = 'DPI45HCE';
     $url = "otpauth://totp/{$username}?secret={$secretKey}&issuer=" . urlencode('XXTIME.COM');
     $qrCode = new QrCode();
     $qrCode->setText($url)->setSize(200)->setPadding(10)->setErrorCorrection('low')->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0))->setImageType(QrCode::IMAGE_TYPE_PNG);
     header('Content-Type: ' . $qrCode->getContentType());
     $qrCode->render();
     exit;
     // 验证
     $totp = new PHPGangsta_GoogleAuthenticator();
     $secretKey = $totp->createSecret(32);
     $oneCode = $totp->getCode($secretKey);
     $checkResult = $totp->verifyCode($secretKey, $oneCode, 2);
     // 2 = 2*30sec clock tolerance
     if ($checkResult) {
         echo 'OK';
         dd($secret, $oneCode);
     } else {
         echo 'FAILED';
     }
     exit;
 }
All Usage Examples Of Endroid\QrCode\QrCode::getContentType