“缺少输入响应”错误重新捕获v3

时间:2019-03-26 15:58:50

标签: javascript php recaptcha

我正在创建一个表单,用于通过Recaptcha发送电子邮件。一切运行正常,但我注意到recaptcha v3仅持续3分钟,需要重置。从那里开始,出现“ missing-input-response”错误。

index.php

<script>
  grecaptcha.ready(function() {
      grecaptcha.execute('key', {action: 'homepage'}).then(function(token) {
         document.getElementById('g-recaptcha-response').value=token;
      }); 
  });
  </script>

  <script>
    var callback = function() {
      grecaptcha.render('id-of-render-element', {
         'sitekey': 'key',
         'expired-callback': expCallback
       });
   };
   var expCallback = function() {
      alert("Your recatpcha has expired, please verify again ...");
      setInterval(function(){ grecaptcha.reset(); }, 5 * 60 * 1000 ); 
   };
  </script>

 <div id="id-of-render-element"></div>
<script src="https://www.google.com/recaptcha/api.js?onload=callback&render=explicit" async defer></script>

验证码类

<?php

    class Captcha{

    public function getCaptcha($SecretKey){

        $Resposta = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=key&response={$SecretKey}");
        $Retorno = json_decode($Resposta);
        return $Retorno;
    }

     public function returnCaptcha(){
         echo "entrou calss_captcha";
  $EnviaMail = False;
  $ObjCaptcha = new Captcha();
  $Retorno=$ObjCaptcha->getCaptcha($_POST['g-recaptcha-response']);
  var_dump($Retorno);
  if($Retorno->success == true && $Retorno->score > 0.5){
      $EnviaMail = True;
  }else{
      $EnviaMail = False;
  }
  return $EnviaMail;
    }
    }

?>

1 个答案:

答案 0 :(得分:0)

根据适用于版本2的用户注释。您需要为file_get_contents函数调用指定其他参数,如果您的站点具有SSL,则设置上下文选项。

<ClaimsProvider>
  <DisplayName>PhoneFactor</DisplayName>
  <TechnicalProfiles>
    <TechnicalProfile Id="PhoneFactor-InputOrVerify">
      <DisplayName>PhoneFactor</DisplayName>
      <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.PhoneFactorProtocolProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      <Metadata>
        <Item Key="setting.authenticationMode">phone</Item>
        <Item Key="setting.autodial">true</Item>
      </Metadata>
      ...
    </TechnicalProfile>
  </TechnicalProfiles>
</ClaimsProvider>