Skip to content

Online (下载加载识别网络上的验证码)

Amatist_Kurisu edited this page Jul 15, 2018 · 4 revisions

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

在使用 Composer 的项目中使用这个包

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

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

<?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
  1. 使用Composer生成ClassMap
    composer update
    # 如果此处运行成功,会在输出 Success 的信息,并 CAPTCHA_Reader 目录下生成一个 verdor 文件夹
  1. 在脚本中使用
<?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 进行验证码的识别

Clone this wiki locally