我正在使用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
方法调用之前或之内配置代理。
[具有代理支持的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();
}