【发布时间】: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.
任何关于我做错了什么的想法将不胜感激。
【问题讨论】: