简体   繁体   English

获得 webhook 后如何发回数据?

[英]How do you send back data when you get a webhook?

I have a quick question.我有一个快速的问题。 I am new to webhooks and the service I am using requires a response.我是 webhook 的新手,我正在使用的服务需要响应。 I am doing this in php and here are their instructions:我在 php 中执行此操作,这是他们的说明:

We require you to verify the ownership of the server you are making WebHook calls to by adding the following object parameters to your JSON response.我们要求您通过将以下 object 参数添加到您的 JSON 响应来验证您进行 WebHook 调用的服务器的所有权。

{ "details": { "zippy_token":"xxxxxxxxxxxxxxxx" }} {“详细信息”:{“zippy_token”:“xxxxxxxxxxxxxxxx”}}

After adding the JSON response code to your WebHook endpoint, come back here and click the green Add Webhook button.将 JSON 响应代码添加到 WebHook 端点后,返回此处并单击绿色的 Add Webhook 按钮。 Zippykind will verify your WebHook by making a POST call to your WebHook URL with the handshake within the parameters, afterwhich will add the verified WebHook to your active list of WebHooks. Zippykind 将通过使用参数中的握手对您的 WebHook URL 进行 POST 调用来验证您的 WebHook,之后会将经过验证的 WebHook 添加到您的活动 WebHook 列表中。 You only need to do this once, after the WebHook has been verified, you can remove the zippy_token parameter from your JSON response.您只需执行一次,在 WebHook 验证后,您可以从 JSON 响应中删除 zippy_token 参数。

I see how to get the data but how do I send the info needed (the token) back?我知道如何获取数据,但如何将所需的信息(令牌)发回?

This will be done in PHP.这将在 PHP 中完成。

Thanks谢谢

If your site, or what you're developing is located at abc.com , you'd essentially need to create a php script for your webhook callback.如果您的站点或您正在开发的站点位于abc.com ,您基本上需要为您的 webhook 回调创建一个 php 脚本。 abc.com/testwebhook.php . abc.com/testwebhook.php

Inside of the testwebhook.php , you'll output a JSON response with the data formatted as they expect to receive it { "details": { "zippy_token":"xxxxxxxxxxxxxxxx" }}testwebhook.php内部,您将收到 output 一个 JSON 响应,其数据格式为{ "details": { "zippy_token":"xxxxxxxxxxxxxxxx" }}

In case the service you're interacting with (Zippy) is checking the header output of your response, you may need to set the header via PHP within your testwebhook.php script: header('Content-Type: application/json'); In case the service you're interacting with (Zippy) is checking the header output of your response, you may need to set the header via PHP within your testwebhook.php script: header('Content-Type: application/json');

Example - testwebhook.php示例 - testwebhook.php

`<?php 
   $output = '{ "details" : { "zippy_token":"xxxxxxxxxxxxxxxx" }}';
   header('Content-Type: application/json');
   echo $output;
   exit;
 ?>

You'll need to ensure that your json is properly formatted and the endpoint doesn't expect more data returned.您需要确保您的 json 格式正确,并且端点不会期望返回更多数据。

Then the rest is explained ini your initial question.然后在您最初的问题中解释了 rest。 Create the webhook by entering the URL at the Zippy service that gave you those instructions and add the url to the script you setup abc.com/testwebhook.php .通过在为您提供这些说明的 Zippy 服务中输入 URL 来创建 webhook,并将 url 添加到您设置abc.com/testwebhook.php的脚本中。

That should be all you need to do.这应该是你需要做的所有事情。

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

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