最近使用发现二步验证用不了,扫码之后提示无法识别的格式,因为安装的时候还发现看的github和文档有点不一样
解决方案:
composer require phpgangsta/googleauthenticator:dev-master
composer require endroid/qr-code
注意这里是安装qr-code而不是qrcode,后者已经弃用了。
然后需要修改一个文件:/application/index/model/TwoFactor.php
,查找public function qrcodeRender()
,修改成如下代码:
public function qrcodeRender(){
ob_end_clean();
$this->secretKey = $this->ga->createSecret();
session("two_factor_enable",$this->secretKey);
$qrCode = new QrCode(urldecode(str_replace("https://api.qrserver.com/v1/create-qr-code/?data=","",$this->ga->getQRCodeGoogleUrl(Option::getValue("siteName"), $this->secretKey))));
$qrCode->setSize(165);
$qrCode->setMargin(0);
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();
}
主要是替换正确的 需要去除 的网址,然后就可以愉快的二步验证了