POST:laravel中Messenger Bot的500内部服务器错误

问题描述 投票:0回答:1

亲爱的,

[我通过Ngrok URL为我的Facebook页面设置了Webhok,并应用了Messenger平台的所有要求,但是当我将消息发送到我的Facebook页面时,遇到以下错误:

POST /Facebook_Messenger_Token 500 Internal Server Error 

并且在Laravel的routs文件中,我使用Get和Post函数,如下所示:

Route::get('Facebook_Messenger_Token', 'MessengerController@index');
Route::post('Facebook_Messenger_Token', 'MessengerController@index');

当我发送消息时,在storage / app.logs / laravel中出现以下错误:

[2020-06-08 18:44:21] local.ERROR: Undefined variable: id {"exception":"[object] (ErrorException(code: 0): Undefined variable: id at C:\\xampp\\htdocs\\AzadApp\\app\\Http\\Controllers\\MessengerController.php:17)
[stacktrace]

我的公共职能指数:

public function index()
    {
        // here we can verify the webhook.
        // i create a method for that.
        $this->verifyAccess();

        $user    = json_decode($this->getUser($id)); --this is line 17
        $input   = json_decode(file_get_contents('php://input'), true);
        $id      = $input['entry'][0]['messaging'][0]['sender']['id'];
        $message = $input['entry'][0]['messaging'][0]['message']['text'];

        $response = [
            'recipient'     =>  ['id'   => $id ],
            'message'       =>  ['text' => "Thanks for watching {$user->first_name} {$user->last_name}! :)"]
        ];

        $this->sendMessage($response);
    }

请支持并表示感谢。

laravel xampp ngrok
1个回答
0
投票
$ id是在第19行(即在第17行之后)定义的。为了在上使用它

$user = json_decode($this->getUser($id));

您应将上述行放在第19行之后

$id = $input['entry'][0]['messaging'][0]['sender']['id'];

不要向上移动第19行(如我在评论中所说),而是向下移动第17行,因为

$id = $input['entry'][0]['messaging'][0]['sender']['id'];

正在使用之前定义的$ input。

您要做的就是将第17行移到第19行下。

© www.soinside.com 2019 - 2024. All rights reserved.