在没有Windows-1252的情况下生成QRCode

时间:2019-05-31 06:47:54

标签: qr-code google-authentication

您好,我用来生成QR码BaconQrCode。我在给Google Authenticator的Gereate QR码上遇到了问题。

要生成QR码,我使用:GoogleAuthenticator

BaconQrCode生成带有字符的QR码,例如:

  

otpauth%3A%2F%2Ftotp%2FLaravel%3Fsecret%3D3DNLF33LLMG7SN2XXX%26issuer%3Dname.surname%2540mydomain.com

我检查并在Google Authenticator中使用此代码:

  

otpauth:// totp / Laravel?secret = 3DNLF33LLMG7SN2XXX&issuer = name.surname%40mydomain.com

1 个答案:

答案 0 :(得分:0)

我更改功能getQRCodeGoogleUrl

public function getQRCodeGoogleUrl($name, $secret, $title = null, $params = array())
{
    $level = !empty($params['level']) && array_search($params['level'], array('L', 'M', 'Q', 'H')) !== false ? $params['level'] : 'M';
    if ($title !== null) {
        $getTitle = $title;
    }
    $urlencoded = "otpauth://totp/$name?secret=$secret&issuer=$getTitle&ecc=$level";
    return $urlencoded;
}

然后我使用BaconQrCodeGenerator

$google_qrCodeUrl = $this->getQRCodeGoogleUrl($title, $secret, $mail);
$qrcode = new BaconQrCodeGenerator;
$qrCodeUrl = $qrcode->size(250)->generate($google_qrCodeUrl);

现在可以正常工作;)