maxlen / anticaptcha

anti-captcha.com 的包装器

安装次数: 365

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 1

类型:扩展

dev-master 2017-01-05 13:51 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:36:51 UTC


README

anti-captcha.com 的包装器

安装说明

composer require maxlen/anticaptcha

用于 captcha 图像转文字

$resCaptcha = new CaptchaService(
    $apiKey, // your apiKey from anti-captcha.com
    CaptchaService::TYPE_IMAGE_TO_TEXT,
    ['imgPath' => '/home/user/example.png'] // path to captcha image
);

echo $resCaptcha->check(); // text-result

// or

$resCaptcha->check();
echo $resCaptcha->hashResult; // text-result

用于 reCaptcha

// $html - it's html-code from $url
// $html = file_get_contents($url) or something like that

if (Captcha::isCaptcha($html)) {
    $html = self::CaptchaProc($url, $html);
    die('CAPTCHA RESOLVED');
}

private function CaptchaProc($url, $html)
{
    $resCaptcha = new CaptchaService(
        $apiKey, // your apiKey from anti-captcha.com
        CaptchaService::TYPE_NO_CAPTCHA_PROXYLESS,
        [
            'webSiteUrl' => $url,
            'html' => $html,
        ]
    );

//        echo PHP_EOL . "getWebSiteKey: " . $resCaptcha->getWebSiteKey();
//        echo PHP_EOL . "getWebSiteSToken: " . $resCaptcha->getWebSiteSToken();
//        echo PHP_EOL;
//        var_dump($resCaptcha->getResolveGetParams());

    if (!$resCaptcha->check()) {
        return false;
    }

    $resolveUrl = $url . '&g-recaptcha-response=' . $resCaptcha->hashResult;
    return file_get_contents($resolveUrl); // curl or something like that
}