我是.net的新手,并使用.net作为GCM推送通知的服务器端。我正在使用下面的代码,它适用于单个用户(对于下面的regId)。我的问题是如何在我们的.net服务器中保存所有注册表?我不知道它是否保存在我们的服务器中。如果没有保存注册ID,那么如何向所有注册用户发送推送通知?
protected void Button1_Click(object sender, EventArgs e)
{
string regId = "APA91bFUgrdgtdgfdgxxxxxxxxxxxxxxxxxxxxxxxxxx6t1QDCn-4IiIAtvBhEt328QeYeLKoDeDFOgumrgACdydLCLvM0wM59nAzm_fZse3ta_A";
//server api key
var applicationID = "AIzaSDGjvbnviiuteuoidsgdfsdryiIfgA";
var SENDER_ID = "77xxxxxx25";
var value = Label1.Text; //message box label
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.Headers.Add(string.Format("Authorization: key={0}", applicationID));
tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
// string postData = "{ 'registration_id': [ '" + regId + "' ], 'data': {'message': '" + txtMsg.Text + "'}}";
string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "®istration_id=" + regId + "";
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);
String sResponseFromServer = tReader.ReadToEnd();
Label3.Text = sResponseFromServer;
tReader.Close();
dataStream.Close();
tResponse.Close();
}
现在我在我的Android设备中收到推送通知,例如this以及如何发送或获取短信,例如" hii"," test" ...而不是"你有痒痒的感觉"。请帮帮我..
答案 0 :(得分:0)
这在android方面是个错误。终于解决了。