2016-05-30 116 views
0

我想验证使用requestify的recaptcha。这就是文档说,有关API:使用requestify验证google recaptcha?

API Request 

URL: https://www.google.com/recaptcha/api/siteverify 

METHOD: POST 

POST  Parameter Description 
secret Required. The shared key between your site and ReCAPTCHA. 
response Required. The user response token provided by the reCAPTCHA to the user and provided to your site on. 
remoteip Optional. The user's IP address. 

这是我的要求

我得到的回应是

{ 
    "success": false, 
    "error-codes": [ 
    "missing-input-response", 
    "missing-input-secret" 
    ] 
} 

我想我可能被张贴在参数错误的方式或者我误解了api文档。

+0

我希望你的秘密不是真正的私钥。哪些应该保持“私人” – Martial

+0

这只是一个开发秘密,但谢谢! – Himmators

回答

0

我使用“请求”,但它应该以同样的方式工作。

var request = require('request'); 

var data = { 
    remoteip: req.connection.remoteAddress, // @IP of the user 
    response: req.body["g-recaptcha-response"], 
    secret: RECAPTCHA_PRIVATE_KEY 
}; 

request.post({ 
    'url': RECAPTCHA_URL, 
    form: data, 
    'proxy': HTTP_PROXY // (optional) I'm behind a proxy 
}, function (error, response, body) { 
    if (!error && response.statusCode == 200) { 
    var b = JSON.parse(body); 
    if (b.success === true) { 
     // ... your code here 
    } else // ... 
    } else // .... 

});