我需要在我的 ZF 应用程序的表单中插入 ReCaptcha。我正在尝试遵循官方文档,但 ReCaptcha 服务总是返回错误“不正确的验证码溶胶”。我正在使用的代码:
(在表格中)
// configure the captcha service
$privateKey = 'XXXXXXXXXXXXXXXXXXX';
$publicKey = 'YYYYYYYYYYYYYYYYYYYY';
$recaptcha = new Zend_Service_ReCaptcha($publicKey, $privateKey);
// create the captcha control
$captcha = new Zend_Form_Element_Captcha('captcha',
array('captcha' => 'ReCaptcha',
'captchaOptions' => array(
'captcha' => 'ReCaptcha',
'service' => $recaptcha)));
$this->addElement($captcha);
(在控制器中)
$recaptcha = new Zend_Service_ReCaptcha('YYYYYYYYYYYYY', 'XXXXXXXXXXXXXXX');
$result = $recaptcha->verify($this->_getParam('recaptcha_challenge_field'),
$this->_getParam('recaptcha_response_field'));
if (!$result->isValid()) {
//ReCaptcha validation error
}
请问有什么帮助吗?