composer安装所需插件
composer install phpgangsta/googleauthenticator:dev-master
生成谷歌key和二维码链接
//用户名,这里可以随意填写,保证唯一就行
$username = '1886666888';
//app名称,这里可以随意填写,能让用户分辨出您的app/系统就行
$app_name = 'xxx管理系统';
// 引用谷歌验证类 若无法引用请看文章最后
$google = new \PHPGangsta_GoogleAuthenticator();
// 生成谷歌key
$secret = $google->createSecret();
// 将谷歌加密key信息保存,并生成二维码链接
$qrcod_url = $google->getQRCodeGoogleUrl($username, $secret, $app_name);
//$secret是谷歌生成的key,可以直接输入绑定
//$qrcod_url是二维码链接,可以使用谷歌身份验证工具扫码绑定
谷歌身份验证工具手机客户端下载地址: Android / IOS
验证谷歌6位验证码是否正确
// 上一步生成的谷歌key
$secret = ''
// 谷歌身份验证器上展示的6位数字验证码
$code