我开始开发一个有推送通知功能的应用程序。我希望我的通知对象保存一条消息和其他我称之为"color“的额外字符串。
在我添加行数据color=‘>$color=’>颜色之前,一切都进行得很好.现在,我的消息字段为空(null),我只能读取颜色字符串。
如何向PHP字段数组中添加更多的数据字段?
function send_notification ($tokens, $message, $color)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message,
'data' => $color
);
$headers = array(
'Authorization:key = Not telling you me real key :)',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}发布于 2017-03-18 17:41:29
您可以更改字段名,使其类似于'color' => $color,也可以将其附加到data字段。会是这样的:
$data = $message . "\n";
$data .= $color;编辑:我相信您的$message变量可能是一个json,所以您应该将$color附加到那个json。
https://stackoverflow.com/questions/42877687
复制相似问题