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 = '123456';// 误差时间,谷歌身份验证器30秒更换一次,这个表示最大的误差时间
$time = 0;//0表示实时// 获取验证结果 返回结果true,false
$checkResult = $google->verifyCode($secret,$code,$time);

若无法调用 $google = new \PHPGangsta_GoogleAuthenticator(); 则执行下面这步

composer install google/apiclient:^2.12.1

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部