繁体   English   中英

从 url 解码中获取属性 (PHP)

[英]Fetch attributes from url decode (PHP)

这是我用来获取数据的代码:

<?php

header('Content-Type: text/html; charset=UTF-8');
$request = file_get_contents('php://input');
//$req_dump = print_r( $request, true );
$fp = file_put_contents( 'request.log', urldecode(json_encode($request)));

?>

output:

domain_prefix = test & payload = {
    "attributed_cost": "0.00",
    "count": 50,
    "id": "da674e25-5d9c-a8e2-1d5e-aa018b6cc1c3",
    "outlet": {
        "id": "3faf0608-91fa-11e3-a0f5-b8ca3a64f8f4",
        "name": "West End Shop",
        "tax_id": "e52b2846-e920-11e5-f98b-29c175501027",
        "time_zone": "Australia/Brisbane"
    },
    "outlet_id": "3faf0608-91fa-11e3-a0f5-b8ca3a64f8f4",
    "product": {
        "active": true,
        "attributed_cost": null,
        "base_name": "Test Productss",
        "button_order": null,
        "categories": [],
        "deleted_at": null,
        "description": "",
        "handle": "testproducts",
        "id": "bfe919c4-6357-46c9-a333-d1db636446c5",
        "name": "Test Productss",
        "sku": "10203",
        "source": "USER",
        "source_id": null,
        "source_variant_id": null,
        "supply_price": "0.00",
        "taxes": [{
            "outlet_id": "3faf0608-91fa-11e3-a0f5-b8ca3a64f8f4",
            "tax_id": "e52b2846-e920-11e5-f98b-29c175501027"
        }],
        "variant_options": [],
        "variant_parent_id": null
    },
    "product_id": "bfe919c4-6357-46c9-a333-d1db636446c5",
    "reorder_point": "0",
    "restock_level": "0",
    "version": 16073287694
} & retailer_id = 3 fa8309c - 91 fa - 11e3 - a0f5 - b8ca3a64f8f4 & type = inventory.update

我不确定如何从中获取“count”和“id”和“product_id”属性值。 我试过parse_str但没有用。 让我知道您对此的想法,如何从中获取数据? 谢谢

如果你的 $request 是这样的 output 那么你可以试试 你可以试试

parse_str($request, $parse_request);
$payload = json_decode($parse_request["payload"], true);

$id =  $payload["id"];
$count =  $payload["count"];
$product_id =  $payload["product"]["id"];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM