php实现谷歌验证
我做的是二次开发添加谷歌验证器
下载文件
https://github.com/PHPGangsta/GoogleAuthenticator
引入 (引入的时候注意引入文件的类名要与文件名保持一致,这是我报错的地方)
use Org\Google\GoogleAuthenticatormaster\PHPGangsta\GoogleAuthenticator;
下面是我的代码 我比较菜,代码撮合看看吧,项目的逻辑还是要自己好好盘的
//谷歌绑定
public function google()
{
session_start();
$account=$_SESSION['account'];
$ga = new GoogleAuthenticator();
//这是生成的密钥,每个用户唯一一个,为用户保存起来用于验证
$secret = $ga->createsecret();
$user=D('User');
$where = [
'account'=>$account
];
$secretselect=$user->where($where)->getField('secretKey');
if(!empty($secretselect)){
//您已已经绑定过
echo("您已已经绑定过");
}else{
setcookie("secret",$secret);
//下面为生成二维码,内容是一个uri地址(otpauth://totp/账