PHP下载加载识别网络上的验证码

技术文档网 2021-04-16

需要确保安装了 Composer 以及 PHP 版本大于 7 以及安装了GD扩展

在使用 Composer 的项目中使用这个包
  1. Composer 引入 kurisu/captcha_reader

    composer require kurisu/captcha_reader
    
  2. Config/app.php 文件进行配置 将 useGroup 对应的值改成你需要的方案对应的方案名,这里的方案名和 componentGroup 中的各个值一一对应(注意不要打错方案名,否则会无法加载到相应的方案类),目前支持的是以下四种方案以及对应的方案名:

    • 正方教务系统验证码 => ZhengFangNormal
    • 青果教务系统验证码 => QinGuoNormal
    • neea.edu.cn验证码 => NeeaNormal
    • 天翼校园网登录验证码 => TianYiNormal
  3. 在某个类中使用 (只是举个例子)

    <?php
        namespace App\Http\Controllers;
    
        use CAPTCHAReader\src\App\IndexController;
    
        class IdentifyController extends Controller
        {
    
            /**
            * read CAPTCHA
            *
            * @return string
            */
            public function identify()
            {
                $indexController = new IndexController();
    
                $results = $indexController->entrance('https://raw.githubusercontent.com/Kuri-su/CAPTCHA_Reader/master/docs/sample/qinguo.png', 'online');
    
                //支持直接传参数指定使用的方式
                //$results = $indexController->entrance('https://raw.githubusercontent.com/Kuri-su/CAPTCHA_Reader/master/docs/sample/qinguo.png', 'online','QinGuoNormal');
    
                //在 online 模式下,默认会在将图片加载到内存后删除下载的图片文件,如果需要保留这个图片文件,在第四个参数位置传 (bool)false
                //$results = $indexController->entrance('https://raw.githubusercontent.com/Kuri-su/CAPTCHA_Reader/master/docs/sample/qinguo.png', 'online',null,false);
                return results;
            }
        }
    
    在未使用 Composer 的项目中使用这个包

需要安装Composer

  1. 使用 git 将源文件拉取
    git clone https://github.com/Kuri-su/CAPTCHA_Reader.git
    
  2. 使用Composer生成ClassMap
    composer update
    # 如果此处运行成功,会在输出 Success 的信息,并 CAPTCHA_Reader 目录下生成一个 verdor 文件夹
    
  3. 在脚本中使用
    <?php
        //!! 这里的 autoload.php 路径需要自己配置
        require_once(__DIR__ . '/../../vendor/autoload.php');
    
        use CAPTCHAReader\src\App\IndexController;
    
        $indexController = new IndexController();
        $results = $indexController->entrance('https://raw.githubusercontent.com/Kuri-su/CAPTCHA_Reader/master/docs/sample/qinguo.png', 'online');
    
        //支持直接传参数指定使用的方式
        //$results = $indexController->entrance('https://raw.githubusercontent.com/Kuri-su/CAPTCHA_Reader/master/docs/sample/qinguo.png', 'online','QinGuoNormal');
    
        //在 online 模式下,默认会在将图片加载到内存后删除下载的图片文件,如果需要保留这个图片文件,在第四个参数位置传 (bool)false
        //$results = $indexController->entrance('https://raw.githubusercontent.com/Kuri-su/CAPTCHA_Reader/master/docs/sample/qinguo.png', 'online',null,false);
    
        dump($results);
    
    至此,你便成功的开始使用 kurisu/captcha_reader 进行验证码的识别

相关文章

  1. 如何通过xhprof分析性能

    使用方法 xhprof_enable(); /** ... 要检查的php代码 ... **/ $xhprof_data = xhprof_disable(); // 引入xhprof_lib i

  2. LUMEN API Controller 规范

    1. 第三方依赖库规范 在使用LUMEN实现API接口时,以下库必须需要包含在composer包依赖中,以实现代码编写的一些规范 dingo/api : 实现API接口库 vlucas/phpdo

  3. PHP文件锁

    共享锁(LOCK_SH) 什么时候加共享锁? 当在读取数据的时候同时进行着其他的写操作,这个时候需要对文件加共享锁,否则无论有没有对写操作加写锁都会写入成功,导致数据不一致 当文件获得共享锁时,其他

  4. Hello-Risen-程序

    首先需要说明的是,您下载到的文件包含两部分,其中src中是开发源码,用于对Risen框架本身的开发,risen 目录中是通过源码生成的包含debug和release版本的框架程序,用于您应用程序的开发

  5. PHP自定义类示例(Weixin消息解析类)

    PHP自定义类示例(Weixin消息解析类) /** * Created by Qingger. * User: jsspf * Date: 2017/3/24 * Time: 10:50

随机推荐

  1. 如何通过xhprof分析性能

    使用方法 xhprof_enable(); /** ... 要检查的php代码 ... **/ $xhprof_data = xhprof_disable(); // 引入xhprof_lib i

  2. LUMEN API Controller 规范

    1. 第三方依赖库规范 在使用LUMEN实现API接口时,以下库必须需要包含在composer包依赖中,以实现代码编写的一些规范 dingo/api : 实现API接口库 vlucas/phpdo

  3. PHP文件锁

    共享锁(LOCK_SH) 什么时候加共享锁? 当在读取数据的时候同时进行着其他的写操作,这个时候需要对文件加共享锁,否则无论有没有对写操作加写锁都会写入成功,导致数据不一致 当文件获得共享锁时,其他

  4. Hello-Risen-程序

    首先需要说明的是,您下载到的文件包含两部分,其中src中是开发源码,用于对Risen框架本身的开发,risen 目录中是通过源码生成的包含debug和release版本的框架程序,用于您应用程序的开发

  5. PHP自定义类示例(Weixin消息解析类)

    PHP自定义类示例(Weixin消息解析类) /** * Created by Qingger. * User: jsspf * Date: 2017/3/24 * Time: 10:50