Ejemplo n.º 1
0
        // GET: /<controller>/
        public async Task <IActionResult> Index()
        {
            var         httpClient = new HttpClient();
            FcmSettings settings   = new FcmSettings();

            settings.SenderId  = "557535861881";
            settings.ServerKey = "AAAAgc-6HHk:APA91bGGjo4Xld7-Lg0vRTcORTZWKFIwZaTZnmw4fr21pgusvwobvSCjzUSjj7-7JlaIcQr2GDNptWZQKe5oWuopgkgpmH-aOHe9_Q9eKUHGgUIMhLPJhEtrq-jHPIyDpBLHmWp2tTf8";


            var fcm = new FcmSender(settings, httpClient);

            var notification = new GoogleNotification
            {
                Data = new GoogleNotification.DataPayload
                {
                    ExperienceId = "@choby/seekit24",
                    Message      = "安卓测试消息 🆚"
                },
                Priority = "high"
            };

            string deviceToken = "fQVPgfq8TZKrltAwHSB-WI:APA91bFWh5E5PKp_8fdjlkkeE7K6xjoA9CH9Dll-nJBvPwnKDcsNnH2Py5Gf5T7SMna4X0D35_tA8a32ytB29nApEei4Kx78pIsk7md6xfBh-_JffilmRZQSR179e2pc8pbZs4T78ocp";

            FcmResponse response = await fcm.SendAsync(deviceToken, notification);

            //  await fcm.SendAsync();

            return(Content($"android push result:"));//{response.IsSuccess().ToString()}
        }
        private static async Task SendFcmNotificationAsync()
        {
            var settings = new FcmSettings
            {
                SenderId  = fcmSenderId,
                ServerKey = fcmServerKey
            };

            var payload = new
            {
                notification = new { body = "Hello World!" }
            };

            var fcm      = new FcmSender(settings, new HttpClient());
            var response = await fcm.SendAsync(fcmReceiverToken, payload);
        }
Ejemplo n.º 3
0
        static async Task Main(string[] args)
        {
            var path = args.Length > 0 ? args[0] : Path.Combine(Directory.GetCurrentDirectory(), "google.json");
            var json = JObject.Parse(File.ReadAllText(path));

            var serverKey   = json["serverKey"].ToString();
            var senderId    = json["senderId"].ToString();
            var deviceToken = json["deviceToken"].ToString();

            var settings = new FcmSettings
            {
                SenderId  = senderId,
                ServerKey = serverKey
            };

            var notification = json["payload"].ToObject <GoogleNotification>();

            var fcm      = new FcmSender(settings, http);
            var response = await fcm.SendAsync(deviceToken, notification);

            Console.WriteLine($"Response: {JsonConvert.SerializeObject(response)}");
        }