繁体   English   中英

如何从Webhook获取数据以存储在数据库中?

[英]How do I get data from Webhook to store in a database?

我正在使用基于SendGrid API v3的Webhook。 Webhook已完全设置为SendGrid发布到的端点,但是我需要能够接收该解析的数据并将其存储在使用PHP的数据库中,但不知道该怎么做。

在启动数据检索或POST之前,我已经使用过API,但是当API服务器是一个POST时,如何捕获通过Webhook端点解析的数据? 到目前为止,我有一些简单的方法,但是还不清楚如何解决这个问题:

<?php

$json = file_get_contents('https://example.com/webhook.php');
$json_decoded = json_decode($json, true);
$var_dump(json_decoded);

?>

我曾尝试向主机发送多封电子邮件,但是每次进行此调用时,我都会返回NULL

尝试使用此示例中的代码。 这将为您提供要解码的原始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更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM