Laravel 4 来自shopify和laravel 4的Webhook

Laravel 4 来自shopify和laravel 4的Webhook,laravel-4,shopify,Laravel 4,Shopify,使用laravel在订单创建时为shopify创建webhook 我在网站的webhook中指定我的url 我使用postcatcher从webhook调用接收数据,以便知道它们传递的是什么数据 数据看起来像这样 { "customer": { "default_address": { "default": true, "country_name"

使用laravel在订单创建时为shopify创建webhook

我在网站的webhook中指定我的url

我使用postcatcher从webhook调用接收数据,以便知道它们传递的是什么数据

数据看起来像这样

{
    "customer": {
        "default_address": {
            "default": true,
            "country_name": "Singapore",
            "country_code": "SG",
            "province_code": null,
            "name": "Own Card",
            "zip": "234567",
            "province": "Singapore",
            "phone": "",
            "last_name": "Card",
            "id": 275454813,
            "first_name": "Own",
            "country": "Singapore",
            "company": "",
            "city": "Singapore",
            "address2": "",
            "address1": ""
        },
        "last_order_name": null,
        "tags": "",
        "verified_email": true,
        "updated_at": "2014-03-14T06:10:59-04:00",
        "total_spent": "0.00",
        "state": "disabled",
        "orders_count": 0,
        "note": null,
        "multipass_identifier": null,
        "last_order_id": null,
        "last_name": "Koh",
        "id": 219085425,
        "first_name": "Kwang",
        "email": "Kwang@a.com.sg",
        "created_at": "2014-03-14T05:55:55-04:00",
        "accepts_marketing": true
    },
    "client_details": {
        "user_agent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36",
        "session_hash": "c30217b1565a1f69ca5c1cb944ee6769c39de0f9acc8d6685975d551a2ff246f",
        "browser_ip": "118.200.236.161",
        "accept_language": "en-GB,en-US;q=0.8,en;q=0.6"
    },
    "fulfillments": [],
    "shipping_address": {
        "province_code": null,
        "country_code": "SG",
        "name": "Own Card",
        "zip": "123456",
        "province": "Singapore",
        "phone": "12345676",
        "longitude": "1.151376",
        "latitude": "1.2646",
        "last_name": "Card",
        "first_name": "Own",
        "country": "Singapore",
        "company": "",
        "city": "Singapore",
        "address2": "",
        "address1": ""
    },
    "billing_address": {
        "province_code": null,
        "country_code": "SG",
        "name": "Own Card",
        "zip": "312133",
        "province": "Singapore",
        "phone": "",
        "longitude": "103.351376",
        "latitude": "1.33146",
        "last_name": "Card",
        "first_name": "Own",
        "country": "Singapore",
        "company": "",
        "city": "Singapore",
        "address2": "",
        "address1": ""
    },
    "payment_details": {
        "credit_card_company": "Bogus",
        "credit_card_number": "XXXX-XXXX-XXXX-1",
        "cvv_result_code": null,
        "credit_card_bin": "1",
        "avs_result_code": null
    },
    "shipping_lines": [
        {
            "tax_lines": [],
            "title": "Standard Shipping",
            "source": "shopify",
            "price": "10.00",
            "code": "Standard Shipping"
        }
    ],
    "line_items": [
        {
            "tax_lines": [],
            "product_exists": true,
            "properties": [],
            "variant_inventory_management": null,
            "name": "test",
            "vendor": "Kwang",
            "variant_title": "",
            "variant_id": 315650553,
            "title": "test",
            "taxable": true,
            "sku": "1",
            "requires_shipping": true,
            "quantity": 1,
            "product_id": 265080025,
            "price": "12.00",
            "id": 432417197,
            "grams": 0,
            "fulfillment_status": null,
            "fulfillment_service": "manual"
        }
    ],
    "tags": "",
    "tax_lines": [],
    "checkout_id": 221740105,
    "processing_method": "direct",
    "note_attributes": [],
    "discount_codes": [],
    "order_number": 1003,
    "landing_site_ref": null,
    "browser_ip": "118.200.236.122",
    "user_id": null,
    "updated_at": "2014-03-14T06:10:59-04:00",
    "total_weight": 0,
    "total_tax": "0.00",
    "total_price_usd": "17.37",
    "total_price": "22.00",
    "total_line_items_price": "12.00",
    "total_discounts": "0.00",
    "token": "3c71c6a830eee3b7cb0c8627e4d48e03",
    "test": true,
    "taxes_included": false,
    "subtotal_price": "12.00",
    "source_url": null,
    "source_name": "web",
    "source_identifier": null,
    "source": "browser",
    "referring_site": "",
    "reference": null,
    "number": 3,
    "note": null,
    "name": "#1003",
    "location_id": null,
    "landing_site": "/products/test",
    "id": 244075413,
    "gateway": "bogus",
    "fulfillment_status": null,
    "financial_status": "authorized",
    "email": "kwank@a.com.sg",
    "currency": "SGD",
    "created_at": "2014-03-14T06:10:58-04:00",
    "confirmed": true,
    "closed_at": null,
    "checkout_token": "95dc1ed9b867df5b1ecdf770de4eba3b",
    "cart_token": "ab1795435caebccb6d96ee69f716a4c9",
    "cancelled_at": null,
    "cancel_reason": null,
    "buyer_accepts_marketing": true
}
我实际上如何从我的php laravel函数访问它?我做了类似的事情,但当用邮递员把这个寄过来时,我没有从c美元那里得到任何东西

    $inputs = Input::all();
    $c = $inputs ['customer'];

有人可以帮忙吗?

看起来您正在以json正文的形式传递数据。您展示的代码本可以工作,但让我们试试这个

首先,请执行以下操作:

$inputs = Input::all();
$c = $inputs->customer;
现在让我们试试:

$inputs = Input::json()->all();
$c = $inputs->customer;
$c = Input::get('customer');
$cd = Input::get('customer.default_address');
它还回什么吗

最后,让我们试试:

$inputs = Input::json()->all();
$c = $inputs->customer;
$c = Input::get('customer');
$cd = Input::get('customer.default_address');
根据文件:

一些JavaScript库(如主干)可能会将输入作为JSON发送到应用程序。您可以像正常情况一样通过Input::get访问此数据


在postman上,您必须将该请求作为json正文发布

选择
raw
选项卡,然后将
text
更改为
json…
并将整个请求复制粘贴到文本区域


因此,您要查找的实际查询是:

$customer = Input::get('customer'); 
现在,您在$inputs中拥有了客户内部的所有内容

访问它的方式如下:

$default_address = $customer->default_address;  // returns object
$state = $customer->state; // returns string
您甚至可以将其环绕:

if (Request::isJson())
{
    // make sure it is from a json body
}

更新

试试这个:

$inputs = Input::all();
dd($inputs); // what does this return?

这些数据看起来像是作为json正文传递的?我将json正文复制并粘贴在邮递员、选定的pos中,并在raw下选择json并复制。我点击了send,选择了3种不同的格式。它给了我一个错误例外,试图获取非objectmy$inputs数组的属性实际上是空的。我是不是访问错误了?我发送的数据就是我上面粘贴的数据。当我使用postman时,是否需要添加标题和内容?因此dd上的输入是空的?如果选择json,请尝试将
Input::all()
替换为
Input::json->all()
@edelweiss no。然后邮递员会自动为您设置邮件头。