Php GCM消息(或数据)限制

Php GCM消息(或数据)限制,php,google-cloud-messaging,Php,Google Cloud Messaging,我有发送推送通知的php代码。它适用于小数据(消息),但当我尝试在推送通知中发送大字符串时,它不起作用。在GCM中发送的字符串有任何限制吗?如果有的话,尺寸是多少 感谢您的支持是的,消息的有效负载有4096字节的限制(包括有效负载中的所有自定义键和值)。经过多次尝试,我发现消息的数据部分的限制不能大于2048字节。 问题是,我对数据使用UTF-8编码,我认为这可能是原因。 数据是一个小文本文件的内容 // Prepare JSON containing the GCM message conte

我有发送推送通知的php代码。它适用于小数据(消息),但当我尝试在推送通知中发送大字符串时,它不起作用。在GCM中发送的字符串有任何限制吗?如果有的话,尺寸是多少


感谢您的支持

是的,消息的有效负载有4096字节的限制(包括有效负载中的所有自定义键和值)。

经过多次尝试,我发现消息的数据部分的限制不能大于2048字节。 问题是,我对数据使用UTF-8编码,我认为这可能是原因。 数据是一个小文本文件的内容

// Prepare JSON containing the GCM message content.
JSONObject jGcmData = new JSONObject();
jGcmData.put("to", "/topics/"+args[0].trim());
// Set maximum time alive in seconds.
jGcmData.put("time_to_live", 300);
// Set the collapse key, which groups as one the messages of same topic
jGcmData.put("collapse_key", args[0].trim());
// Prepare the GCM data
JSONObject jData = new JSONObject();
String message = readFile(args[1].trim(), Charset.forName("UTF-8"));
jData.put("message", message);
System.out.println("Data length: " + message.length());
// Add the data to the message.
jGcmData.put("data", jData);
System.out.println("Total GCM length: " + jGcmData.toString().getBytes("UTF-8").length);
// Create connection to send GCM Message request.
URL url = new URL("https://android.googleapis.com/gcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "key=" + API_KEY);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestMethod("POST");
conn.setDoOutput(true);
 // Send GCM message content.
DataOutputStream outputStream = new DataOutputStream(conn.getOutputStream());
outputStream.write(jGcmData.toString().getBytes("UTF-8"));
outputStream.flush();
outputStream.close();
// Read GCM response.
InputStream inputStream = conn.getInputStream();
String resp = IOUtils.toString(inputStream);
System.out.println(resp);
System.out.println("SUCCESS!");