我正在我的网站中实现 gocardless api。我被困在 webhook 中。当我从沙盒测试环境向我的网站发送一个 webhook 时,它显示 200 响应,但之后没有执行任何代码。而且我没有在响应正文中看到任何内容,它显示为空。
我为此使用 laravel 5.7。这是我的代码
route.php Route::post('/webhook', 'HomeController@webhook');
家庭控制器.php
public function webhook()
{
$webhook_endpoint_secret = env("GOCARDLESS_WEBHOOK_ENDPOINT_SECRET");
$request_body = file_get_contents('php://input');
$headers = getallheaders();
$signature_header = $headers["Webhook-Signature"];
try {
$events = Webhook::parse($request_body, $signature_header, $webhook_endpoint_secret);
foreach ($events as $event) {
print("Processing event " . $event->id . "\n");
switch ($event->resource_type) {
case "mandates":
$this->process_mandate_event($event);
break;
default:
print("Don't know how to process an event with resource_type " . $event->resource_type . "\n");
break;
}
}
header("HTTP/1.1 204 OK");
} catch(InvalidSignatureException $e) {
header("HTTP/1.1 498 Invalid Token");
}
}
public function process_mandate_event($event)
{
switch ($event->action) {
case "cancelled":
print("Mandate " . $event->links["mandate"] . " has been cancelled!\n");
break;
default:
print("Don't know how to process a mandate " . $event->action . " event\n");
break;
}
}
我试图执行一些数据库查询,但没有任何工作。谁能指出我做错了什么以及在哪里做错了?