gpt4 book ai didi

php - 如何创建 Webhook?

转载 作者:可可西里 更新时间:2023-11-01 13:12:58 27 4
gpt4 key购买 nike

因此,我正在使用 Tropo 和 Nexmo 创建一个 click2call 应用程序,此时,我需要设置网络钩子(Hook)方面的帮助。它们都提供了一个指向 webhook 的位置,但现在,我不明白该在其中包含什么。它是一个php文件吗?还是一个 json?我已经尝试创建一个 php 并具有以下内容:

<?php
header('Content-Type: application/json');
ob_start();
$json = file_get_contents('php://input');
$request = json_decode($json, true);
$action = $request["result"]["action"];
$parameters = $request["result"]["parameters"];
$output["contextOut"] = array(array("name" => "$next-context", "parameters" =>
array("param1" => $param1value, "param2" => $param2value)));
$output["speech"] = $outputtext;
$output["displayText"] = $outputtext;
$output["source"] = "whatever.php";
ob_end_clean();
echo json_encode($output);
?>

我以后如何从我的 webhook 检索信息并将其存储在数据库中?我看过一些代码,但我不知道在哪里包含它......它在我的 api 中,在我的 webhook 指向的 php 文件中吗?提前谢谢你。

最佳答案

所以我想出了一个非常简单的方法。只需使用以下代码将您的 webhook 指向 php:

<?php
// Original Answer
header('Content-Type: application/json');
$request = file_get_contents('php://input');
$req_dump = print_r( $request, true );
$fp = file_put_contents( 'request.log', $req_dump );

// Updated Answer
if($json = json_decode(file_get_contents("php://input"), true)){
$data = $json;
}
print_r($data);
?>

信息将被发布,然后可以通过“request.log”访问

希望以后能对其他人有所帮助。

关于php - 如何创建 Webhook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45835797/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com