예제 #1
0
        /// <summary>
        /// 将消息推送给安卓和IOS,并指定拥有特定标签的人
        /// </summary>
        /// <returns></returns>
        public static bool PushObject_android_and_ios(string alert, string androidTitle, Dictionary <string, string> extraParameters, params string[] tags)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();//发送目标:android和ios
            var audience = Audience.s_tag(tags);

            pushPayload.audience = audience;                       //设置要发送的目标
            var notification = new Notification().setAlert(alert); //设置要发送的内容

            //针对安卓设置
            notification.AndroidNotification = new AndroidNotification().setTitle(androidTitle);//设置针对安卓的通知栏标题

            //针对ios设置
            notification.IosNotification = new IosNotification();
            notification.IosNotification.incrBadge(1);//角标加1

            //添加额外的数据
            if (extraParameters != null && extraParameters.Count > 0)
            {
                foreach (var dicItem in extraParameters)
                {
                    notification.IosNotification.AddExtra(dicItem.Key, dicItem.Value);
                }
            }

            //检查参数是否有设置正确
            pushPayload.notification = notification.Check();

            return(SendPush(pushPayload));
        }
예제 #2
0
        public static void PushMessage(string telephone, string message)
        {
            PushPayload payload = new PushPayload();

            payload.platform     = Platform.all();
            payload.audience     = Audience.s_tag(telephone);
            payload.notification = new Notification().setAlert(message);
            ThreadPool.QueueUserWorkItem(new WaitCallback((obj) =>
            {
                try
                {
                    client.SendPush((PushPayload)obj);
                    var db     = Data.Entities.NewInstance;
                    var notice = new Data.notice()
                    {
                        content    = message,
                        isread     = false,
                        noticetime = DateTime.Now,
                        noticetype = 1,
                        telephone  = telephone
                    };
                    db.notices.Add(notice);
                    db.SaveChanges();
                    LogHelper.LogInfo(string.Format("消息推送成功(收件人:{0} 消息:{1})", telephone, message));
                }
                catch (Exception e)
                {
                    LogHelper.LogError(e);
                }
            }), payload);
        }
예제 #3
0
        public static SimpleResultModel SendToTags(string msg, string tags)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform     = Platform.android();
            pushPayload.audience     = Audience.s_tag(tags.Split(','));
            pushPayload.notification = new Notification().setAlert(msg);
            AndroidNotification androidnotification = new AndroidNotification();

            androidnotification.setTitle(TITLE);
            pushPayload.notification.AndroidNotification = androidnotification;

            try {
                var result = client.SendPush(pushPayload);
                return(new SimpleResultModel()
                {
                    suc = true, msg = result.msg_id.ToString()
                });
            }
            catch (APIRequestException e) {
                return(new SimpleResultModel()
                {
                    suc = false, msg = "HTTP Status: " + e.Status + ";Error Code: " + e.ErrorCode + ";Error Message: " + e.ErrorMessage
                });
            }
            catch (APIConnectionException e) {
                return(new SimpleResultModel()
                {
                    suc = false, msg = e.message
                });
            }
        }
예제 #4
0
        /// <summary>
        /// 发送标签消息
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="Content">内容</param>
        /// <param name="alias">标签组</param>
        /// <returns></returns>
        public MessageResult SendTagMsg(string title, string Content, string[] Tags)
        {
            MessageResult result = new MessageResult();

            try
            {
                JPushClient  client      = new JPushClient(app_key, master_secret);
                string       MSG_CONTENT = Content;
                PushPayload  payload     = new PushPayload();
                Notification not         = new Notification();
                not.setAlert(title);

                payload.notification = not;
                payload.platform     = Platform.all();
                payload.audience     = Audience.s_tag(Tags);
                payload.message      = Message.content(title)
                                       .AddExtras("Content", Content)
                                       .AddExtras("Title", title)
                                       .AddExtras("key2", false);
                result = client.SendPush(payload);
            }
            catch (APIRequestException e)
            {
                SystemLogsBiz.logv("推送失败APIRequestException", e.ErrorMessage, "类 JpushHelp");
            }
            catch (APIConnectionException e)
            {
                SystemLogsBiz.logv("推送失败APIConnectionException", e.Message, "类 JpushHelp");
            }
            return(result);
        }
예제 #5
0
        /// <summary>
        /// 发送标签消息
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="message">消息</param>
        /// <param name="alias">标签组</param>
        /// <returns></returns>
        public MessageResult SendTagMsg(Notification not, Message message, string[] Tags)
        {
            MessageResult result = new MessageResult();

            try
            {
                JPushClient client = new JPushClient(app_key, master_secret);

                PushPayload payload = new PushPayload();
                payload.notification = not;
                payload.platform     = Platform.all();
                payload.audience     = Audience.s_tag(Tags);
                payload.message      = message;
                result = client.SendPush(payload);
            }
            catch (APIRequestException e)
            {
                SystemLogsBiz.logv("推送失败APIRequestException", e.ErrorMessage, "类 JpushHelp");
            }
            catch (APIConnectionException e)
            {
                SystemLogsBiz.logv("推送失败APIConnectionException", e.Message, "类 JpushHelp");
            }
            return(result);
        }
예제 #6
0
        /// <summary>
        /// Android文档消息推送
        /// </summary>
        /// <param name="message"></param>
        /// <param name="notificationType"></param>
        /// <param name="tag"></param>
        /// <param name="updateDocumentTypeId"></param>
        /// <param name="updateCity"></param>
        /// <param name="updateDocumentType"></param>
        /// <param name="updateCityId"></param>
        /// <returns></returns>
        private static PushPayload PushAndroidObjectDocument(string message, int notificationType, string tag, int updateDocumentTypeId, string updateCity, string updateDocumentType, int updateCityId)
        {
            var pushPayload = new PushPayload
            {
                platform = Platform.android(),
                audience = tag == "all" ? Audience.all() : Audience.s_tag(tag)
            };

            var notification = new Notification().setAlert(message);

            notification.AndroidNotification =
                new AndroidNotification().setAlert(message)
                .AddExtra("UpdateDocumentTypeID", updateDocumentTypeId)
                .AddExtra("NotificationType", notificationType)
                .AddExtra("message", message);

            if (!string.IsNullOrEmpty(updateCity))
            {
                notification.AndroidNotification.AddExtra("UpdateCity", updateCity);
            }
            if (!string.IsNullOrEmpty(updateDocumentType))
            {
                notification.AndroidNotification.AddExtra("UpdateDocumentType", updateDocumentType);
            }
            if (updateCityId > 0)
            {
                notification.AndroidNotification.AddExtra("UpdateCityId", updateCityId);
            }
            pushPayload.notification = notification;
            return(pushPayload);
        }
예제 #7
0
        /// <summary>
        /// 发送广播给老师或学生,或者All
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="title"></param>
        /// <param name="text"></param>
        /// <param name="extraId"></param>
        /// <param name="extraMemberId"></param>
        /// <param name="isProduction"></param>
        /// <returns></returns>
        public static PushPayload PushBroadcast(string[] tags, string title, string text, string parameters, bool isProduction)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();
            pushPayload.options.apns_production = isProduction;
            if (tags == null || tags.Length == 0)
            {
                pushPayload.audience = Audience.all();
            }
            else
            {
                pushPayload.audience = Audience.s_tag(tags);
            }

            var notification = new Notification().setAlert(text);

            notification.AndroidNotification = new AndroidNotification();
            notification.AndroidNotification.setTitle(title);
            notification.AndroidNotification.AddExtra("params", parameters);

            notification.IosNotification = new IosNotification();
            notification.IosNotification.setCategory(title);
            notification.IosNotification.incrBadge(1);
            notification.IosNotification.AddExtra("params", parameters);

            pushPayload.notification = notification.Check();

            return(pushPayload);
        }
예제 #8
0
        /// <summary>
        /// 推送消息给特定标签用户
        /// </summary>
        /// <param name="request">request.PushUsers 以,分隔的多个标签</param>
        /// <returns></returns>
        public SnsResponse JpushSendToTag(SnsRequest request)
        {
            JpushLog _model = new JpushLog();

            _model.CreateTime = DateTime.Now;
            _model.PushId     = request.UserId;
            _model.IsToAll    = 0;
            _model.BePushId   = request.PushUsers;
            _model.PushMsg    = request.PushMsg;
            if (request.PushExtras != null)
            {
                _model.ParamString = request.PushExtras.ToString();
            }
            _jpushLog.Insert(_model);

            PushPayload pushPayload = GetPushPayload(request);
            var         userlist    = request.PushUsers.Split(',');

            pushPayload.audience = Audience.s_tag(userlist);

            var         result   = JPushClient.SendPush(pushPayload);
            SnsResponse response = new SnsResponse();

            response.JpushMsgId = result.msg_id;
            return(response);
        }
예제 #9
0
        /// <summary>
        /// 极光推送方法
        /// </summary>
        /// <param name="model"></param>
        public static void PushMessage(JPushModel model)
        {
            try
            {
                string appKey       = "";
                string masterSecret = "";
                if (model.TagId == 0)                          //C端
                {
                    appKey       = "dce902893245e99461b9a5c8"; // Your App Key from JPush
                    masterSecret = "fdc95d37d67c9472ad4e0e96"; // Your Master Secret from JPush
                }
                else if (model.TagId == 1)                     //B端
                {
                    appKey       = "d794d51f2ffaf5de42001c4b"; // Your App Key from JPush
                    masterSecret = "03f956afaaeb086481aa3b7c"; // Your Master Secret from JPush
                }
                JPushClient client   = new JPushClient(appKey, masterSecret);
                Audience    audience = null;
                if (model.PushType == 0)
                {
                    //0:标签,因为一个应用只能有一个标签,现有支付已经使用,其它应用请使用别名
                    audience         = Audience.s_alias(model.RegistrationId);
                    model.ContentKey = "Content";
                }
                if (model.PushType == 1)
                {
                    //1:别名
                    audience = Audience.s_tag(model.RegistrationId);
                }
                PushPayload pushPayload = new PushPayload();
                pushPayload.platform = Platform.android_ios();
                pushPayload.audience = audience;
                Notification notification = new Notification().setAlert(model.Alert);//不需要写弹出内容
                notification.AndroidNotification = new AndroidNotification().setTitle(model.Title);
                notification.IosNotification     = new IosNotification().setAlert(model.Alert).setBadge(1).setSound(string.Concat(model.ContentKey, ":", model.Content));
                if (!string.IsNullOrEmpty(model.Content))
                {
                    //notification.IosNotification = new IosNotification().setAlert(model.Alert).setBadge(1).setSound("YourSound").AddExtra(model.ContentKey, model.Content);
                    notification.AndroidNotification = new AndroidNotification().AddExtra(model.ContentKey, model.Content);
                }

                pushPayload.notification = notification.Check();
                var response = client.SendPush(pushPayload);
                if (!response.isResultOK())
                {
                    LogHelper.LogWriter("推送失败", response.msg_id);
                }
                else
                {
                    LogHelper.LogWriter("推送成功", response.msg_id);
                }
            }
            catch (Exception ex)
            {
                string parm = string.Concat("推送异常,参数:tagId", model.TagId, ",RegistrationId:", model.RegistrationId);
                LogHelper.LogWriter(ex, parm);
            }
        }
예제 #10
0
        //public DefaultResult addDeviceAlias(String registrationId, String alias)
        //{
        //    String mobile = null;
        //    HashSet<String> tagsToAdd = null;
        //    HashSet<String> tagsToRemove = null;
        //    return updateDevice(registrationId, alias, mobile, tagsToAdd, tagsToRemove);
        //}
        #endregion

        #region 推送给多个别名:
        public static PushPayload PushObject_alias_Alert(string strPush, string[] aliasId)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform     = Platform.all(); //推送平台
            pushPayload.audience     = Audience.s_tag(aliasId);
            pushPayload.notification = new Notification().setAlert(strPush);
            return(pushPayload);
        }
예제 #11
0
        public static PushPayload PushObject_ios_audienceMore_messageWithExtras()
        {
            var pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();
            pushPayload.audience = Audience.s_tag("tag1", "tag2");
            pushPayload.message  = Message.content(MSG_CONTENT).AddExtras("from", "JPush");
            return(pushPayload);
        }
예제 #12
0
        public static PushPayload PushObject_Android_Tag_AlertWithTitle(string tag, string title, string alert)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform     = Platform.android();
            pushPayload.audience     = Audience.s_tag(tag);
            pushPayload.notification = Notification.android(alert, title);
            return(pushPayload);
        }
예제 #13
0
        public static PushPayload PushObject_Android_Tag_AlertWithTitle()
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform     = Platform.android();
            pushPayload.audience     = Audience.s_tag("tag1");
            pushPayload.notification = Notification.android(ALERT, TITLE);
            return(pushPayload);
        }
예제 #14
0
        /// <summary>
        /// 推送消息给拥有特定“标签”的用户群
        /// </summary>
        /// <returns></returns>
        public static bool PushObject_Android_Tag_AlertWithTitle(string alert, string title, params string[] tags)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform     = Platform.android();
            pushPayload.audience     = Audience.s_tag(tags);
            pushPayload.notification = Notification.android(alert, title);

            return(SendPush(pushPayload));
        }
        public static PushPayload PushObject_apns_production_options()
        {
            var pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();
            pushPayload.audience = Audience.s_tag("tag1", "tag2");
            pushPayload.message  = Message.content(MSG_CONTENT).AddExtras("from", "JPush");
            pushPayload.options.apns_production = false;
            return(pushPayload);
        }
예제 #16
0
        public static void Push_all_tag_message(string[] tag, string message)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();
            pushPayload.audience = Audience.s_tag(tag);
            pushPayload.message  = Message.content(message);

            Push(pushPayload);
        }
예제 #17
0
        //同时推送指定多类推送目标:在深圳或者广州,并且是 ”女“ “会员
        //Audience audience= Audience.s_tag("广州", "深圳").tag("女","会员");
        public static PushPayload PushObject_tags_tag_and(string[] selects, string[] selects1, string content)
        {
            var pushPayload = new PushPayload();

            pushPayload.platform     = Platform.android();
            pushPayload.audience     = Audience.s_tag(selects).tag(selects1);
            pushPayload.message      = Message.content(content).AddExtras("Tag", "2").AddExtras("CompanyTag", "1");
            pushPayload.notification = Notification.android(ALERT, TITLE);
            return(pushPayload);
        }
예제 #18
0
        /// <summary>
        /// 发送推送
        /// </summary>
        /// <param name="alert">推送内容</param>
        /// <param name="MemberIds">推送到的用户用逗号分隔, 如果留空则为全部用户</param>
        /// <param name="MerId">商家ID</param>
        public void SendPush(string alert, string MemberIds, string eventStr, decimal MerId, string[] tag)
        {
            string[] sa = { "JPushAppKey", "JPushMasterSecret" };

            Dictionary <string, string> MerConfig = BLL.StaticBLL.MerConfig(MerId, sa);

            JPushClient client = new JPushClient(MerConfig["JPushAppKey"], MerConfig["JPushMasterSecret"]);

            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.all();
            var notification = new Notification().setAlert(alert);
            AndroidNotification androidNotification = new AndroidNotification();
            IosNotification     iosNotification     = new IosNotification();
            Options             options             = new Options();

            options.apns_production = true; //生产环境的

            pushPayload.options = options;
            androidNotification.AddExtra("eventStr", eventStr);
            iosNotification.AddExtra("eventStr", eventStr);
            notification.setAndroid(androidNotification);
            notification.setIos(iosNotification);
            if (MemberIds.Trim() != "")
            {
                //如果不为空,说明指定了MemberId
                string[] MemberArray = MemberIds.Split(',');

                pushPayload.audience = Audience.s_alias(MemberArray); //推送设备对象,表示一条推送可以被推送到那些设备,确认推送设备的对象,JPush提供了多种方式,比如:别名,标签,注册id,分群,广播等。
            }

            else if (tag != null)
            {
                if (tag.Length > 0)
                {
                    pushPayload.audience = Audience.s_tag(tag);  //按照标签推送
                }
            }

            else
            {
                pushPayload.audience = Audience.all();//推送设备对象,表示一条推送可以被推送到那些设备,确认推送设备的对象,JPush提供了多种方式,比如:别名,标签,注册id,分群,广播等。
            }

            pushPayload.notification = notification;



            pushPayload.message = Message.content("msg")
                                  .AddExtras("DoEvent", "GetNewMsgNum()");      //如果不加一条自定义消息的话, android是不会触发监听事件的.但是IOS可以



            var result = client.SendPush(pushPayload);
        }
예제 #19
0
        public static void Push_all_tag_alert_message(string alert, string message, params string[] tag)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform     = Platform.android_ios();
            pushPayload.audience     = Audience.s_tag(tag);
            pushPayload.notification = new Notification().setAlert(alert);
            pushPayload.message      = Message.content(message);

            Push(pushPayload);
        }
예제 #20
0
        public static PushPayload PushObject_Android_Tag_AlertWithTitle(string ALERT, string TITLE)
        {
            PushPayload pushPayload = new PushPayload()
            {
                platform     = Platform.android(),
                audience     = Audience.s_tag("tag1"),
                notification = Notification.android(ALERT, TITLE)
            };

            return(pushPayload);
        }
예제 #21
0
        public static PushPayload PushObject_Android_Tag_AlertWithTitle(User user)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android();
            // pushPayload.audience = Audience.all();
            pushPayload.audience     = Audience.s_tag("0000000008");
            pushPayload.notification = Notification.android(user.MessageAlert, user.MessageTitle);

            return(pushPayload);
        }
예제 #22
0
        /// <summary>
        /// 推送消息给特定标签用户
        /// </summary>
        /// <param name="request">request.PushUsers 以,分隔的多个标签</param>
        /// <returns></returns>
        public SnsResponse JpushSendToTag(SnsRequest request)
        {
            PushPayload pushPayload = GetPushPayload(request);
            var         userlist    = request.PushUsers.Split(',');

            pushPayload.audience = Audience.s_tag(userlist);

            var         result   = JPushClient.SendPush(pushPayload);
            SnsResponse response = new SnsResponse();

            response.JpushMsgId = result.msg_id;
            return(response);
        }
예제 #23
0
        /// <summary>
        /// 构建推送对象:平台是 Android,目标是 tag 为 "tag1" 的设备
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        private static PushPayload PushObject_Android_Tag_AlertWithTitle(MessageEntity message, params string[] tags)
        {
            //构建Message对象

            PushPayload pushPayload = new PushPayload()
            {
                platform     = Platform.android(),
                audience     = Audience.s_tag(tags),
                notification = Notification.android(message.Alert, message.Title),
                message      = Message.content(message.Content.ToJson()),
            };

            return(pushPayload);
        }
예제 #24
0
 /// <summary>
 /// 极光消息推送
 /// </summary>
 /// <param name="tagId">来源标识(1=B端/0=C端)</param>
 /// <param name="title">提示title</param>
 /// <param name="alert"></param>
 /// <param name="content"></param>
 /// <param name="RegistrationId">商户id  注册ID 数组。多个注册ID之间是 OR 关系,即取并集。 设备标识。一次推送最多 1000 个。 </param>
 /// <param name="city">城市 </param>
 public static void PushMessage(int tagId, string title, string alert, string content, string RegistrationId, string city)
 {
     try
     {
         string appKey       = "";
         string masterSecret = "";
         if (tagId == 0)                                //C端
         {
             appKey       = "dce902893245e99461b9a5c8"; // Your App Key from JPush
             masterSecret = "fdc95d37d67c9472ad4e0e96"; // Your Master Secret from JPush
         }
         else if (tagId == 1)                           //B端
         {
             appKey       = "d794d51f2ffaf5de42001c4b"; // Your App Key from JPush
             masterSecret = "03f956afaaeb086481aa3b7c"; // Your Master Secret from JPush
         }
         JPushClient client   = new JPushClient(appKey, masterSecret);
         Audience    audience = null;
         if (tagId == 0)  //C端
         {
             audience = Audience.s_tag_and(city.Trim());
         }
         else if (tagId == 1 && !string.IsNullOrEmpty(RegistrationId)) //B端
         {
             audience = Audience.s_tag(RegistrationId);
         }
         PushPayload pushPayload = new PushPayload();
         pushPayload.platform = Platform.android_ios();
         pushPayload.audience = audience;
         Notification notification = new Notification().setAlert(alert);
         notification.AndroidNotification = new AndroidNotification().setTitle(title);
         notification.IosNotification     = new IosNotification().setAlert(alert).setBadge(1).setSound("YourSound");
         pushPayload.notification         = notification.Check();
         var response = client.SendPush(pushPayload);
         if (!response.isResultOK())
         {
             LogHelper.LogWriter("推送失败", response.msg_id);
         }
         else
         {
             LogHelper.LogWriter("推送成功", response.msg_id);
         }
     }
     catch (Exception ex)
     {
         string parm = string.Concat("推送异常,参数:tagId", tagId, ",RegistrationId:", RegistrationId);
         LogHelper.LogWriter(ex, parm);
     }
 }
예제 #25
0
        /// <summary>
        /// 发送通知(s_tag 定位)
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="appKey">appkey</param>
        /// <param name="masterSecret">主密钥</param>
        public static void sendNotificToUsers(string msg, List <string> userId, string appKey = "9b725db3484eceb1abab684a", string masterSecret = "7a6081367b0d0dda83a8b969")
        {
            JPushClient client      = new JPushClient(appKey, masterSecret);
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform     = Platform.android_ios();
            pushPayload.audience     = Audience.s_tag(userId.ToArray());
            pushPayload.notification = new Notification().setAlert(msg).setIos(new IosNotification().autoBadge().setSound("happy").AddExtra("form", "JPush"));

            try
            {
                var result = client.SendPush(pushPayload);
            }
            catch
            {
            }
        }
예제 #26
0
        public void sendByTagMore()
        {
            //PushPayload payload = PushPayload.newBuilder()
            //        .setPlatform(Platform.all())
            //        .setAudience(Audience.tag(TAG1, TAG2))
            //        .setNotification(Notification.alert(ALERT))
            //        .build();

            PushPayload payload = new PushPayload();

            payload.platform     = Platform.all();
            payload.audience     = Audience.s_tag(TAG1, TAG2);
            payload.notification = new Notification().setAlert(ALERT);
            var result = _client.SendPush(payload);

            Assert.IsTrue(result.isResultOK());
        }
예제 #27
0
        public static PushPayload PushObject_android_and_ios()
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();
            var audience = Audience.s_tag("tag1");

            pushPayload.audience = audience;
            var notification = new Notification().setAlert("alert content");

            notification.AndroidNotification = new AndroidNotification().setTitle("Android Title");
            notification.IosNotification     = new IosNotification();
            notification.IosNotification.incrBadge(1);
            notification.IosNotification.AddExtra("extra_key", "extra_value");
            pushPayload.notification = notification.Check();
            return(pushPayload);
        }
예제 #28
0
        /// <summary>
        /// 发送通知(s_tag 定位)
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="appKey">appkey</param>
        /// <param name="masterSecret">主密钥</param>
        public static void sendNotificToUsers(string msg, List <string> userId, string appKey = "a91410f29fd95fe5800fff9a", string masterSecret = "2bd0c5a1418c05f97ae9048a")
        {
            JPushClient client      = new JPushClient(appKey, masterSecret);
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform     = Platform.android_ios();
            pushPayload.audience     = Audience.s_tag(userId.ToArray());
            pushPayload.notification = new Notification().setAlert(msg).setIos(new IosNotification().autoBadge().setSound("happy").AddExtra("form", "JPush"));

            try
            {
                var result = client.SendPush(pushPayload);
            }
            catch (Exception ex)
            {
            }
        }
예제 #29
0
        /// <summary>
        /// 获取推送目标
        /// </summary>
        private Audience GetAudience()
        {
            Audience audience = null;

            switch (PushModel.Audience.Category)
            {
            // 标签
            case PushAudienceCategory.Tags:
                audience = Audience.s_tag(PushModel.Audience.Objects.ToArray());
                break;

            // 别名
            case PushAudienceCategory.Alias:
                audience = Audience.s_alias(PushModel.Audience.Objects.ToArray());
                break;

            // RegistrationID
            case PushAudienceCategory.RegistrationID:
                audience = Audience.s_registrationId(PushModel.Audience.Objects.ToArray());
                break;

            // 群组,暂未支持
            case PushAudienceCategory.UserGroup:
                return(null);

            // 广播
            default:
                return(Audience.all());
            }

            if (PushModel.Audience.SecondObjects != null && PushModel.Audience.SecondObjects.Objects.Count > 0)
            {
                // 二级关联取交集
                if (PushModel.Audience.SecondObjects.Category == PushAudienceSecondCategory.TagsAnd)
                {
                    audience.tag_and(PushModel.Audience.SecondObjects.Objects.ToArray());
                }

                // 二级关联取非,当前SDK暂不支持
                //if (PushModel.Audience.SecondObjects.Category == PushAudienceSecondCategory.TagsNot)
                //{

                //}
            }
            return(audience);
        }
예제 #30
0
        public static bool PushObject_ios_audienceMore_messageWithExtras(string message, Dictionary <string, string> extraParameters, params string[] tags)
        {
            var pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();
            pushPayload.audience = Audience.s_tag(tags);
            pushPayload.message  = Message.content(message);
            //添加额外的数据
            if (extraParameters != null && extraParameters.Count > 0)
            {
                foreach (var dicItem in extraParameters)
                {
                    pushPayload.notification.IosNotification.AddExtra(dicItem.Key, dicItem.Value);
                }
            }

            return(SendPush(pushPayload));
        }