reCaptcha:错误代码 "invalid-keys"

reCaptcha: error code "invalid-keys"

我目前正在为具有 HTML 和 PHP 的表单实施 reCaptcha。客户端解决方案没有任何问题。但是服务器端验证失败。

这是我的服务器端代码:

$data = array(
    "secret" => "MY_SECRET_KEY",
    "response" => $captcha_response,
    "remoteip" => $_SERVER['REMOTE_ADDR']
);
$opts = [
    "http" => [
        "method" => "POST",
        "header" => "Accept-language: en",
        "content" => http_build_query($data)
    ]
];

$context = stream_context_create($opts);

$data = json_decode(file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context), true);

所以现在当我转储结果时,我得到以下输出:

array(4) {
  ["success"]=>
  bool(false)
  ["challenge_ts"]=>
  string(20) "2017-06-22T13:14:50Z"
  ["hostname"]=>
  string(9) "localhost"
  ["error-codes"]=>
  array(1) {
    [0]=>
    string(12) "invalid-keys"
  }
}

我确定响应代码将完全发送到 PHP 脚本。

我也在 API 文档中进行了搜索,但只找到这些 error codes 并且没有与 invalid-keys.

匹配的内容

我做错了什么?

太蠢了。我从 admin console 错误的项目 中获取了密钥。错误的项目未列入白名单 localhost,这是我需要的。 public-site-key 和 secret-key 也不匹配(但都有效)。

我可以确认,错误代码 invalid-keys 仅当使用现有但不正确的帐户或项目密钥时 returns。

如果密钥无效或格式错误,将返回错误代码 invalid-input-secret

在我们的例子中,我们的 Wordpress 生产环境有一个插件,它定义了一个常量,我们正在使用来自不同帐户的不正确的密钥。