首页 > 解决方案 > 如何确认在 Coldfusion 中接收到 Webhook POST

问题描述

首先要明确一点,我不是专业人士 - 只是想完成一项任务,我的专业知识很少。我认为很容易的事情显然并非如此。我处理过 API 和 XML,但它一直是我发起的。这显然是不同的。

目标:

从我的 Wordpress/Woocommerce 网站接收 HTTP POST Webhook 数据 (JSON)。

问题:

Webhook 正在工作并且被 RequestBin 完美接收。JSON 字符串正在通过 HTTP 发送。但我什至不确定我的 CF 模板是否听到了该请求。当我尝试将接收到的数据写入会话变量以便我至少可以看到它时,什么都没有?!?!如何确定我的代码是否被触发?

我的 CF 模板中的第一行代码:

<cfset HTTPRequestData = deserializeJSON(ToString(getHTTPRequestData().content))>

RequestBin 中发送数据的示例:

{
    "id": 259609,
    "parent_id": 0,
    "number": "CW-104-270219",
    "order_key": "xxxxxxxxxxxx",
    "created_via": "checkout",
    "version": "3.5.5",
    "status": "completed",
    "currency": "USD",
    "date_created": "2019-02-27T15:11:58",
    "date_created_gmt": "2019-02-27T20:11:58",
    "date_modified": "2019-02-27T15:11:59",
    "date_modified_gmt": "2019-02-27T20:11:59",
    "discount_total": "0.00",
    "discount_tax": "0.00",
    "shipping_total": "0.00",
    "shipping_tax": "0.00",
    "cart_tax": "0.00",
    "total": "9.68",
    "total_tax": "0.00",
    "prices_include_tax": false,
    "customer_id": 2,
    "customer_ip_address": "xxxxxxxxxxxx",
    "customer_user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36",
    "customer_note": "",
    "billing": {
        "first_name": "Valerie",
        "last_name": "Criswell",
        "company": "",
        "address_1": "",
        "address_2": "",
        "city": "",
        "state": "",
        "postcode": "",
        "country": "",
        "email": "xxxxxxxxxx",
        "phone": ""
    },
    "shipping": {
        "first_name": "",
        "last_name": "",
        "company": "",
        "address_1": "",
        "address_2": "",
        "city": "",
        "state": "",
        "postcode": "",
        "country": ""
    },
    "payment_method": "authorize_net_aim",
    "payment_method_title": "Credit Card",
    "transaction_id": "xxxxxxxxxxxxx",
    "date_paid": "2019-02-27T15:11:59",
    "date_paid_gmt": "2019-02-27T20:11:59",
    "date_completed": "2019-02-27T15:11:59",
    "date_completed_gmt": "2019-02-27T20:11:59",
    "cart_hash": "xxxxxxxxxxxxx",
    "meta_data": [
        {
            "id": 8785641,
            "key": "_wcson_order_number",
            "value": "CWD-259609-022719-108"
        },
        {
            "id": 8785642,
            "key": "_order_number",
            "value": "104"
        },
        {
            "id": 8785643,
            "key": "_order_number_formatted",
            "value": "CW-104-270219"
        },
        {
            "id": 8785644,
            "key": "_order_number_meta",
            "value": {
                "prefix": "CW-",
                "suffix": "-{DD}{MM}{YY}",
                "length": "2"
            }
        },
        {
            "id": 8785645,
            "key": "_wc_authorize_net_aim_retry_count",
            "value": "0"
        },
        {
            "id": 8785646,
            "key": "_wc_authorize_net_aim_trans_id",
            "value": "xxxxxxxx"
        },
        {
            "id": 8785647,
            "key": "_wc_authorize_net_aim_trans_date",
            "value": "2019-02-27 15:11:59"
        },
        {
            "id": 8785648,
            "key": "_wc_authorize_net_aim_environment",
            "value": "production"
        },
        {
            "id": 8785649,
            "key": "_wc_authorize_net_aim_account_four",
            "value": "xxxxxxxx"
        },
        {
            "id": 8785650,
            "key": "_wc_authorize_net_aim_authorization_amount",
            "value": "xxxxxxx"
        },
        {
            "id": 8785651,
            "key": "_wc_authorize_net_aim_authorization_code",
            "value": "xxxxxxx"
        },
        {
            "id": 8785652,
            "key": "_wc_authorize_net_aim_charge_captured",
            "value": "yes"
        },
        {
            "id": 8785653,
            "key": "_wc_authorize_net_aim_card_expiry_date",
            "value": "21-08"
        },
        {
            "id": 8785654,
            "key": "_wc_authorize_net_aim_card_type",
            "value": "mastercard"
        },
        {
            "id": 8785659,
            "key": "_pip_invoice_number",
            "value": "CW-104-270219"
        },
        {
            "id": 8785660,
            "key": "_wc_pip_invoice_email_count",
            "value": "1"
        },
        {
            "id": 8785661,
            "key": "_wc_pip_packing_list_email_count",
            "value": "1"
        }
    ],
    "line_items": [
        {
            "id": 17,
            "name": "I Give Myself Away -   MP3 Download - 30 Day Access",
            "product_id": 192127,
            "variation_id": 192128,
            "quantity": 1,
            "tax_class": "",
            "subtotal": "9.68",
            "subtotal_tax": "0.00",
            "total": "9.68",
            "total_tax": "0.00",
            "taxes": [],
            "meta_data": [
                {
                    "id": 182,
                    "key": "pa_format",
                    "value": "download-30-day"
                }
            ],
            "sku": "131599-DL30DAY",
            "price": 9.68
        }
    ],
    "tax_lines": [],
    "shipping_lines": [],
    "fee_lines": [],
    "coupon_lines": [],
    "refunds": []
}

标签: jsoncoldfusionwebhookscoldfusion-10

解决方案


让我们从既定目标开始:

从我的 Wordpress/Woocommerce 网站接收 HTTP POST Webhook 数据。

您的 Wordpress 站点能否在您的 ColdFusion 站点上访问预期的 URL?如果是这样,您可以将 HTTP POST 请求记录/转储到文件中吗?

<cfdump var="#form#" format="html" output="/full/path/to/file">

这将告诉您是否正确接收请求。


推荐阅读