【发布时间】:2017-12-16 08:14:27
【问题描述】:
我想从 url-> "https://fcm.googleapis.com/fcm/send" 解码这个 json 但不幸的是我没有成功,我真的不知道该怎么办请帮助我,在下面你看到我的代码:
function decodeJSON($ids)
{
$MyString = sendFCMToMultiple($ids);
echo "return:" . $MyString . PHP_EOL;
//$MyDecode = json_decode($MyString, false, 512, JSON_BIGINT_AS_STRING);
//$MyDecode = json_decode($MyString, true, 512, JSON_BIGINT_AS_STRING);
$MyDecode = json_decode($MyString);
$MultiCastID = $MyDecode->multicast_id;
$Success = $MyDecode->success;
$Failure = $MyDecode->failure;
$CanonicalIDS = $MyDecode->canonical_ids;
$Results = $MyDecode->results;
//echo 'Var MultiCastID=' . var_dump($MultiCastID) . PHP_EOL;
echo 'MultiCastID to Str=' . number_format($MultiCastID, 0, '.', '') . PHP_EOL;
echo 'MultiCastID=' . $MultiCastID . PHP_EOL;
echo 'Success=' . $Success . PHP_EOL;
echo 'Failure=' . $Failure . PHP_EOL;
echo 'CanonicalIDS=' . $CanonicalIDS . PHP_EOL;
echo 'Results=' . $Results . PHP_EOL;
echo '=================================================================' . PHP_EOL;
}
这是来自 fcm url 的原始和主要 json:
{
"multicast_id": 7640049088650537742,
"success": 2,
"failure": 2,
"canonical_ids": 0,
"results": [
{
"error": "NotRegistered"
},
{
"error": "NotRegistered"
},
{
"message_id": "0:1513401047065944%93a06d80f9fd7ecd"
},
{
"message_id": "0:1513401047066546%93a06d80f9fd7ecd"
}
]
}
这是返回并从我的代码中显示:
{"multicast_id":7640049088650537742,"success":2,"failure":2,"canonical_ids":0,"results":[{"error":"NotRegistered"},{"error":"NotRegistered"},{"message_id":"0:1513401047065944%93a06d80f9fd7ecd"},{"message_id":"0:1513401047066546%93a06d80f9fd7ecd"}]}
MultiCastID to Str=7640049088650537984
MultiCastID=7.6400490886505E+18
Success=2
Failure=2
CanonicalIDS=0
Results=
=================================================================
还有我的问题:
首先:我不能使用 json 字符串来 json_decode($MyString, false, 512, JSON_BIGINT_AS_STRING) 并为所有键返回空值;这就是为什么我说我想要 multicast_id 键的字符串值或整数类型,但 json_decode 本身自动大整数浮点数,我不喜欢它,我想要整数和/或字符串值,尽管我使用了第 5 行和第 6 行并且因为评论在代码中,但不是真的。 第二:结果键数组对我来说非常重要,因为我明白谁没有收到,谁收到了,为什么?谢谢。
【问题讨论】:
-
可能与您关于 bigints 的第一点有关:stackoverflow.com/questions/19520487/…
标签: php json firebase push-notification decode