Javascript 使用Angularjs和PHP重新捕获缺少的输入响应

Javascript 使用Angularjs和PHP重新捕获缺少的输入响应,javascript,php,angularjs,recaptcha,Javascript,Php,Angularjs,Recaptcha,我在处理recaptcha请求时遇到问题。我正在使用vc Recaptcha服务对Angular JS进行PHP验证。提交表单时,我从reCaptcha对象收到错误“missing-input-Response” 该网站是用AngularJS和PHP构建的,我使用数据工厂使用$http对象向服务器发送请求。我正在实现密码重置功能,我想在重置表单上使用reCaptcha。这就是我遇到麻烦的地方 后端工作正常,这显然是验证码请求的问题。我的reCaptcha API代码在站点的其他地方工作,但没有A

我在处理recaptcha请求时遇到问题。我正在使用vc Recaptcha服务对Angular JS进行PHP验证。提交表单时,我从reCaptcha对象收到错误“missing-input-Response”

该网站是用AngularJS和PHP构建的,我使用数据工厂使用$http对象向服务器发送请求。我正在实现密码重置功能,我想在重置表单上使用reCaptcha。这就是我遇到麻烦的地方

后端工作正常,这显然是验证码请求的问题。我的reCaptcha API代码在站点的其他地方工作,但没有AngularJS实现

我的控制器如下所示:

MySite.controller('passwordResetController', function($rootScope, $scope, $window, $location, $routeParams, Data, vcRecaptchaService) {
    $rootScope.showControls = false;
    $scope.response = null;
    $scope.widgetId = null;
    $scope.form = {email: '', id: '', response: ''};
    $scope.model = {
        key: // MY SITE KEY //
    };
    $scope.setResponse = function (response) {
        console.info('Response available');
        $scope.response = response;
    };
    $scope.setWidgetId = function (widgetId) {
        console.info('Created widget ID: %s', widgetId);
        $scope.widgetId = widgetId;
    };
    $scope.cbExpiration = function() {
        console.info('Captcha expired. Resetting response object');
        vcRecaptchaService.reload($scope.widgetId);
        $scope.response = null;
     };
    $scope.sendReset = function(form) {
        var valid;
        $scope.form.response = $scope.response;
        console.log($scope.form.response);
        Data.post('/sendreset', {form:form})
        .then(function(results) {
            console.log(results);
            if (results.status === 'success') {
                valid = true;
            } else {
                valid = false;
            }
            Data.toast(results);
        });
        console.log('sending the captcha response to the server', $scope.response);
        if (valid) {
            console.log('Success');
            Data.post('/createRequest', {
                form: form
            }).then(function(results) {
                if (results.status === 'success') {
                    $scope.sendMail(form);
                }
            });
        } else {
            console.log('Failed validation');
            vcRecaptchaService.reload($scope.widgetId);
        }
    }
    $scope.sendMail = function(form) {
        Data.post('/sendPasswordReset', {
            form: form
        }).then(function(results) {
            Data.toast(results);
            if (results.status === 'success') {
                $location.path('login');
            }
        });
    }
});
我的PHP验证是:

$app->post('/sendreset', function() use ($app) {
    $r = json_decode($app->request->getBody());
    $post = [
        'secret' => //== MY SECRET KEY ==//,
        'response' => $r->form->response
    ];
    $ch = curl_init('https://www.google.com/recaptcha/api/siteverify');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    $response = curl_exec($ch);
    curl_close($ch);
    var_dump($response);
    $response = json_decode($response, true);
    // check result
    if (isset($response['success']) && $response['success'] == true) {
        $response['status'] = 'success';
        echoResponse(200, $response);
    } else {
        $response['status'] = 'error';
        $response['message'] = 'Captcha test failed';
        echoResponse(201, $response);
    }
});
数据功能都正常工作。
非常感谢您的帮助。

服务器的响应是字符串而不是数组。我将控制器更改为在字符串中搜索“true”,现在可以正常工作了