最近项目需要实现多因子登陆MFA,想到使用谷歌google验证器来实现,github上找到开源库,引入到自己项目时候报错。

项目中需要安装PHPGangsta/GoogleAuthenticator

composer中这么写的:

    "require": {
        "php": ">=5.4.0",
        "topthink/framework": "~5.0.0",
        "erusev/parsedown": "^1.6",
        "phpoffice/phpexcel": "^1.8",
        "upyun/sdk": "^3.3",
        "qcloud/cos-sdk-v5": "^2.0",
        "jenssegers/agent": "^2.6",
        "qcloudsms/qcloudsms_php": "^0.1.4",
        "phpgangsta/googleauthenticator":"^1.0.1"
    }

执行composer update后,出现错误信息如下:

The requested package phpgangsta/googleauthenticator >=1.0.1 is satisfiable by phpgangsta/googleauthenticator[dev-master] but these conflict with your requirements or minimum-stability.

错误原因可能是软件包中没有1.0.1版本

解决办法:

"phpgangsta/googleauthenticator":"^1.0.1"

把这个更换成:"phpgangsta/googleauthenticator":"dev-master"

解决方式参考:

https://github.com/PHPGangsta/GoogleAuthenticator/issues/45

https://github.com/PHPGangsta/GoogleAuthenticator/issues/50