【问题标题】:Symfony: Webhook End Point ProblemsSymfony:Webhook 端点问题
【发布时间】:2021-08-06 03:28:15
【问题描述】:

我在使用 Webhook 端点时遇到问题。

#[Route("/web_hook", name: 'web_hook')]
    public function webhook(Request $request)
    {
        
        $data = json_decode($request->getContent(), true);
        if ($data === null){
            throw new \Exception('bad bad');
        }

        $txt = 'samle of some text text text';
        $myfile = fopen("test.txt", "w") or die("Unable to open file!");
        fwrite($myfile, $txt);
        fwrite($myfile, $data->id);
        fclose($myfile);
        
        $response = new Response();
        $response->setStatusCode(200);
        return $response;
    }

我有 0 运气让它工作,我通过邮递员向它发送一个 POST 请求,它不断返回错误 500。

当我访问 URL 时,它给了我这个错误

“无法自动装配“App\Controller\WebHookController::webhook()”的参数 $request:它引用了类“Symfony\Component\HTTPFoundation\Request”,但不存在这样的服务。 "

我基于此方法

https://symfonycasts.com/screencast/stripe-level2/webhook-endpoint-setup.

任何关于我做错了什么的想法将不胜感激。

【问题讨论】:

    标签: symfony webhooks endpoint


    【解决方案1】:

    如果您收到这样的错误消息

    Cannot autowire argument $request of
    "App\Controller\WebHookController::webhook()": it references class
    "Symfony\Component\HTTPFoundation\Request" but no such service exists.
    

    表示此服务不可用。请先尝试安装 http-foundation 组件。

    composer require symfony/http-foundation
    

    并尝试将use Symfony\Component\HTTPFoundation\Request 更改为use Symfony\Component\HttpFoundation\Request

    【讨论】:

    • 无法解析“App\Controller\WebHookController::webhook()”的参数 $request:无法确定“App\Controller\WebHookController::webhook()”的控制器参数:$request 参数是使用不存在的类或接口进行类型提示:“Symfony\Component\HTTPFoundation\Request”。就是它现在所说的......奇怪我以为我安装了 http-foundations
    • 好像Symfony\Component\HTTPFoundation\Request 不是有效的位置。尝试更改为Symfony\Component\HttpFoundation\Request。在命名空间下方的控制器文件中,类部分上方
    猜你喜欢
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 2012-05-16
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多