예제 #1
0
        private static PushPayload CreatePushObject(string msg, List <string> userIds, Message message = null)
        {
            var result = GetRegIdList(userIds);

            if (result.IsSuccess && result.Entities.IsNotNullOrEmpty())
            {
                HashSet <string> hash = new HashSet <string>();
                foreach (var obj in result.Entities)
                {
                    var user = obj as MsgReg;
                    hash.Add(user.RegId);
                }

                PushPayload pushPayload = new PushPayload();
                pushPayload.platform = Platform.android_ios();
                pushPayload.audience = Audience.s_registrationId(hash);
                if (!string.IsNullOrEmpty(msg))
                {
                    pushPayload.notification = new Notification().setAlert(msg);
                }
                if (message != null)
                {
                    pushPayload.message = message;
                }
                return(pushPayload);
            }

            return(null);
        }
예제 #2
0
        private static PushPayload CreateNotificationObject(string msg, Dictionary <string, object> extras, List <string> userIds)
        {
            var result = GetRegIdList(userIds);

            if (result.IsSuccess && result.Entities.IsNotNullOrEmpty())
            {
                HashSet <string> hash = new HashSet <string>();
                foreach (var obj in result.Entities)
                {
                    var user = obj as MsgReg;
                    hash.Add(user.RegId);
                }

                PushPayload pushPayload = new PushPayload();
                pushPayload.platform = Platform.android_ios();
                pushPayload.audience = Audience.s_registrationId(hash);
                Notification notification = new Notification();
                notification.AndroidNotification = new AndroidNotification();
                notification.IosNotification     = new IosNotification();
                notification.AndroidNotification.setAlert(msg);
                notification.IosNotification.setAlert(msg);
                notification.IosNotification.setContentAvailable(true);
                foreach (var item in extras)
                {
                    notification.AndroidNotification.AddExtra(item.Key, item.Value.ToString());
                    notification.IosNotification.AddExtra(item.Key, item.Value.ToString());
                }

                pushPayload.notification = notification;

                return(pushPayload);
            }

            return(null);
        }
예제 #3
0
        public static PushPayload PushObject_all_registrationId_alert(string Msg, string RegId, Dictionary <string, object> extras)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.all();
            string[] arrregid = RegId.Split(',');
            pushPayload.audience = Audience.s_registrationId(arrregid); //Audience.s_alias("alias1");


            pushPayload.notification = new Notification();//.setAlert(Msg);


            pushPayload.notification.AndroidNotification = new push.notification.AndroidNotification();
            pushPayload.notification.IosNotification     = new push.notification.IosNotification();
            pushPayload.notification.AndroidNotification.setAlert(Msg);
            pushPayload.notification.AndroidNotification.setBuilderID(1);
            pushPayload.notification.IosNotification.setAlert(Msg);
            if (extras != null)
            {
                foreach (var item in extras)
                {
                    pushPayload.notification.AndroidNotification.extras.Add(item.Key, item.Value);
                    pushPayload.notification.IosNotification.extras.Add(item.Key, item.Value);
                }
            }
            pushPayload.notification.IosNotification.setSound("default");
            pushPayload.options.apns_production = true;
            pushPayload.platform             = Platform.all();
            pushPayload.message              = Message.content(Msg);
            pushPayload.message.content_type = "text";
            pushPayload.notification.setExtras(null);
            return(pushPayload);
        }
예제 #4
0
        /// <summary>
        /// 推送配置
        /// </summary>
        /// <param name="registerid">推送列表(设备别号)</param>
        /// <param name="pushTitle">标题</param>
        /// <param name="pushlist">推送附加参数</param>
        /// <returns></returns>
        private static PushPayload PushObject_RegisterID(HashSet <string> registerid, string pushTitle, List <Push> pushList)
        {
            PushPayload pushPayload = new PushPayload();

            //设置推送平台
            pushPayload.platform = Platform.android_ios();                //设置为安卓
            //设置受众
            pushPayload.audience = Audience.s_registrationId(registerid); //设置推送目标
            ////通知获取
            //pushPayload.notification = Notification.android("55555", pushTitle);
            ////通知获取
            //pushPayload.notification = Notification.ios(pushTitle);
            var notification = new Notification().setAlert(pushTitle);//推送消息内容

            notification.AndroidNotification = new AndroidNotification();
            notification.IosNotification     = new IosNotification();
            //if (pushList.Count>0)
            //{
            //    foreach (var model in pushList)
            //    {
            //        notification.AndroidNotification.AddExtra(model.Key, model.Value);//Android推送消息
            //        notification.IosNotification.AddExtra(model.Key, model.Value);//IOS推送消息
            //        notification.IosNotification.setSound("happy");
            //        pushPayload.notification = notification.Check();
            //    }
            //}
            //else
            //{
            //    pushPayload.notification = Notification.android("这是标题", pushTitle);
            //}
            return(pushPayload);
        }
예제 #5
0
        /// <summary>
        ///  推送到单个App Android设备
        /// </summary>
        /// <param name="registrationId"></param>
        /// <param name="MsgContent"></param>
        /// <returns></returns>
        public static PushPayload PushObject_AndroidMsg(string registrationId, string MsgContent)
        {
            string[] register = registrationId.Split(',');


            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android();
            pushPayload.audience = Audience.s_registrationId(register);
            var notification = new AndroidNotification().setAlert(MsgContent);


            var message = Message.content(MsgContent);

            message.content_type = "text";
            message.msg_content  = "aaaaaaaaaaa";
            message.setTitle("aaaaa");

            pushPayload.message = message;


            pushPayload.notification            = new Notification().setAndroid(notification);
            pushPayload.options.apns_production = true;
            return(pushPayload);
        }
예제 #6
0
        /// <summary>
        /// 推送消息
        /// </summary>
        /// <param name="notificationTitle">通知title</param>
        /// <param name="content">通知内容</param>
        /// <param name="message">消息内容</param>
        /// <param name="deviceTypes">推送平台</param>
        /// <param name="pushId">用户标识</param>
        /// <param name="keyValueParams">参数</param>
        /// <returns>推送消息ID</returns>
        public static long SendPush(
            string notificationTitle,
            string content,
            string message,
            DeviceType deviceTypes,
            string pushId,
            Dictionary <string, string> keyValueParams)
        {
            PushPayload pushPayload = new PushPayload();

            var platformNotification = GetPlatformNotification(deviceTypes, notificationTitle, content, keyValueParams);

            pushPayload.platform     = platformNotification.Item1;
            pushPayload.notification = platformNotification.Item2;

            Audience audience = string.IsNullOrWhiteSpace(pushId)
                ?
                                Audience.all()
                : Audience.s_registrationId(pushId);

            pushPayload.audience = audience;

            if (!string.IsNullOrWhiteSpace(message))
            {
                pushPayload.message = Message.content(message);
            }

            //true 表示推送生产环境, false表示要推送开发环境;
            pushPayload.ResetOptionsApnsProduction(isRelease);

            var result = _client.SendPush(pushPayload);

            return(result.msg_id);
        }
예제 #7
0
        public static PushPayload PushObject_android_with_options()
        {
            PushPayload pushPayload = new PushPayload()
            {
                platform = Platform.android_ios()
            };

            pushPayload.audience = Audience.s_registrationId();

            AndroidNotification androidnotification = new AndroidNotification();

            androidnotification.setAlert("Push Object android with options");
            androidnotification.setBuilderID(3);
            androidnotification.setStyle(1);
            androidnotification.setAlert_type(1);
            androidnotification.setBig_text("big text content");
            androidnotification.setInbox("JSONObject");
            androidnotification.setBig_pic_path("picture url");
            androidnotification.setPriority(0);
            androidnotification.setCategory("category str");

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

            notification.AndroidNotification = androidnotification;
            notification.IosNotification     = new IosNotification();
            notification.IosNotification.incrBadge(1);
            notification.IosNotification.AddExtra("extra_key", "extra_value");
            pushPayload.notification = notification.Check();
            return(pushPayload);
        }
예제 #8
0
        public static PushPayload PushObject_registration_Alert(string strPush, string[] registrationId)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform     = Platform.all(); //推送平台
            pushPayload.audience     = Audience.s_registrationId(registrationId);
            pushPayload.notification = new Notification().setAlert(strPush);
            return(pushPayload);
        }
예제 #9
0
        public PushPayload PushObject_ios_audienceMore_messageWithExtras(Msg msg)
        {
            var pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();
            //pushPayload.audience = Audience.s_tag("tag1", "tag2");
            pushPayload.audience = Audience.s_registrationId(msg.users.ToArray());
            pushPayload.message  = cn.jpush.api.push.mode.Message.content(msg.content).setContentType(msg.action).setTitle(msg.title).AddExtras("from", "JPush");
            return(pushPayload);
        }
예제 #10
0
        /// <summary>
        /// 极光推送主体 Android
        /// </summary>
        /// <param name="registrationId"></param>
        /// <param name="alert"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        private PushPayload PushObject(string[] registrationId, string alert, string title)
        {
            var pushPayload = new PushPayload();

            pushPayload.platform     = Platform.all();
            pushPayload.audience     = Audience.s_registrationId(registrationId);
            pushPayload.notification = new Notification()
                                       .setAlert(alert)
                                       .setAndroid(new AndroidNotification().setTitle(title));
            return(pushPayload);
        }
예제 #11
0
        public void sendByRegistrationID()
        {
            PushPayload payload = new PushPayload();

            payload.platform     = Platform.all();
            payload.audience     = Audience.s_registrationId(REGISTRATION_ID1);
            payload.notification = new Notification().setAlert(ALERT);
            var result = _client.SendPush(payload);

            Assert.IsTrue(result.isResultOK());
        }
예제 #12
0
        public static PushPayload PushObject_registrationId(string ALERT)
        {
            PushPayload pushPayload = new PushPayload()
            {
                platform = Platform.all()
            };

            string[] rId = new string[] { "registrationId1" };
            pushPayload.audience     = Audience.s_registrationId(rId);
            pushPayload.notification = new Notification().setAlert(ALERT);
            return(pushPayload);
        }
예제 #13
0
        /// <summary>
        /// 极光推送主体 Android and  IOS
        /// </summary>
        /// <param name="registrationId"></param>
        /// <param name="alert"></param>
        /// <returns></returns>
        private PushPayload PushObject(string[] registrationId, string alert)
        {
            var pushPayload = new PushPayload
            {
                platform     = Platform.all(),
                audience     = Audience.s_registrationId(registrationId),
                notification = new Notification()
                               .setAlert(alert).setIos(new IosNotification().incrBadge(1))
            };

            return(pushPayload);
        }
예제 #14
0
        /// <summary>
        /// 推送到单个App  IOS设备
        /// </summary>
        /// <param name="registrationId"></param>
        /// <param name="MsgContent"></param>
        /// <returns></returns>
        public static PushPayload PushObject_IOSMsg(string registrationId, string MsgContent)
        {
            string[]    register    = registrationId.Split(',');
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.ios();
            pushPayload.audience = Audience.s_registrationId(register);
            var notification = new IosNotification().setAlert(MsgContent);

            pushPayload.notification            = new Notification().setIos(notification);
            pushPayload.options.apns_production = true;
            return(pushPayload);
        }
예제 #15
0
파일: JPush.cs 프로젝트: junprof/EC
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="Msg">消息</param>
        /// <param name="RegId">关联设备标识</param>
        /// <param name="extras">附带信息</param>
        /// <param name="type">1 别名(默认)  2 registrationid</param>
        /// <returns></returns>
        public bool SendPush(string Msg, string RegId, Dictionary <string, object> extras, int type = 1)
        {
            bool        res         = false;
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.all();
            string[] arrregid = RegId.Split(',');
            //Audience.s_alias("alias1");
            if (type == 1)
            {
                pushPayload.audience = Audience.s_alias(arrregid);
            }
            else if (type == 2)
            {
                pushPayload.audience = Audience.s_registrationId(arrregid);
            }

            pushPayload.notification = new Notification();//.setAlert(Msg);


            pushPayload.notification.AndroidNotification = new cn.jpush.api.push.notification.AndroidNotification();
            pushPayload.notification.IosNotification     = new cn.jpush.api.push.notification.IosNotification();
            pushPayload.notification.AndroidNotification.setAlert(Msg);
            pushPayload.notification.AndroidNotification.setBuilderID(1);
            pushPayload.notification.IosNotification.setAlert(Msg);
            if (extras != null)
            {
                foreach (var item in extras)
                {
                    pushPayload.notification.AndroidNotification.extras.Add(item.Key, item.Value);
                    pushPayload.notification.IosNotification.extras.Add(item.Key, item.Value);
                }
            }
            pushPayload.notification.IosNotification.setSound("dianAnBao.wav");
            pushPayload.options.apns_production = true;
            pushPayload.platform             = Platform.all();
            pushPayload.message              = Message.content(Msg);
            pushPayload.message.content_type = "text";
            var result = client.SendPush(pushPayload);

            if (result.ResponseResult.responseCode == System.Net.HttpStatusCode.OK)
            {
                res = true;
            }
            else
            {
                res = false;
                Log.Warn(JsonHelper2.Serialize(result));
            }
            return(res);
        }
예제 #16
0
        /// <summary>
        /// 极光推送(ios和安卓)
        /// </summary>
        /// <param name="push">系统消息推送</param>
        /// <param name="platform"></param>
        public static void Jpush(SystemPushMongo push, Constants.DataType.Platform platform)
        {
            var customerId = push.CustomerId;
            var title      = push.Title;
            var content    = push.Content;
            var client     = new JPushClient(Constants.Jpush.AppKey, Constants.Jpush.MasterSecret);

            var list = CusJpServer.GetListByCusId(customerId);

            // android -->01  iod -->02
            var pushList = list.Where(en => en.Platform.Equals(EnumOperation.Description(platform))).ToArray();


            if (!pushList.Any())
            {
                return;
            }

            if (platform == Constants.DataType.Platform.Android)
            {
                var androidHashSet = new HashSet <string>();
                foreach (var customerJPush in pushList)
                {
                    androidHashSet.Add(customerJPush.RegId);
                }
                var payload = new PushPayload(Platform.android(), Audience.s_registrationId(androidHashSet),
                                              Notification.android(title, content));

                client.SendPush(payload);
            }
            else
            {
                var iosHashSet = new HashSet <string>();
                foreach (var customerJPush in pushList)
                {
                    iosHashSet.Add(customerJPush.RegId);
                }

#if DEBUG
                var payload = new PushPayload(Platform.ios(), Audience.s_registrationId(iosHashSet), Notification.ios(content), null, new Options());
#endif
#if !DEBUG
                PushPayload payload = new PushPayload(Platform.ios(), Audience.s_registrationId(iosHashSet), Notification.ios(content));
#endif
                client.SendPush(payload);
            }
        }
예제 #17
0
        /// <summary>
        /// 发送推送
        /// </summary>
        /// <param name="androidTitle">通知栏标题</param>
        /// <param name="alert">通知消息</param>
        /// <param name="AppType">APP类型 0:业主APP  1:物业APP</param>
        /// <param name="registrationIds">设备Id集合数组</param>
        /// <returns></returns>
        public static bool SendPush(string androidTitle, string alert, int AppType, params string[] registrationIds)
        {
            try
            {
                //通知信息
                var notification = new Notification().setAlert(alert);
                notification.AndroidNotification = new AndroidNotification().setTitle(androidTitle);

                if (registrationIds.Count() > 0)
                {
                    PushPayload pushPayload = new PushPayload();
                    //设置平台信息:全部
                    pushPayload.platform = Platform.all();
                    pushPayload.options.apns_production = true;
                    //推送目标:设备Id集
                    pushPayload.audience = Audience.s_registrationId(registrationIds);

                    notification.IosNotification = new IosNotification();
                    notification.IosNotification.incrBadge(1).setSound("sound");
                    notification.IosNotification.AddExtra("Title", androidTitle);
                    //推送消息
                    pushPayload.notification = notification.Check();

                    //根据客户端类型选择相应的KEY推送
                    if (AppType == ConstantParam.MOBILE_TYPE_OWNER)
                    {
                        JPushClient client = new JPushClient(ConstantParam.APP_KEY, ConstantParam.MASTER_SECRET);
                        client.SendPush(pushPayload);
                    }
                    else if (AppType == ConstantParam.MOBILE_TYPE_PROPERTY)
                    {
                        JPushClient client = new JPushClient(ConstantParam.PROPERTY_APP_KEY, ConstantParam.PROPERTY_MASTER_SECRET);
                        client.SendPush(pushPayload);
                    }
                    else if (AppType == ConstantParam.MOBILE_TYPE_SHOP)
                    {
                        JPushClient client = new JPushClient(ConstantParam.SHOP_APP_KEY, ConstantParam.SHOP_MASTER_SECRET);
                        client.SendPush(pushPayload);
                    }
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #18
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);
        }
예제 #19
0
        public PushPayload PushObject_All_All_Alert()
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android();
            pushPayload.audience = Audience.s_registrationId("1507bfd3f7f0af7925b");

            //Message sms_message = new Message();
            //sms_message.title = "标题";
            //sms_message.msg_content = "内容";

            pushPayload.message = Message.content("标2222题");


            pushPayload.notification = new Notification().setAlert("了开始了减肥收到了快捷方式的浪2222222费");

            return(pushPayload);
        }
예제 #20
0
        /// <summary>
        /// 推送信息到指定设备
        /// </summary>
        /// <param name="userRIds">推送给多个设备id,参数为:"xxxxx1","xxxxxx2","xxxxxx3"</param>
        /// <param name="msg">推送信息</param>
        /// <returns>返回操作结果</returns>
        public static String Send(String[] userRIds, String msg)
        {
            String      r           = String.Empty;
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();
            pushPayload.audience = Audience.s_registrationId(userRIds);
            //pushPayload.audience = Audience.s_tag_and("tag1", "tag_all");
            var notification = new Notification();

            notification.IosNotification = new IosNotification().setAlert(msg).setBadge(5).setSound("happy").AddExtra("from", "JPush");
            pushPayload.notification     = notification;

            JPushClient client = new JPushClient(app_key, master_secret);
            var         result = client.SendPush(pushPayload);

            return(r);
        }
예제 #21
0
파일: Push.cs 프로젝트: wndayday/bex5
        public static MessageResult sendPushMessage(string registrationId, string key, string secret)
        {
            //ClientConfig config = ClientConfig.getInstance();
            //jpushClient = new JPushClient(secret, key, 3, null, config);
            jpushClient = new JPushClient(key, secret);
            PushPayload payload = new PushPayload();

            payload.platform     = Platform.all();
            payload.audience     = Audience.s_registrationId(registrationId);
            payload.notification = new Notification().setAlert("亲爱的x5外卖用户,您的订单已经配货完毕,正在运送中..");

            payload.ResetOptionsTimeToLive(86400);
            payload.ResetOptionsApnsProduction(apnsProduction);
            string        schedleTime = DateTime.Today.ToString("yyyy-MM-dd HH:mm:ss");
            MessageResult result      = jpushClient.SendPush(payload);

            return(result);
        }
예제 #22
0
        /// <summary>
        ///  向指定安卓手机推送一条
        /// </summary>
        /// <param name="registrationId">注册ID </param>
        /// <param name="Data">数据</param>
        /// <param name="TaskID">任务ID</param>
        /// <returns></returns>
        public static void PushObject_Android(string RegistrationId, string Data, string TaskID, TaskType TaskType, string Extra = "")
        {
            var pushPayload = new PushPayload();

            pushPayload.platform = Platform.android();
            pushPayload.audience = Audience.s_registrationId(RegistrationId);

            //入值发送内容,然后将任务ID作为附加ID传递过去
            Message Info = Message.content("{\"Data\":" + Data + "}").AddExtras("Operation", (int)TaskType).AddExtras("TaskID", TaskID);

            Info.title          = Extra;
            pushPayload.message = Info;
            Options Option = new Options();

            Option.time_to_live    = 0;    //如果当前用户离线,则不接收任何消息
            Option.apns_production = true; //当前所有推送都是正式环境下进行
            pushPayload.options    = Option;
            JPushClient   client = new JPushClient(AppKey, Master_Secret);
            MessageResult Result = client.SendPush(pushPayload);
        }
예제 #23
0
        public bool Push(string message, List <User> users, Dictionary <string, string> paras = null)
        {
            JPushClient client      = new JPushClient(AppKey, MasterSecret);
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform     = Platform.all();
            pushPayload.audience     = Audience.s_registrationId(users.Select(u => u.MobileDevice).ToArray());
            pushPayload.notification = new Notification().setAlert(message);
            pushPayload.notification.IosNotification     = new IosNotification().setAlert(message).autoBadge();
            pushPayload.notification.AndroidNotification = new AndroidNotification().setAlert(message);

            if (paras != null)
            {
                foreach (var para in paras)
                {
                    pushPayload.notification.IosNotification.AddExtra(para.Key, para.Value);
                    pushPayload.notification.AndroidNotification.AddExtra(para.Key, para.Value);
                }
            }

            pushPayload.options.apns_production = ApnsProduction;
            try
            {
                client.SendPush(pushPayload);
                return(true);
            }
            catch (APIRequestException e)
            {
                Logger.Error("Error response from JPush server. Should review and fix it. HTTP Status: " + e.Status +
                             "Error Code: " + e.ErrorCode + "Error Message: " + e.ErrorCode);
                return(false);
            }
            catch (APIConnectionException e)
            {
                Logger.Error(e, "消息推送失败");
                return(false);
            }
        }
예제 #24
0
        private void TimingJush(object o)
        {
            if (_j_time == null)
            {
                _j_time = new JushTiming_DAL();
            }
            if (payload == null)
            {
                payload = new PushPayload();
            }

            list = _j_time.PushTiming();
            if (list.Count > 0)
            {
                foreach (var item in list)
                {
                    long MessageID = 0;
                    int  ErrorCode = 0;
                    switch (item.SendPlatform)
                    {
                    case 1: payload.platform = Platform.android();
                        break;

                    case 2: payload.platform = Platform.ios();
                        break;

                    case 3: payload.platform = Platform.android_ios();
                        break;

                    default:
                        break;
                    }
                    switch (item.SendAudience)
                    {
                    case 0: payload.audience = Audience.all();
                        break;

                    case 1:
                        string[] tagArray = item.AudienceName.Split(',');
                        payload.audience = Audience.s_tag(tagArray);
                        break;

                    case 2: payload.audience = Audience.s_alias(item.AudienceName);
                        break;

                    case 3: payload.audience = Audience.s_registrationId(item.AudienceName);
                        break;

                    default:
                        break;
                    }
                    string strJosn = item.Extras == null ? "" : item.Extras;
                    if (strJosn.Length > 0)
                    {
                        data = strJosn.JsonToDocuments();
                        if (data.Count > 0)
                        {
                            android = new AndroidNotification();
                            ios     = new IosNotification();
                            foreach (var tt in data)
                            {
                                android.AddExtra(tt.Key, tt.Value.ToString());
                                ios.AddExtra(tt.Key, tt.Value.ToString());
                            }
                        }
                        payload.notification = new Notification().setAlert(item.Content).setAndroid(android).setIos(ios);
                    }
                    else
                    {
                        payload.notification = new Notification().setAlert(item.Content);
                    }

                    try
                    {
                        var result = client.SendPush(payload);
                        //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法
                        System.Threading.Thread.Sleep(5000);
                        MessageID = Convert.ToInt64(result.msg_id);
                        //记录日志
                        Config.PushLogAPP("APP定时发送", "所有", item.Content);
                    }
                    catch (Jpush.api.common.APIRequestException ee)
                    {
                        MessageID = ee.MsgId;
                        ErrorCode = ee.ErrorCode;


                        string.Format("\r\n>>>APP定时发送 推送异常:{0},time:{1}",
                                      ee.Message,
                                      DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                                      ).WriteLog("ERROR");
                    }

                    _j_time.PushTimingUpdateStatu(MessageID, ErrorCode, item.Id);
                    android = null;
                    ios     = null;
                }
            }
        }
예제 #25
0
 public static string doPushMessage(string title, Dictionary <string, object> extras, string[] cids = null, string sendtype = "android", string msg_content = "", int PushAPP = 1, bool IsToAll = false)
 {
     try
     {
         if (cids == null && !IsToAll)
         {
             return("没有接收用户");
         }
         PushPayload pushPayload = new PushPayload();
         //pushPayload.notification = new Notification();
         if (IsToAll)
         {
             pushPayload.audience = Audience.all();
         }
         else
         {
             pushPayload.audience = Audience.s_registrationId(cids);
         }
         pushPayload.message = Message.content(msg_content);
         //pushPayload.message.setTitle(title);
         pushPayload.message.setContentType("text");
         foreach (var item in extras)
         {
             pushPayload.message.AddExtras(item.Key, item.Value.ToString());
         }
         pushPayload.message.AddExtras("sound", "widget://res/newmessage.mp3");
         var notification = new Notification();
         notification.setAlert(msg_content);
         if (sendtype.Equals("android"))
         {
             pushPayload.platform             = Platform.android();
             notification.AndroidNotification = new AndroidNotification();
             //notification.AndroidNotification.setAlert(msg_content);
             foreach (var item in extras)
             {
                 notification.AndroidNotification.AddExtra(item.Key, item.Value.ToString());
             }
             notification.AndroidNotification.AddExtra("sound", "widget://res/newmessage.mp3");
             //pushPayload.notification = notification;
         }
         else if (sendtype.Equals("ios"))
         {
             pushPayload.platform         = Platform.ios();
             notification.IosNotification = new IosNotification();
             notification.IosNotification.setBadge(1);
             notification.IosNotification.setSound("widget://res/newmessage.mp3");
             notification.IosNotification.setAlert(msg_content);
             foreach (var item in extras)
             {
                 notification.IosNotification.AddExtra(item.Key, item.Value.ToString());
             }
             pushPayload.notification = notification;
         }
         pushPayload.options.apns_production = true;
         pushPayload.options.time_to_live    = 3600;
         var    config = new Utility.SiteConfig();
         string key    = string.Empty;
         string secret = string.Empty;
         if (PushAPP == 1)
         {
             key    = config.JPushKey_User;
             secret = config.JPushMasterSecret_User;
         }
         else if (PushAPP == 2)
         {
             key    = config.JPushKey_Customer;
             secret = config.JPushMasterSecret_Customer;
         }
         else if (PushAPP == 3)
         {
             key    = config.JPushKey_Business;
             secret = config.JPushMasterSecret_Business;
         }
         var client   = new JPushClient(key, secret);
         var response = client.SendPush(pushPayload);
         return("code:" + response.ResponseResult.responseCode + " content:" + response.ResponseResult.responseContent);
     }
     catch (Exception ex)
     {
         Utility.LogHelper.WriteError("Jpush.JpushAPI", "PushMessage", ex);
         return(ex.Message);
     }
 }
예제 #26
0
        /// <summary>
        /// 占用车辆超时还车通知
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                int minutes_timeout = 30;
                int.TryParse(context.JobDetail.JobDataMap.Get("minutes_timeout").ToString(), out minutes_timeout);
                int ios_production = 0;
                int.TryParse(context.JobDetail.JobDataMap.Get("ios_production").ToString(), out ios_production);

                List <string> saasList = ConfigHelper.GetSaasList();
                foreach (string saas in saasList)
                {
                    try
                    {
                        MyWorkerRequest.CreateHttpContext(saas, "", "");

                        APPKEY       = SiteHelper.GetAppsetString("JPush_AppKey");
                        MASTERSECRET = SiteHelper.GetAppsetString("JPush_MasterSecret");

                        JPushClient pushClient = new JPushClient(APPKEY, MASTERSECRET);

                        OrdersManager om = new OrdersManager();
                        DataTable     dt = om.GetVehicleReturnOrders(minutes_timeout);
                        foreach (DataRow dr in dt.Rows)
                        {
                            string clientid = string.Empty;
                            if (dr["PushID"] != DBNull.Value)
                            {
                                clientid = dr["PushID"].ToString();
                            }
                            string licenseNumber = dr["LicenseNumber"].ToString();
                            if (!string.IsNullOrEmpty(clientid))
                            {
                                PushMessage pushMessage = new PushMessage();
                                pushMessage.code    = "0101";
                                pushMessage.message = "您当前占用的车辆已锁车停留较长时间,如不再使用请及时还车,避免不必要的浪费哟!";

                                PushPayload payload = new PushPayload();
                                payload.platform                = Platform.all();
                                payload.audience                = Audience.s_registrationId(new string[] { clientid });
                                payload.notification            = new Notification().setAlert(pushMessage.message);
                                payload.message                 = Message.content(Newtonsoft.Json.JsonConvert.SerializeObject(pushMessage));
                                payload.options                 = new Options();
                                payload.options.time_to_live    = 86400 * 10;
                                payload.options.apns_production = ios_production == 1 ? true : false;

                                MessageResult pushResult = pushClient.SendPush(payload);
                                if (pushResult.isResultOK())
                                {
                                    Logger.Info("车辆还车通知:" + pushResult + ",车辆:" + licenseNumber);
                                }
                                else
                                {
                                    Logger.Info("车辆还车通知失败");
                                }
                            }
                        }
                    }
                    catch
                    {
                        Logger.Info("车辆还车通知任务(ReturnVehicleNotify:" + saas + ")失败");
                    }
                }
            }
            catch
            {
                Logger.Info("车辆还车通知任务(ReturnVehicleNotify)失败");
            }
        }
예제 #27
0
 //registrationId发送
 private Audience registrationId(HashSet <string> targets)
 {
     return(Audience.s_registrationId(targets));
 }
예제 #28
0
        /// <summary>
        /// 极光推送
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public Ptcp <string> SendPush(M_SendPushReq req)
        {
            var ptcp = new Ptcp <string>();

            if (req.IsNull())
            {
                ptcp.DoResult = "请求错误";
                return(ptcp);
            }
            string jsonParam = JsonConvert.SerializeObject(req);

            Logger.Write(LoggerLevel.Error, "SendPush_in", "", jsonParam, "");

            try
            {
                #region

                if (req.UserId <= 0)
                {
                    ptcp.DoResult = "会员ID错误";
                    return(ptcp);
                }

                //if (req.SourceTypeSysNo <= 0)
                //{
                //    ptcp.DoResult = "来源渠道错误";
                //    return ptcp;
                //}

                if (string.IsNullOrEmpty(req.MsgAlert))
                {
                    ptcp.DoResult = "消息alert不能为空";
                    return(ptcp);
                }

                var pushInfo = DbSession.MLT.T_JiGuangPushRepository.QueryBy(new T_JiGuangPush()
                {
                    UserId   = req.UserId,
                    IsEnable = true
                }, " ORDER BY ModifyTime DESC").FirstOrDefault();

                if (pushInfo.IsNull() || pushInfo.SysNo <= 0)
                {
                    ptcp.DoResult = "没有获取到会员与极光的关联关系";
                    return(ptcp);
                }

                int sourceTypeSysNo = pushInfo.SourceTypeSysNo.GetValueOrDefault();
                if (sourceTypeSysNo != (int)Enums.SourceTypeSysNo.AndroIdApp &&
                    sourceTypeSysNo != (int)Enums.SourceTypeSysNo.IosApp)
                {
                    ptcp.DoResult = "平台类型错误";
                    return(ptcp);
                }

                if (string.IsNullOrEmpty(pushInfo.JiGuangSysNo))
                {
                    ptcp.DoResult = "没有获取到会员与极光的关联关系";
                    return(ptcp);
                }

                PushClient  pushClient  = new PushClient();
                PushPayload pushPayload = new PushPayload();

                if (sourceTypeSysNo == (int)Enums.SourceTypeSysNo.AndroIdApp)
                {
                    pushPayload.platform = Platform.android();
                    if (!string.IsNullOrEmpty(req.MsgTitle))
                    {
                        pushPayload.notification = Notification.android(req.MsgAlert, req.MsgTitle);
                    }
                    else
                    {
                        pushPayload.notification = new Notification().setAlert(req.MsgAlert);
                    }
                }
                else if (sourceTypeSysNo == (int)Enums.SourceTypeSysNo.IosApp)
                {
                    pushPayload.platform     = Platform.ios();
                    pushPayload.notification = new Notification().setAlert(req.MsgAlert);
                }

                pushPayload.audience = Audience.s_registrationId(pushInfo.JiGuangSysNo);

                pushPayload.message = Message.content(req.MsgContent);

                var res = pushClient.sendPush(pushPayload);

                DbSession.MLT.T_JiGuangPushRecordRepository.Add(new T_JiGuangPushRecord()
                {
                    UserId          = req.UserId,
                    JiGuangSysNo    = pushInfo.JiGuangSysNo,
                    MsgTitle        = req.MsgTitle,
                    MsgAlert        = req.MsgAlert,
                    MsgContent      = req.MsgContent,
                    PushMsgId       = res.msg_id.ToString(),
                    PushResult      = res.isResultOK() == true ? "1" : "0",
                    SourceTypeSysNo = pushInfo.SourceTypeSysNo,
                    RowCeateDate    = DateTime.Now,
                    IsEnable        = true
                });
                DbSession.MLT.SaveChange();

                ptcp.DoFlag   = PtcpState.Success;
                ptcp.DoResult = "推送成功";

                #endregion
            }
            catch (Exception ex)
            {
                string strEx = string.Format("请求参数:{0};异常:{1}", req, ex.ToString());
                Logger.Write(LoggerLevel.Error, "SendPush_ex", "异常", strEx, "");
            }

            return(ptcp);
        }