C#利用极光进行APP推送

看了他的sdk,然后自己写的几个方法。需要引入极光的SDK中的DLL 

 

   private static JPushClient client = new JPushClient("自己的key", "自己的MasterSecret");

        public static void Main(string[] args)
        {
           
            //ExecutePustByTags(new List<string>{"北京","上海"}, "aa", "abb");
            ExecutePushByUserId(new List<string> { "120c83f760079951806", "上海" }, "我是标题",$"当前时间:{DateTime.Now.ToString()}");

            Console.ReadLine();
        }

        /// <summary>
        /// 根据Tags推送(根据角色推送)
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="title"></param>
        /// <param name="countent"></param>
        public static void ExecutePustByTags(List<string> tags, string title, string content)
        {
            //audience : { "tag" : [ "tag1", "tag2" ]} 
            var pushPayload = new PushPayload()
            {
                Platform = new List<string> { "android" },
                Audience = "{\"tag\" :" + Newtonsoft.Json.JsonConvert.SerializeObject(tags) + "}",
                Notification = new Notification
                {
                    Android = new Android
                    {
                        Alert = content,
                        Title = title
                    },
                },
                Options = new Options {
                    TimeToLive = 864000//单位秒,最大值10天
                }
                
            };
            var response = client.SendPush(pushPayload);
            Console.WriteLine(response.Content);
        }
        /// <summary>
        /// 推送所有人
        /// </summary>
        /// <param name="title"></param>
        /// <param name="content"></param>
        public static void ExecutePushByALL(string title, string content)
        {
            var pushPayload = new PushPayload()
            {
                Platform = new List<string> { "android" },
                Audience = "all",
                Notification = new Notification
                {
                    Android = new Android
                    {
                        Alert = content,
                        Title = title
                    },
                },
                 Options = new Options
                 {
                     TimeToLive = 864000//单位秒,最大值10天
                 }
            };
            var response = client.SendPush(pushPayload);
            Console.WriteLine(response.Content);
        }
        /// <summary>
        /// 推送到个人,每次推送最多1000人
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="title"></param>
        /// <param name="content"></param>
        public static void ExecutePushByUserId(List<string> registration_id, string title, string content)
        {
            //audience : { "registration_id" : [ "111", "22" ]}  设备标识。一次推送最多 1000 个。
            var pushPayload = new PushPayload()
            {
                Platform = new List<string> { "android" },
                Audience = "{\"registration_id\" :" + Newtonsoft.Json.JsonConvert.SerializeObject(registration_id) + "}",
                Notification = new Notification
                {
                    Android = new Android
                    {
                        Alert = content,
                        Title = title
                    },
                },
                 Options = new Options
                 {
                     TimeToLive = 864000//单位秒,最大值10天
                 }
            };
            var response = client.SendPush(pushPayload);
            Console.WriteLine(response.Content);
        }

 

转载于:https://www.cnblogs.com/HandLoong/p/8607909.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值