私はこのパッケージを使用しています:https://github.com/RobThree/TwoFactorAuthあなた自身のQRコードプロバイダを使用できるガイドの部分に従っています。クラスが見つかりませんPHP(2FAパッケージ)
phpqrcode.php
ファイルをダウンロードし、TwoFactorAuth.php
というディレクトリに配置しました。
require_once
はガイドのように上部にあるとき、私はエラーを取得:
Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in /var/www/public/vendor/robthree/twofactorauth/lib/Providers/Qr/MyProvider.php on line 4
ので、TwoFactorAuth.php
とディレクトリに、私は次のコードでmyprovider.php
を追加しました:
<?php
namespace RobThree\Auth\Providers\Qr;
require_once(__DIR__ . '/../../phpqrcode.php');
class MyProvider implements IQRCodeProvider {
public function getMimeType() {
return 'image/png'; // This provider only returns PNG's
}
public function getQRCodeImage($qrtext, $size) {
ob_start(); // 'Catch' QRCode's output
QRCode::png($qrtext, null, QR_ECLEVEL_L, 3, 4); // We ignore $size and set it to 3
// since phpqrcode doesn't support
// a size in pixels...
$result = ob_get_contents(); // 'Catch' QRCode's output
ob_end_clean(); // Cleanup
return $result; // Return image
}
}
私は次のコードを使用して、readmeと同様にQRコードを生成します。
<?php
require_once __DIR__ . '/vendor/autoload.php';
$mp = new RobThree\Auth\Providers\Qr\MyProvider();
$tfa = new RobThree\Auth\TwoFactorAuth('My Company', 6, 30, 'sha1', $mp);
$secret = $tfa->createSecret();
echo $tfa->getQRCodeImageAsDataUri('Bob Ross', $secret);
?>
しかし、私はこのエラーを取得します。..
Fatal error: Uncaught Error: Class 'RobThree\Auth\Providers\Qr\QRCode' not found in /var/www/public/vendor/robthree/twofactorauth/lib/Providers/Qr/MyProvider.php:13 Stack trace: #0 /var/www/public/vendor/robthree/twofactorauth/lib/TwoFactorAuth.php(146): RobThree\Auth\Providers\Qr\MyProvider->getQRCodeImage('otpauth://totp/...', 200) #1 /var/www/public/test.php(6): RobThree\Auth\TwoFactorAuth->getQRCodeImageAsDataUri('Bob Ross', 'ID2Y3P5C6N2NXKD...') #2 {main} thrown in /var/www/public/vendor/robthree/twofactorauth/lib/Providers/Qr/MyProvider.php on line 13
は、誰もがこれで私を助けることができますか?