doujiyuan0211 2016-06-13 06:54
浏览 53

Google reCAPTCHA返回错误的json响应

I have a form which has Google's reCAPTCHA. But I am having trouble with the json format returned by it: In the documentation,

https://developers.google.com/recaptcha/docs/verify#api-request :

{
 "success": true|false,
 "challenge_ts": timestamp,  // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
 "hostname": string,         // the hostname of the site where the reCAPTCHA was solved
 "error-codes": [...]        // optional
}

But I am getting this response:

{
 "success": true,
 "challenge_ts": "2016-06-13T06:46:40Z",
 "hostname": "devs.mysite.com.au"
} {"success":false,"errors":[null]}'

Resulting some error . My code is:

$is_valid = $_POST['g-recaptcha-response'];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$fields = array(
    'secret' => 'mysecretcode',
    'response' => $is_valid,
    'remoteip', ''
);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
  • 写回答

1条回答 默认 最新

  • duanmaduan1848 2016-06-13 07:34
    关注

    The json output from the Google API is as expected. I am not too versed in json, though I expect the [...] for the error-codes argument specifies that it contain anything:

     "error-codes": [...]
    

    What it returns is a json object (that is what the curly braces mean, see the json specification). In fact, it returns an object with two properties: success and errors:

    {"success":false,"errors":[null]}'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?