php - PHP Webhook 请求
问题描述
我正在运行一个带有 WooCommerce 结帐功能的 WordPress 网站。在结帐页面,我使用 webhook woocommerce_thankyou作为我的代码的登机点。此时,我正在从新订单中选择一些数据,以通过 webhook 将数据发送到另一个网站。我通过自定义 WordPress 插件集成了代码。目前,webhook 向我返回了以下错误:“DigiMember - Webhook Checkout (#1): the E-Mail-Adress will not send as GET- or POST-Parameter.”
可能是什么问题呢?
<?php
function test ($order_id) {
?>
<span>
woocommerce_thankyou
<?php echo $order_id;
$order=wc_get_order($order_id);
echo $order->get_meta('digi_first_name');
echo $order->get_meta('digi_last_name');
echo $order->get_meta('digi_email');
?>
</span>
<?php
//The url you wish to send the POST request to
$url = 'https://traumjob-campus.de/member?dm_webhook=1_DCqtx6Xre1oM7tuKyon5rVzAIUWvVVXofMqTRQjE9JVDgf7gLI3M198bIeD5';
//The data you want to send via POST
$fields = [
'digi_first_name' => 'user',
'digi_last_name' => 'test',
'digi_email' => 'test@user.de'
];
//url-ify the data for the POST
$fields_string = http_build_query($fields);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
echo $result;
?>
解决方案
推荐阅读
- javascript - 类 Object 不是构造函数
- r - 计算 group_by 中行之间的差异分数
- php - 在 HTML PHP 中打印大量页面时出错
- talend - 使用 tFileInputDelimited 从 CSV 读取 int 值时出错错误:对于输入字符串:“10617,,,,”
- python - Python 3.7.2 Turtle 源文件夹特定的错误消息
- python - 如何使用pickle保存sklearn模型
- ninject - 什么是 NInjects 相当于 TryAdd
- java - JNA 中的 RasEnumConnections 函数返回不完整的数据。我做错了什么?
- javascript - HTML/CSS/JS - 模式弹出窗口的覆盖背景 - 问题
- java - 循环数组队列中余数操作数的意义是什么