zoukankan      html  css  js  c++  java
  • 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);
            }
  • 相关阅读:
    [算法分析]计数排序
    [置顶] 基于stm32f103zet6之UC/OS_II的学习1(初步移植OS点灯大法)
    IOS开发(59)之Block Object的调用
    【译】测试员,敢问路在何方?来自微软工程师
    各种字符串hash
    hdu 2579 BFS
    qq相册
    程序人生之我们的故事:十年如歌(9)
    关联模型和无限极分类
    十大技巧破解电话面试
  • 原文地址:https://www.cnblogs.com/HandLoong/p/8607909.html
Copyright © 2011-2022 走看看