使用php的android推送通知GCM是否有任何数据限制。我通过这段代码传递了数据(消息)。
$url = 'https://android.googleapis.com/gcm/send';
$fields = array (
registration_ids' => $registatoin_ids,
data => $message,
);
$headers = array(
Authorization: key= . GOOGLE_API_KEY,
Content-Type: application/json
);
// Open connection
if(!function_exists('curl_init'))
echo "CURL not installed";
else
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
$obj = json_decode($result);
if($obj->{'success'})
{
echo "Message Sent Successfully";
}
else{
echo "Sending Error : " . $result;
}
如果$ message包含超过3000个字符,那么我没有收到任何通知。假设$ message包含少于1000个字符,我收到通知。
提前致谢。
答案 0 :(得分:1)
是它的有效负载限制为4096字节。