Problems with json data processing in php

WBOY
Release: 2016-10-19 10:40:52
Original
1151 people have browsed it

The order information format pushed by Weidian API is as follows:

<code>content=
{"message":{
"seller_name":"天天向上","total":"0.10",
"express_fee":"0.00",
"buyer_identity_id":"0",
"f_phone":"",
"fx_fee_value":"0.00",
"express_type":null,
"express_note":"",
"modify_price_enable":"1",
"express":null,
"order_id":"774780580411340",
"order_type_des":"担保交易",
"confirm_expire":"",
"group_status":-1,
"send_time":null,
"weixin":"",
"is_close":0,
"argue_flag":0,
"total_fee":"0.00",
"status_desc":"未付款",
"quantity":"1",
"note":"",
"trade_no":null,
"sk":null,
"status":"unpay",
"discount_info":"无优惠",
"seller_phone":"18512345678",
"express_fee_num":"0.00",
"pay_time":"",
"discount_amount":"0",
"discount":null,
"real_income_price":"",
"price":"0.10",
"buyer_info":{
"buyer_id":"1024799624",
"region":"禹会区",
"phone":"15923808761",
"post":null,
"address":"安徽 蚌埠市 禹会区 城区回来了",
"name":"路过",
"self_address":"城区回来了",
"province":"安徽",
"city":"蚌埠"
},
"items":
[{
"is_delivered":0,
"img":"http://wd.geilicdn.com/vshop1024697422-1476758240117-CE6F5-s1.jpg?w=110&h=110&cp=1",
"total_price":"0.10",
"merchant_code":"",
"deliver_id":"0",
"url":"http://weidian.com/i/1969988669",
"deliver_status_desc":"",
"price":"0.10",
"sku_merchant_code":"",
"item_name":"测试商品",
"item_id":"1969988669",
"fx_fee_rate":"0%",
"quantity":"1",
"can_deliver":1,
"refund_info":{"refund_no":"",
"refund_fee":"0",
"refund_status_str":"",
"item_id":"1969988669",
"item_sku_id":"0",
"refund_status":"",
"refund_express_fee":"0",
"can_refund":"0",
"refund_item_fee":"0",
"refund_status_desc":""},
"sku_id":"0","sku_title":null
}],
"user_phone":"15912345678",
"status2":"未付款",
"f_seller_id":"",
"seller_id":"1024697422",
"add_time":"2016-10-18 13:25:54",
"refund_info":
{
"buyer_refund_fee":null,
"refund_time":null},
"return_code":"",
"express_no":null,
"f_shop_name":"",
"original_total_price":"",
"order_type":"3"
},
"type":"weidian.order.non_payment"
}&public={"x_forwarded_for":null}
</code>
Copy after login
Copy after login

You need to get the data of one or several fields. There are two pieces of json information here. I would like to ask the master how to deal with it?

If yes

<code>{"seller_name":"天天向上","total":"0.10",
"express_fee":"0.00",
"buyer_identity_id":"0",
"f_phone":"",
"fx_fee_value":"0.00",
"express_type":null,
"express_note":"",
"modify_price_enable":"1",
"express":null,
"order_id":"774780580411340"}
</code>
Copy after login
Copy after login

For this format, the following code should be enough

<code><?php
$input = file_get_contents("php://input"); //接收POST数据
$arr=json_decode($input, true); 
file_put_contents("test.txt",$arr[order_id], FILE_APPEND);//以将order_id追加如文本文档为例
?></code>
Copy after login
Copy after login

Reply content:

The order information format pushed by Weidian API is as follows:

<code>content=
{"message":{
"seller_name":"天天向上","total":"0.10",
"express_fee":"0.00",
"buyer_identity_id":"0",
"f_phone":"",
"fx_fee_value":"0.00",
"express_type":null,
"express_note":"",
"modify_price_enable":"1",
"express":null,
"order_id":"774780580411340",
"order_type_des":"担保交易",
"confirm_expire":"",
"group_status":-1,
"send_time":null,
"weixin":"",
"is_close":0,
"argue_flag":0,
"total_fee":"0.00",
"status_desc":"未付款",
"quantity":"1",
"note":"",
"trade_no":null,
"sk":null,
"status":"unpay",
"discount_info":"无优惠",
"seller_phone":"18512345678",
"express_fee_num":"0.00",
"pay_time":"",
"discount_amount":"0",
"discount":null,
"real_income_price":"",
"price":"0.10",
"buyer_info":{
"buyer_id":"1024799624",
"region":"禹会区",
"phone":"15923808761",
"post":null,
"address":"安徽 蚌埠市 禹会区 城区回来了",
"name":"路过",
"self_address":"城区回来了",
"province":"安徽",
"city":"蚌埠"
},
"items":
[{
"is_delivered":0,
"img":"http://wd.geilicdn.com/vshop1024697422-1476758240117-CE6F5-s1.jpg?w=110&h=110&cp=1",
"total_price":"0.10",
"merchant_code":"",
"deliver_id":"0",
"url":"http://weidian.com/i/1969988669",
"deliver_status_desc":"",
"price":"0.10",
"sku_merchant_code":"",
"item_name":"测试商品",
"item_id":"1969988669",
"fx_fee_rate":"0%",
"quantity":"1",
"can_deliver":1,
"refund_info":{"refund_no":"",
"refund_fee":"0",
"refund_status_str":"",
"item_id":"1969988669",
"item_sku_id":"0",
"refund_status":"",
"refund_express_fee":"0",
"can_refund":"0",
"refund_item_fee":"0",
"refund_status_desc":""},
"sku_id":"0","sku_title":null
}],
"user_phone":"15912345678",
"status2":"未付款",
"f_seller_id":"",
"seller_id":"1024697422",
"add_time":"2016-10-18 13:25:54",
"refund_info":
{
"buyer_refund_fee":null,
"refund_time":null},
"return_code":"",
"express_no":null,
"f_shop_name":"",
"original_total_price":"",
"order_type":"3"
},
"type":"weidian.order.non_payment"
}&public={"x_forwarded_for":null}
</code>
Copy after login
Copy after login

You need to get the data of one or several fields. There are two pieces of json information here. How should I deal with it?

If yes

<code>{"seller_name":"天天向上","total":"0.10",
"express_fee":"0.00",
"buyer_identity_id":"0",
"f_phone":"",
"fx_fee_value":"0.00",
"express_type":null,
"express_note":"",
"modify_price_enable":"1",
"express":null,
"order_id":"774780580411340"}
</code>
Copy after login
Copy after login

For this format, the following code should be enough

<code><?php
$input = file_get_contents("php://input"); //接收POST数据
$arr=json_decode($input, true); 
file_put_contents("test.txt",$arr[order_id], FILE_APPEND);//以将order_id追加如文本文档为例
?></code>
Copy after login
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template