这是我生成qr码的代码
public function getUrl($user, $hostname, $secret) {
$encoder = "https://chart.googleapis.com/chart?chs=200x200&chld=M%70&cht=qr&chl=";
$encoderURL = sprintf( "%sotpauth://totp/%s@%s",$encoder, $user, $hostname);
$finalEncodorURL = $encoderURL . "%26secret=". urlencode($secret);
return $finalEncodorURL;
}
应该会产生一个qr码,它做到了。但当我使用Google authenticator app扫描这段代码时,它会生成一个错误
The barcode 'otpauth://totp/user4@noemail.com&secret=UOPKN6QFW3J6PW74' is not a valid authentication barcode.
但是当使用密钥"手动输入"时,它会工作,我可以使用生成的密钥登录。
我在网上找到一些东西说我应该对数据进行unlencode,我做了,但它仍然不起作用
下面是上面函数生成的url示例:https://chart.googleapis.com/chart?chs=200x200&chld=M%70&cht=qr&chl=otpauth://totp/user4@noemail.com%26secret=UOPKN6QFW3J6PW74
我错过了什么还是做错了什么?
将&secret=
替换为?secret=
(不要忘记进行url编码)。
我也不知道这里的情况,但帐户名不能有空格。如果你在android上扫描,它可以工作,但不能在iphone上(想想吧!)
似乎Google和IOS Authenticator应用程序都不喜欢OTP QR码中的"帐户名"中的空格。将它们替换为-或_或删除它们
Windows phone应用程序允许空格,我6个月前在Android phone上安装的一个版本可以工作。我没有机会测试IOS,但看起来IOS存在问题。手动输入键可以正常工作,但不能扫描带有空格的QR码。
您应该完全 URL编码您传递给图表API的数据。
otpauth%3A%2F%2Ftotp%2Fuser4%40noemail.com%26secret%3DUOPKN6QFW3J6PW74
这应该确保数据被正确编码
用%20代替QR码URL中的空格。此问题仅发生在Google Authenticator iOS应用程序中。在Android中,它不需要替换空格。