相关疑难解决方法(0)

使用FCM通过C#发送推送到Android(Firebase云消息传递)

我正在使用此代码通过C#和GCM发送通知消息,使用Winforms,Webforms等等.现在我想发送到FCM(Firebase云消息传递).我应该更新我的代码吗?:

public class AndroidGCMPushNotification
{
    public AndroidGCMPushNotification()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public string SendNotification(string deviceId, string message)
    {
        string SERVER_API_KEY = "server api key";        
        var SENDER_ID = "application number";
        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.Headers.Add(string.Format("Authorization: key={0}", SERVER_API_KEY));

        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.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + deviceId + "";
        Console.WriteLine(postData);
        Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        tRequest.ContentLength = …
Run Code Online (Sandbox Code Playgroud)

c# android firebase-cloud-messaging

39
推荐指数
5
解决办法
10万
查看次数

如何从C#Console应用程序发送通知

我想创建控制台应用程序,用于通过Goolge Firebase Notifications向不同的移动设备发送通知,

我已经看到了使用FCM(Firebase云消息传递)通过C#发送推送到Android的代码

我收到状态码为500的内部服务器错误

try{
    string url = @"https://fcm.googleapis.com/fcm/send";
    WebRequest tRequest = WebRequest.Create(url);
    tRequest.Method = "post";
    tRequest.ContentType = "application/json";

    string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + "This is the message" + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + deviceId + "";
    var data = new
    {
        to = deviceId,
        notification = new
        {
            body = "This is the message",
            title = "This is the title"

        }
    };
    string jsonss = Newtonsoft.Json.JsonConvert.SerializeObject(data);

    Byte[] byteArray = Encoding.UTF8.GetBytes(jsonss);              
    tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
    tRequest.Headers.Add(string.Format("Sender: id={0}", …
Run Code Online (Sandbox Code Playgroud)

c# firebase-cloud-messaging

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×2

firebase-cloud-messaging ×2

android ×1