如何从给定的数据中获取有效载荷?

时间:2018-07-09 05:22:19

标签: php json laravel php-7 urlencode

我无法从此数据中获取有效载荷,请帮助我。这是代码

  

domain_prefix = leaderdots&environment = prod&payload = {“ created_at”:“ 2018-07-09 05:10:17”,“ customer”:{“ balance”:“ 0.00000”,“ company_name”:null,“ contact_first_name”: null,“ contact_last_name”:null,“ created_at”:“ 2018-07-05   10:27:47“,” custom_field_1“:null,” custom_field_2“:null,” custom_field_3“:null,” custom_field_4“:null,” customer_code“:” WALKIN“,” customer_group_id“:” 0adfd74a-1555-11e8- fa42-803e0f84ff30“,” date_of_birth“:null,” deleted_at“:null,” do_not_email“:false,” email“:null,” enable_loyalty“:false,” fax“:null,” first_name“:null,” id“ :“ 0adfd74a-1555-11e8-fa42-803e0f85287c”,“姓氏”:null,“忠诚度余额”:“ 0.00000”,“ mobile”:null,“ note”:null,“ phone”:null,“ points”:0 ,“性别”:空,“ updated_at”:“ 2018-07-06   12:59:51“,” year_to_date“:” 0.00000“},” customer_id“:” 0adfd74a-1555-11e8-fa42-803e0f85287c“,” deleted_at“:null,” id“:” f6f4e5c9-9945-97f0-11e8 -83355fd52f80“,”发票编号“:” 66“,”注释“:”“,” register_id“:” 0adfd74a-1555-11e8-fa42-803e0f8aa114“,” register_sale_payments“:[{”金额“:1100,” id“ :“ f6f4e5c9-9945-97f0-11e8-83365cae0974”,“付款日期”:“ 2018-07-09T05:10:14Z”,“付款类型”:{“ has_native_support”:false,“ id”:“ 1”,“名称“:”现金“},” payment_type_id“:1,” retailer_payment_type“:{” config“:null,” id“:” 0adfd74a-1555-11e8-fa42-803e0f8ac9eb“,”名称“:”现金“,” payment_type_id “:” 1“},” retailer_payment_type_id“:” 0adfd74a-1555-11e8-fa42-803e0f8ac9eb“}],” register_sale_products“:[{” discount“:” 0.00000“,” id“:” f6f4e5c9-9945-97f0- 11e8-83365b647272“,”忠诚度值“:” 0.00000“,”价格“:” 1100.00000“,” price_set“:false,”价格总计“:” 1100.00000“,” product_id“:” 4d561106-1410-1b93-cc7f-ef04f3306d85“ ,“ quantity”:1,“ tax”:“ 0.00000”,“ tax_id”:“ 0adfd74a-1555-11e8-fa42-803e0f863715”,“ tax_total”:“ 0.00000”}],“ sale_date”:“ 2018-07- 09T05:10 :14Z“,” short_code“:” ezl9kt“,” source“:” USER“,” source_id“:null,” status“:” CLOSED“,” taxes“:[{” id“:” 0f867708-803e-11e8 -ba42-0adfd74a1555“,”名称“:”否   税”,“费率”:“ 0.00000”,“税”:0}],“总计”:{“总计忠诚度”:“ 0.00000”,“总计付款”:“ 1100.00000”,“总计价格”:“ 1100.00000”,“总计税收” “:” 0.00000“,” total_to_pay“:” 0.00000“},” updated_at“:” 2018-07-09T05:10:17 + 00:00“,” user“:{” created_at“:” 2018-07-05   10:27:47“,” display_name“:” Radhe Shyam   Sharma“,”电子邮件“:” leadtesting@yopmail.com“,” id“:” 0adfd74a-1555-11e8-fa42-803e0f8b1095“,”名称“:” leadtesting@yopmail.com“,” target_daily“:null,” target_monthly“:null,” target_weekly“:null,” updated_at“:” 2018-07-05   11:14:25“},” user_id“:” 0adfd74a-1555-11e8-fa42-803e0f8b1095“,” version“:7602780686}&retailer_id = 0adfd74a-1555-11e8-fa42-803e0f833351&type = sale.update =

预先感谢

3 个答案:

答案 0 :(得分:1)

您可以使用explode() on "&"来获取数组格式的数据。因此,如果您的有效负载字符串不在固定位置,则可以使用foreach loo p,在strchr()的帮助下,您可以找到有效负载字符串是否以字符串形式存在。

 $str = 'domain_prefix=leadingdots&environment=prod&payload={"created_at":"2018-07-09 05:10:17","customer":{"balance":"0.00000","company_name":null,"contact_first_name":null,"contact_last_name":null,"created_at":"2018-07-05 10:27:47","custom_field_1":null,"custom_field_2":null,"custom_field_3":null,"custom_field_4":null,"customer_code":"WALKIN","customer_group_id":"0adfd74a-1555-11e8-fa42-803e0f84ff30","date_of_birth":null,"deleted_at":null,"do_not_email":false,"email":null,"enable_loyalty":false,"fax":null,"first_name":null,"id":"0adfd74a-1555-11e8-fa42-803e0f85287c","last_name":null,"loyalty_balance":"0.00000","mobile":null,"note":null,"phone":null,"points":0,"sex":null,"updated_at":"2018-07-06 12:59:51","year_to_date":"0.00000"},"customer_id":"0adfd74a-1555-11e8-fa42-803e0f85287c","deleted_at":null,"id":"f6f4e5c9-9945-97f0-11e8-83355fd52f80","invoice_number":"66","note":"","register_id":"0adfd74a-1555-11e8-fa42-803e0f8aa114","register_sale_payments":[{"amount":1100,"id":"f6f4e5c9-9945-97f0-11e8-83365cae0974","payment_date":"2018-07-09T05:10:14Z","payment_type":{"has_native_support":false,"id":"1","name":"Cash"},"payment_type_id":1,"retailer_payment_type":{"config":null,"id":"0adfd74a-1555-11e8-fa42-803e0f8ac9eb","name":"Cash","payment_type_id":"1"},"retailer_payment_type_id":"0adfd74a-1555-11e8-fa42-803e0f8ac9eb"}],"register_sale_products":[{"discount":"0.00000","id":"f6f4e5c9-9945-97f0-11e8-83365b647272","loyalty_value":"0.00000","price":"1100.00000","price_set":false,"price_total":"1100.00000","product_id":"4d561106-1410-1b93-cc7f-ef04f3306d85","quantity":1,"tax":"0.00000","tax_id":"0adfd74a-1555-11e8-fa42-803e0f863715","tax_total":"0.00000"}],"sale_date":"2018-07-09T05:10:14Z","short_code":"ezl9kt","source":"USER","source_id":null,"status":"CLOSED","taxes":[{"id":"0f867708-803e-11e8-ba42-0adfd74a1555","name":"No Tax","rate":"0.00000","tax":0}],"totals":{"total_loyalty":"0.00000","total_payment":"1100.00000","total_price":"1100.00000","total_tax":"0.00000","total_to_pay":"0.00000"},"updated_at":"2018-07-09T05:10:17+00:00","user":{"created_at":"2018-07-05 10:27:47","display_name":"Radhe Shyam Sharma","email":"leadtesting@yopmail.com","id":"0adfd74a-1555-11e8-fa42-803e0f8b1095","name":"leadtesting@yopmail.com","target_daily":null,"target_monthly":null,"target_weekly":null,"updated_at":"2018-07-05 11:14:25"},"user_id":"0adfd74a-1555-11e8-fa42-803e0f8b1095","version":7602780686}&retailer_id=0adfd74a-1555-11e8-fa42-803e0f833351&type=sale.update=';
        $array = explode('&',$str);
        foreach($array as $value) {
            $str2  =  strchr($value, 'payload');
            if(!empty($str2)) {
                $result = $str2;
            }

        }
print_r($result);

输出:

payload={"created_at":"2018-07-09 05:10:17","customer":{"balance":"0.00000","company_name":null,"contact_first_name":null,"contact_last_name":null,"created_at":"2018-07-05 10:27:47","custom_field_1":null,"custom_field_2":null,"custom_field_3":null,"custom_field_4":null,"customer_code":"WALKIN","customer_group_id":"0adfd74a-1555-11e8-fa42-803e0f84ff30","date_of_birth":null,"deleted_at":null,"do_not_email":false,"email":null,"enable_loyalty":false,"fax":null,"first_name":null,"id":"0adfd74a-1555-11e8-fa42-803e0f85287c","last_name":null,"loyalty_balance":"0.00000","mobile":null,"note":null,"phone":null,"points":0,"sex":null,"updated_at":"2018-07-06 12:59:51","year_to_date":"0.00000"},"customer_id":"0adfd74a-1555-11e8-fa42-803e0f85287c","deleted_at":null,"id":"f6f4e5c9-9945-97f0-11e8-83355fd52f80","invoice_number":"66","note":"","register_id":"0adfd74a-1555-11e8-fa42-803e0f8aa114","register_sale_payments":[{"amount":1100,"id":"f6f4e5c9-9945-97f0-11e8-83365cae0974","payment_date":"2018-07-09T05:10:14Z","payment_type":{"has_native_support":false,"id":"1","name":"Cash"},"payment_type_id":1,"retailer_payment_type":{"config":null,"id":"0adfd74a-1555-11e8-fa42-803e0f8ac9eb","name":"Cash","payment_type_id":"1"},"retailer_payment_type_id":"0adfd74a-1555-11e8-fa42-803e0f8ac9eb"}],"register_sale_products":[{"discount":"0.00000","id":"f6f4e5c9-9945-97f0-11e8-83365b647272","loyalty_value":"0.00000","price":"1100.00000","price_set":false,"price_total":"1100.00000","product_id":"4d561106-1410-1b93-cc7f-ef04f3306d85","quantity":1,"tax":"0.00000","tax_id":"0adfd74a-1555-11e8-fa42-803e0f863715","tax_total":"0.00000"}],"sale_date":"2018-07-09T05:10:14Z","short_code":"ezl9kt","source":"USER","source_id":null,"status":"CLOSED","taxes":[{"id":"0f867708-803e-11e8-ba42-0adfd74a1555","name":"No Tax","rate":"0.00000","tax":0}],"totals":{"total_loyalty":"0.00000","total_payment":"1100.00000","total_price":"1100.00000","total_tax":"0.00000","total_to_pay":"0.00000"},"updated_at":"2018-07-09T05:10:17+00:00","user":{"created_at":"2018-07-05 10:27:47","display_name":"Radhe Shyam Sharma","email":"leadtesting@yopmail.com","id":"0adfd74a-1555-11e8-fa42-803e0f8b1095","name":"leadtesting@yopmail.com","target_daily":null,"target_monthly":null,"target_weekly":null,"updated_at":"2018-07-05 11:14:25"},"user_id":"0adfd74a-1555-11e8-fa42-803e0f8b1095","version":7602780686}

答案 1 :(得分:0)

{"created_at":"2018-07-09 05:10:17","customer":{"balance":"0.00000","company_name":null,"contact_first_name":null,"contact_last_name":null,"created_at":"2018-07-05 10:27:47","custom_field_1":null,"custom_field_2":null,"custom_field_3":null,"custom_field_4":null,"customer_code":"WALKIN","customer_group_id":"0adfd74a-1555-11e8-fa42-803e0f84ff30","date_of_birth":null,"deleted_at":null,"do_not_email":false,"email":null,"enable_loyalty":false,"fax":null,"first_name":null,"id":"0adfd74a-1555-11e8-fa42-803e0f85287c","last_name":null,"loyalty_balance":"0.00000","mobile":null,"note":null,"phone":null,"points":0,"sex":null,"updated_at":"2018-07-06 12:59:51","year_to_date":"0.00000"},"customer_id":"0adfd74a-1555-11e8-fa42-803e0f85287c","deleted_at":null,"id":"f6f4e5c9-9945-97f0-11e8-83355fd52f80","invoice_number":"66","note":"","register_id":"0adfd74a-1555-11e8-fa42-803e0f8aa114","register_sale_payments":[{"amount":1100,"id":"f6f4e5c9-9945-97f0-11e8-83365cae0974","payment_date":"2018-07-09T05:10:14Z","payment_type":{"has_native_support":false,"id":"1","name":"Cash"},"payment_type_id":1,"retailer_payment_type":{"config":null,"id":"0adfd74a-1555-11e8-fa42-803e0f8ac9eb","name":"Cash","payment_type_id":"1"},"retailer_payment_type_id":"0adfd74a-1555-11e8-fa42-803e0f8ac9eb"}],"register_sale_products":[{"discount":"0.00000","id":"f6f4e5c9-9945-97f0-11e8-83365b647272","loyalty_value":"0.00000","price":"1100.00000","price_set":false,"price_total":"1100.00000","product_id":"4d561106-1410-1b93-cc7f-ef04f3306d85","quantity":1,"tax":"0.00000","tax_id":"0adfd74a-1555-11e8-fa42-803e0f863715","tax_total":"0.00000"}],"sale_date":"2018-07-09T05:10:14Z","short_code":"ezl9kt","source":"USER","source_id":null,"status":"CLOSED","taxes":[{"id":"0f867708-803e-11e8-ba42-0adfd74a1555","name":"No Tax","rate":"0.00000","tax":0}],"totals":{"total_loyalty":"0.00000","total_payment":"1100.00000","total_price":"1100.00000","total_tax":"0.00000","total_to_pay":"0.00000"},"updated_at":"2018-07-09T05:10:17+00:00","user":{"created_at":"2018-07-05 10:27:47","display_name":"Radhe Shyam Sharma","email":"leadtesting@yopmail.com","id":"0adfd74a-1555-11e8-fa42-803e0f8b1095","name":"leadtesting@yopmail.com","target_daily":null,"target_monthly":null,"target_weekly":null,"updated_at":"2018-07-05 11:14:25"},"user_id":"0adfd74a-1555-11e8-fa42-803e0f8b1095","version":7602780686}

这是Json字符串,您可以使用json_decode()函数将其解析为数组。

答案 2 :(得分:0)

您可以使用json_decode将原始的json有效内容解码为数组:

$payLoad = json_decode(request()->getContent(), true);

dd($payLoad['created_at']);