我使用phonegap构建移动应用程序,用户可以在其中创建和共享项目。部分过程是向1-3位朋友发送推送通知。出于某种原因,有时候所有的朋友都会收到通知,有时候只会收到一些通知,有时甚至没有人收到通知。 这是我正在使用的代码(在c#中)
string stringregIds = string.Join("\",\"", deviceIds);
string GoogleAppID = "AIzaSyDqwXXXXXXXXXXXXXHfbyqiA";
var SENDER_ID = "604XXXXXXX98";
var value = message;
WebRequest tRequest;
tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
tRequest.Method = "post";
//tRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
tRequest.ContentType = "application/json";
tRequest.Headers.Add(string.Format("Authorization: key={0}", GoogleAppID));
tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
//string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.title=" + title + "&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "®istration_id=" + stringregIds + "";
string postData = "{\"collapse_key\":\"score_update\",\"time_to_live\":108,\"delay_while_idle\":true,\"data\": { \"message\" : " + "\"" + value + "\",\"time\": " + "\"" + System.DateTime.Now.ToString() + "\"},\"registration_ids\":[\"" + stringregIds + "\"]}";
//Console.WriteLine(postData);
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
sResponseFromServer = tReader.ReadToEnd();
tReader.Close();
dataStream.Close();
tResponse.Close();
你知道可能出现什么问题吗?
我做错了什么?