wordpress - 如何在 WordPress 中为 clickfunnels 创建自定义 Webhook

标签 wordpress webhooks

我需要在 WordPress 中创建自定义端点以使用 Clickfunnels 中的 Webhook。

Clickfunnels 文档对此并不清楚。根据 clickfunnels 文档,我必须在端点中添加:

  • 中创建测试端点

并且您必须包含以下 header 。

  • 内容类型为 application/json
  • X-Clickfunnels-Webhook-Delivery-Id 作为网址和负载的 MD5。
  • 有效负载(HTTP 消息正文)应为带有“时间”的 JSON 对象 键和 UTC 中的当前时间值,如下所示: { "time": “YYYYY-MM-DD HH: MM: SS UTC”}

实际上这是我的代码,我已经成功创建了端点,但不幸的是 Clickfunnels 无法识别它。我认为问题可能出在我添加的标题中......

add_action( 'rest_api_init', function () {
    register_rest_route( 'funnel-webhooks', '/test',
        array(
            'methods' => 'GET', 
            'callback' => 'ffalcon_funnel_webhooks'
        )
    );
});
function ffalcon_funnel_webhooks(){

    // Set the arguments based on our get parameters
    $today = gmdate('Y-m-d H:i:s e');
    $data = array();
    $data['time'] = $today;
  $Clickfunnels_Webhook_Delivery_Id = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . $today;

    $response = new WP_REST_Response(json_encode($data), 200);
  $response->header( 'X-Clickfunnels-Webhook-Delivery-Id', md5($Clickfunnels_Webhook_Delivery_Id) ); 
  $response->set_data(json_encode($data));
  return $response;
    
}

这是我的自定义端点的 URL:https://test.umanyx.com/wp-json/funnel-webhooks/test

是否有人有在 WordPress 中创建自定义端点以与 Clickfunnels Webhooks 配合使用的经验。

有什么想法吗?

谢谢

最佳答案

终于,我能够修复它了。我留下了对我有用的代码,以防它对任何人有帮助。

add_action( 'rest_api_init', function () {
    register_rest_route( 'funnel-webhooks', '/test',
        array(
            'methods' => 'POST', 
            'callback' => 'ffalcon_funnel_webhooks_test'
        )
    );
    register_rest_route( 'funnel-webhooks', '/real',
        array(
            'methods' => 'POST', 
            'callback' => 'ffalcon_funnel_webhooks_real'
        )
    );
});
function ffalcon_funnel_webhooks_test(){

    $today = gmdate('Y-m-d H:i:s e');
    $data = array();
    $data['time'] = $today;
    $Clickfunnels_Webhook_Delivery_Id = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . $today;

    $response = new WP_REST_Response(json_encode($data), 200);
    $response->header( 'X-Clickfunnels-Webhook-Delivery-Id', md5($Clickfunnels_Webhook_Delivery_Id) ); 
  
  return $response;
    
}

关于wordpress - 如何在 WordPress 中为 clickfunnels 创建自定义 Webhook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69130942/

相关文章:

html - WordPress无法将文件写入磁盘

PHP - 响应传入的 API 调用而不返回

javascript - 从 Typeforms webhook 解析原始正文时出现问题

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

ruby-on-rails - 在 Rails 中使用 Stripe webhook

php - 使用 HTTPS 时缺少 CSS、JS 和图像链接

wordpress - 子目录中不同的lighttpd重写规则

mysql - 建立数据库连接时出错 - WordPress 和 mysql

gitlab - Hook 执行成功但返回 HTTP 500 Missing_text_or_fallback_or_attachments

html - 表格在移动设备上的兼容性问题