【问题标题】:PHP - Google Recaptcha proxy setupPHP - Google Recaptcha 代理设置
【发布时间】:2020-04-25 20:29:54
【问题描述】:

我正在为 Google Recaptcha 使用 PHP 包装库。
https://packagist.org/packages/google/recaptcha

我需要设置一个代理,但在我调查时,这个库不支持代理配置。

有没有人有机会为 Google Recaptcha 成功配置代理配置?

这是在没有代理的服务器上正常工作的代码

    /**
     * RecaptchaService constructor.
     *
     * @param ReCaptcha $recaptcha
     */
    public function __construct(ReCaptcha $recaptcha)
    {
        $this->recaptcha = $recaptcha;
    }

    /**
     * @param array $data
     *
     * @return bool
     */
    public function validateCaptcha(array $data): bool
    {
        $response = $this->recaptcha->verify($data['gRecaptchaResponse'], $data['clientIp']);

        return $response->isSuccess() || \PHP_SAPI === 'cli';
    }

我猜应该在verify 方法调用之前或内部配置代理。

【问题讨论】:

    标签: php symfony security proxy recaptcha


    【解决方案1】:

    有一个支持代理的 Google ReCaptcha 库的分支

    https://github.com/toskadv/recaptcha

    $curl = new ReCaptcha\RequestMethod\CurlPost(null, null, [
        CURLOPT_PROXY => 'http://127.0.0.1:9050/',
        CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5
    ]);
    $recaptcha = new \ReCaptcha\ReCaptcha($secret, $curl);
    $resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
    if ($resp->isSuccess()) {
        // verified!
    } else {
        $errors = $resp->getErrorCodes();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-29
      • 2015-10-05
      • 2022-01-19
      • 2020-11-17
      • 2021-05-15
      相关资源
      最近更新 更多