Facebook Messenger Webhook无法验证

时间:2018-08-07 12:29:35

标签: facebook get httprequest facebook-messenger-bot

我正在测试facebook Messenger Webhook, 注册我已经设置了必要的参数 这是我的PHP代码,

代码:

$postData = request()->all();

        // Your verify token. Should be a random string.
        $verfityTocken = "fR8Eu5Wj9m9WTLvA0vIZYMenoTvu51bdGaL70FFb9pHhSeySbLHa0Q5cTLaJ";

        // Parse the query params
        $mode = $postData['hub_mode'];
        $token = $postData['hub_verify_token'];
        $challenge = $postData['hub_challenge'];

        // Checks if a token and mode is in the query string of the request
        if ($mode && $token) {

            // Checks the mode and token sent is correct
            if ($mode === 'subscribe' && $token === $verfityTocken) {

                // Responds with the challenge token from the request
                //echo 'WEBHOOK_VERIFIED';

                return response(request()->input("hub_challenge"), 200);

            } else {
                // Responds with '403 Forbidden' if verify tokens do not match
                return response('403 Forbidden', 403);
            }
        }

现在在从messanger面板验证webhook时,出现如图所示的错误

enter image description here

我不明白为什么收到了尾随数据\u0033Clink

1 个答案:

答案 0 :(得分:1)

对于仍在尝试解决此问题的任何人,您都需要以纯文本格式返回hub_challenge数字。

我是这样用红宝石做的:

def accept_request

    render plain: params['hub.challenge']
end