我想将fcm响应与另一个响应结合起来

时间:2017-02-16 12:13:51

标签: php

{     “成功”:1,“数据”:{“状态”:“发送的消息”,                         “MESSAGE_ID”:3594,                         “personaluid”: “161”,                         “GID”: “0”,                         “UID”: “160”,                         “消息”: “cxzczxczxsada123”,                         “chat_image”: “”,                         “created_at”:“2017-02-04 16:52:11”,                         “UTYPE”: “1”                     } } {
     aps =           {alert =              {body = hdhd; title =来自某个人的名字;};               badge = 1;           };
         “gcm.message_id”=“0:1487247942837269%19aca14d19aca14d”;          “gcm.notification.Content_available”= 1;          “gcm.notification.created_at”=“2017-02-16 17:55:41”;
         “gcm.notification.uid”= 161; }

2 个答案:

答案 0 :(得分:0)

你可以合并2个解码数组。

$data = json_decode($result, true);
$data = array_merge($data[0], $data[1]);
$data = json_encode($data, JSON_FORCE_OBJECTS);`

答案 1 :(得分:0)

将您的json数据转换为php数组,然后使用array_merge合并两者。然后再将其转换为json数据。例如:

 <?php
   $json1='{"success":1,
  "Data":{"status":"message sent","message_id":3594,"personaluid":"161","gid":"0","uid":"160","message":"cxzczxczxsada123","chat_image":"","created_at":"2017-02-04 16:52:11","utype":"1"}
}';
$json2='{
    "multicast_id":5114850183838817498,
    "success":1,
    "failure":0,
    "canonical_ids":0,
    "results":[{"message_id":"0:1487247086404626%19aca14d19aca14d"}]
}';

$ar1=json_decode($json1,true);
$ar2=json_decode($json2,true);
$ar1=array_merge($ar1,$ar2);
echo json_encode($ar1);

输出:

{"success":1,"Data":{"status":"message sent","message_id":3594,"personaluid":"161","gid":"0","uid":"160","message":"cxzczxczxsada123","chat_image":"","created_at":"2017-02-04 16:52:11","utype":"1"},"multicast_id":5.1148501838388e+18,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1487247086404626%19aca14d19aca14d"}]}