我正在使用一个基于SendGrid API v3的Webhook。Webhook完全设置了一个SendGrids发布到的端点,但我需要能够接收解析的数据并使用PHP将其存储在数据库中,但我不知道如何做到这一点。
我以前使用过API来启动数据的检索或POST,但当API服务器是POSTing时,我如何捕获通过Webhook端点解析的数据?到目前为止,我有一些简单的方法,但真的不清楚如何解决这个问题:
<?php $json = file_get_contents('https://example.com/webhook.php'); $json_decoded = json_decode($json, true); $var_dump(json_decoded); ?>
我曾尝试向主持人发送多封电子邮件,但每次打这个电话我都会回复 NULL .
NULL
尝试使用中的代码 this example 。这将为您提供要解码的原始HTTP请求正文字节。
<?php $data = file_get_contents("php://input"); $events = json_decode($data, true); foreach ($events as $event) { // Here, you now have each event and can process them how you like process_event($event); } ?>
有关的更多信息 php://input
php://input