我需要在 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/