webman 怎么引入 谷歌验证器 这个类

webmanchin

https://github.com/PHPGangsta/GoogleAuthenticator

我直接 require_once GoogleAuthenticator.php
然后 new PHPGangsta_GoogleAuthenticator()
提示不存在 这个类

826 3 1
3个回答

nitron
composer require phpgangsta/googleauthenticator
  • webmanchin 2022-08-23

    Could not find a version of package phpgangsta/googleauthenticator matching your minimum-stability (stable). Require it with an explicit version constraint allowin
    g its desired stability.

    这怎么搞,之间引入文件 不可以吗

nitron

我看了下这个的代码,就一个文件,那很简单啊

把代码里的类名改了, 比如改成class GoogleAuthenticator {...}

放到文件夹里,比如app\tools\

然后再去代码里定义命名空间, 比如这里就是namespace app\tools;

需要用到的地方先引入 use app\tools\GoogleAuthenticator;,都不用require_once,系统会自动帮你设置autoload

然后new GoogleAuthenticator()即可

  • 暂无评论
年代过于久远,无法发表回答
🔝