调用极光推送接口C#代码

来源:互联网 发布:java md5使用 编辑:程序博客网 时间:2024/05/13 20:55

          代码是推送设备为IOS的。请注意!Ios和Android区别不大,改几个参数就可以了。和手机端的伙伴一起测试跑跑

一定要去极光推送官网下载 dll并引用进去

ifunction.JPush.dll


//推送条件

            var appKey = "";//在极光推送官网创建的key
            var masterSecret = "";//在极光推送官网创建的key对于的密码

            JPushClientV3 client = new JPushClientV3(appKey, masterSecret);

            #region 添加推送给哪个用户的UID
            Audience audience = new Audience();

            List<string> aliaslist = new List<string>();
            aliaslist = list;

            //推送对象
            if (aliaslist.Count() == 0)
            {
                return;
            }
            //这种是alias模式 通知 别名模式
            audience.Add(PushTypeV3.ByAlias, aliaslist);
            #endregion

            Dictionary<string, string> customizedValues = new Dictionary<string, string>();
            //添加类型ID 可自定义
            customizedValues.Add("type", "1");

            //消息
            Notification notification = new Notification
            {
                //IOS 设备
               iOSNotification =new iOSNotificationParameters
                 //安卓设备
                //AndroidNotification = new AndroidNotificationParameters
                {
                  //title="",
                    Alert = "你有新单子,请刷新!",
                    //这个是自定义值
                    CustomizedValues = customizedValues
                    
                }
               
            };
        
            //内容体
            var response = client.SendPushMessage(new PushMessageRequestV3
            {
                Audience = audience,
                //设备类型
                Platform = PushPlatform.iOS,
                //生产环境或者测试环境
                IsTestEnvironment = false,
                AppMessage = new AppMessage
                {
                    ContentType = "",
                    Content = "",
                    CustomizedValue = customizedValues
                },
                Notification = notification
                
            });
           
            List<string> idToCheck = new List<string>();
            idToCheck.Add(response.MessageId);
            var statusList = client.QueryPushMessageStatus(idToCheck);
0 0
原创粉丝点击