【发布时间】:2017-02-16 19:05:07
【问题描述】:
我正在使用这个包:https://github.com/RobThree/TwoFactorAuth,并且我正在尝试按照指南的部分内容使用您自己的 QR 码提供程序。
我下载了phpqrcode.php文件,放到TwoFactorAuth.php所在的目录下。
当require_once 像指南中一样位于顶部时,我收到错误:
致命错误:命名空间声明语句必须是第 4 行 /var/www/public/vendor/robthree/twofactorauth/lib/Providers/Qr/MyProvider.php 脚本中的第一个语句或任何声明调用之后
所以,在带有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
}
}
然后我使用以下代码尝试生成二维码,类似于自述文件:
<?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);
?>
但是我得到了这个错误..
致命错误:未捕获的错误:在 /var/www/public/vendor/robthree/twofactorauth/lib/Providers/Qr/MyProvider.php:13 中找不到类 'RobThree\Auth\Providers\Qr\QRCode' 堆栈跟踪: #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} 抛出 /var/www /public/vendor/robthree/twofactorauth/lib/Providers/Qr/MyProvider.php 在第 13 行
谁能帮我解决这个问题?
【问题讨论】:
标签: php