0

我是 .net 新手,使用 .net 作为 GCM 推送通知的服务器端。我正在使用下面的代码,它适用于单个用户(对于低于 regId)。我的问题是如何将所有 reg-id 保存在我们的 .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() + "&registration_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 设备中收到推送通知,以及如何发送或获取诸如“hii”、“test”之类的短信......而不是“你有痒痒”。请帮助我..

4

1 回答 1

0

这是android方面的错误。终于解决了。

于 2014-07-02T13:02:15.790 回答