Exemplo n.º 1
0
        public static AndroidPushDto PushMsgModelToAndroidPushDto(PushChannelModel channel, PushMsgModel msg)
        {
            AndroidPushDto androidpush = new AndroidPushDto
            {
                Url             = channel.Url,
                AppKey          = channel.AppKey,
                AppMasterSecret = channel.AppSecret,
                DeviceTokens    = msg.DeviceToken,
                ProductionMode  = channel.ProductionMode,
                Ticker          = msg.Ticker,
                Title           = msg.Title,
                Text            = msg.Msg,
                Description     = msg.Title,
                Displaytype     = DisplayType.notification,  //默认通知
                AfterOpen       = AfterOpenAction.go_custom, //默认用户自定义
                TimeStamp       = Convert.ToString((int)(CurrentUnixTimeMillis() / 1000)),
                PlayVibrate     = true,
                PlayLights      = true,
                PlaySound       = true,
            };

            if (!string.IsNullOrEmpty(msg.AttachInfo))
            {
                try
                {
                    androidpush.Extra = JsonConvert.DeserializeObject <Dictionary <string, string> >(msg.AttachInfo);
                }
                catch
                {
                    //LogHelper.Info.Write("PushMsg", string.Format("AttachInfo:{0},字段中内容不符合规范,序列化失败,置为空继续发送", msg.AttachInfo));
                    androidpush.Extra = null;
                }
            }
            return(androidpush);
        }
Exemplo n.º 2
0
        public static SenderRet PushMsg(PushChannelModel channel, PushMsgModel msg)
        {
            IOSPushDto iospush = PushMsgModelToIOSPushDto(channel, msg);
            int        timeOut = channel.PushNum == 0 ? 2 : (int)Math.Ceiling((double)channel.TimeOut / channel.PushNum);

            return(pushApplicationSession.IPushIOSUnicast.SendMessage(iospush, timeOut));
        }
Exemplo n.º 3
0
        public static IOSPushDto PushMsgModelToIOSPushDto(PushChannelModel channel, PushMsgModel msg)
        {
            IOSPushDto iospush = new IOSPushDto
            {
                PushUrl         = channel.Url,
                AppKey          = channel.AppKey,
                AppMasterSecret = channel.AppSecret,
                DeviceTokens    = msg.DeviceToken,
                ProductionMode  = channel.ProductionMode,
                Alert           = msg.Msg,
                Description     = msg.Title,
                TimeStamp       = Convert.ToString((int)(CurrentUnixTimeMillis() / 1000)),
                Sound           = "default"
            };

            if (!string.IsNullOrEmpty(msg.AttachInfo))
            {
                try
                {
                    iospush.Extra = JsonConvert.DeserializeObject <Dictionary <string, string> >(msg.AttachInfo);
                }
                catch
                {
                    //LogHelper.Info.Write("PushMsg", string.Format("AttachInfo:{0},字段中内容不符合规范,序列化失败,置为空继续发送", msg.AttachInfo));
                    iospush.Extra = null;
                }
            }
            return(iospush);
        }
Exemplo n.º 4
0
        public static AndroidPushDto PushMsgModelToAndroidPushDto(PushChannelModel channel, PushMsgModel msg)
        {
            AndroidPushDto androidpush = new AndroidPushDto
            {
                DeviceToken    = msg.DeviceToken,
                ProductionMode = channel.ProductionMode,
                Description    = msg.Ticker,
                Title          = msg.Title,
                PayLoad        = msg.Msg
            };

            if (!string.IsNullOrEmpty(msg.AttachInfo))
            {
                try
                {
                    androidpush.Extra = JsonConvert.DeserializeObject <Dictionary <string, string> >(msg.AttachInfo);
                }
                catch
                {
                    //LogHelper.Info.Write("PushMsg", string.Format("AttachInfo:{0},字段中内容不符合规范,序列化失败,置为空继续发送", msg.AttachInfo));
                    androidpush.Extra = null;
                }
            }
            return(androidpush);
        }
Exemplo n.º 5
0
 public SenderRet Send(PushChannelModel channel, PushMsgModel msg)
 {
     if (msg.SystemType == SystemTypeEnum.Android)
     {
         return(AndroidSender.PushMsg(channel, msg));
     }
     return(IOSSender.PushMsg(channel, msg));
 }
Exemplo n.º 6
0
 public SenderRet SendList(PushChannelModel channel, List <PushMsgModel> msgList)
 {
     if (channel.SystemType == SystemTypeEnum.Android)
     {
         return(AndroidSender.PushMsgList(channel, msgList));
     }
     return(IOSSender.PushMsgList(channel, msgList));
 }
Exemplo n.º 7
0
        /// <summary>
        /// 推送消息给推送平台
        /// </summary>
        /// <param name="sendProcessDto">推送消息</param>
        /// <param name="rzTokenBrandDto">注册信息</param>
        /// <param name="rzTokenBrandDetailDto">注册明细</param>
        /// <param name="channelDto">通道</param>
        /// <param name="appChannelDto">App和通道的关系</param>
        /// <param name="requestTime">请求时间</param>
        /// <returns></returns>
        public SenderRet SendPushMsgToProvider(SendProcessDto sendProcessDto, DeviceChannelDto deviceChannelDto, out int requestTime)
        {
            SenderRet senderRet = new SenderRet {
                IsSuccess = true
            };

            //底层发送消息
            requestTime = 0;
            //获取ProductionMode
            object ProducttMode = _configLogic.GetConfigValue(ConfigKey.ProductionMode);
            //构造底层推送消息的参数
            PushChannelModel pushChannelModel = new PushChannelModel
            {
                ChannelName    = deviceChannelDto.ChannelName,
                Url            = deviceChannelDto.Url,
                AppKey         = deviceChannelDto.AppKey,
                AppSecret      = deviceChannelDto.AppSecret,
                ProductionMode = Convert.ToBoolean(ProducttMode)      //获取调试模式
            };
            PushMsgModel pushMsgModel = new PushMsgModel
            {
                Ticker      = sendProcessDto.Title,
                Title       = sendProcessDto.Title,
                Msg         = sendProcessDto.Msg,
                AttachInfo  = sendProcessDto.AttachInfo,
                DeviceToken = deviceChannelDto.DeviceToken,
                SystemType  = (SystemTypeEnum)deviceChannelDto.SystemType
            };
            ISender sender = PushSenderManager.GetSender(deviceChannelDto.ChannelId);

            if (sender == null)
            {
                senderRet.IsSuccess = false;
                senderRet.Msg       = string.Format("ChannelId:{0},推送信息供应商不存在", deviceChannelDto.ChannelId);
                //LogHelper.Error.Write("SendPushMsgToProvider", senderRet.Msg);
                return(senderRet);
            }
            Stopwatch sw            = new Stopwatch();
            var       isRealPushMsg = _configLogic.GetConfigValue(ConfigKey.IsRealPushMsg);

            sw.Start();
            if (isRealPushMsg != null && Convert.ToBoolean(isRealPushMsg))
            {
                senderRet = PushSender.Send(sender, pushChannelModel, pushMsgModel);
            }
            else
            {
                Thread.Sleep(200);
                senderRet = new SenderRet {
                    IsSuccess = true, Sign = Guid.NewGuid().ToString()
                };
            }
            sw.Stop();
            requestTime = (int)sw.ElapsedMilliseconds;
            return(senderRet);
        }
Exemplo n.º 8
0
 public SenderRet SendList(PushChannelModel channel, List <PushMsgModel> msgList)
 {
     if (channel.SystemType == SystemTypeEnum.Android)
     {
         return(MultiCast.SendMessage(channel, msgList));
     }
     return(new SenderRet()
     {
         IsSuccess = false, Code = "-1", Msg = "华为推送通道只支持android"
     });
 }
Exemplo n.º 9
0
 public SenderRet Send(PushChannelModel channel, PushMsgModel msg)
 {
     if (channel.SystemType == SystemTypeEnum.Android || msg.SystemType == SystemTypeEnum.Android)
     {
         return(UniCast.SendMessage(channel, msg));
     }
     return(new SenderRet()
     {
         IsSuccess = false, Code = "-1", Msg = "华为推送通道只支持android"
     });
 }
Exemplo n.º 10
0
        /// <summary>
        /// 单播发送友盟消息
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public override SenderRet SendMessage(object channel, object msg)
        {
            PushChannelModel pushChannelModel = channel as PushChannelModel;
            PushMsgModel     pushMsgModel     = msg as PushMsgModel;
            string           url       = pushChannelModel.Url;
            string           appSecret = pushChannelModel.AppSecret;
            var bodyStr = InitMiMessage(pushMsgModel);
            var ret     = SendToMiPush(bodyStr, url, appSecret);

            return(ret);
        }
Exemplo n.º 11
0
        public override SenderRet SendMessage(object channel, object msgList)
        {
            PushChannelModel    pushChannelModel = channel as PushChannelModel;
            List <PushMsgModel> pushMsgModelList = msgList as List <PushMsgModel>;
            string url       = pushChannelModel.Url;
            string appSecret = pushChannelModel.AppSecret;
            var    bodyStr   = InitMiMultiMessage(pushMsgModelList);
            int    timeOut   = pushChannelModel.TimeOut;
            var    ret       = SendToMiPush(bodyStr, url, appSecret, timeOut);

            return(ret);
        }
Exemplo n.º 12
0
        public static SenderRet PushMsgList(PushChannelModel channel, List <PushMsgModel> msgList)
        {
            List <SenderRet> senderRetList = new List <SenderRet>();

            foreach (var item in msgList)
            {
                SenderRet ret = PushMsg(channel, item);
                ret.Id = item.Id;
                senderRetList.Add(ret);
            }
            return(new SenderRet {
                IsSuccess = true, ResultList = senderRetList
            });
        }
Exemplo n.º 13
0
        public static SenderRet SendMessage(PushChannelModel channel, List <PushMsgModel> msgList)
        {
            List <SenderRet> senderRetList = new List <SenderRet>();

            foreach (var msg in msgList)
            {
                SenderRet ret = UniCast.SendMessage(channel, msg);
                ret.Id = msg.Id;
                senderRetList.Add(ret);
            }
            return(new SenderRet {
                IsSuccess = true, ResultList = senderRetList
            });
        }
Exemplo n.º 14
0
 public SenderRet SendList(PushChannelModel channel, List <PushMsgModel> msgList)
 {
     //目前MiPush只做小米手机(Android系统)
     //TODO 批量推送
     return(AndroidSender.PushMsgList(channel, msgList));
 }
Exemplo n.º 15
0
 public SenderRet Send(PushChannelModel channel, PushMsgModel msg)
 {
     //目前MiPush只做小米手机(Android系统)
     return(AndroidSender.PushMsg(channel, msg));
 }
Exemplo n.º 16
0
        public static SenderRet SendMessage(PushChannelModel channel, PushMsgModel msg)
        {
            int timeout = channel.TimeOut * 1000 / channel.PushNum;

            return(SendToHuaweiPush(channel.Url, channel.AppKey, channel.AppSecret, timeout, msg));
        }
Exemplo n.º 17
0
        /// <summary>
        /// 将消息推送给推送平台
        /// </summary>
        /// <param name="list"></param>
        /// <param name="channel"></param>
        /// <param name="requestTime"></param>
        /// <returns></returns>
        public SenderRet SendPushMsgListToProvider(List <SendProcessDto> processList, SystemTypeEnum systemType, ChannelDto channelDto, out int requestTime)
        {
            string    retMsg    = string.Empty;
            SenderRet senderRet = new SenderRet {
                IsSuccess = true
            };

            requestTime = 0;
            if (processList == null || processList.Count == 0)
            {
                senderRet.IsSuccess = false;
                senderRet.Msg       = "SendProcessDtoList为空";
                return(senderRet);
            }
            int           appId = processList.First().AppId;
            AppChannelDto appChannelDto;

            if (!_channelLogic.CheckAppChannel(appId, (int)systemType, channelDto.Id, out appChannelDto, out retMsg))
            {
                senderRet.IsSuccess = false;
                senderRet.Msg       = retMsg;
                return(senderRet);
            }
            //推送第三方平台  友盟只能单推,小米可以批量推,个推也能批量推送
            ISender sender = PushSenderManager.GetSender(channelDto.Id);

            if (sender == null)
            {
                senderRet.IsSuccess = false;
                senderRet.Msg       = string.Format("ChannelId:{0},推送信息供应商不存在", channelDto.Id);
                return(senderRet);
            }
            PushChannelModel pushChannelModel = new PushChannelModel
            {
                ChannelName    = channelDto.ChannelName,
                Url            = channelDto.MultiUrl,
                AppKey         = appChannelDto.AppKey,
                AppSecret      = appChannelDto.AppSecret,
                ProductionMode = Convert.ToBoolean(_configLogic.GetConfigValue(ConfigKey.ProductionMode)),
                SystemType     = systemType,
                PushNum        = channelDto.PushNum ?? 50,
                TimeOut        = channelDto.PushTimeOut
            };
            List <PushMsgModel> pushMsgModelList = processList.Select(e =>
            {
                return(new PushMsgModel
                {
                    Id = e.Id,
                    Ticker = e.Title,
                    Title = e.Title,
                    Msg = e.Msg,
                    AttachInfo = e.AttachInfo,
                    DeviceToken = e.DeviceToken,
                    SystemType = systemType
                });
            }).ToList();
            var       isRealPushMsg = _configLogic.GetConfigValue(ConfigKey.IsRealPushMsg);
            Stopwatch sw            = new Stopwatch();

            sw.Start();
            if (isRealPushMsg != null && Convert.ToBoolean(isRealPushMsg))
            {
                senderRet = sender.SendList(pushChannelModel, pushMsgModelList);
            }
            else
            {
                Thread.Sleep(2000);
                senderRet = new SenderRet {
                    IsSuccess = true, Sign = Guid.NewGuid().ToString()
                };
            }
            sw.Stop();
            requestTime = (int)sw.ElapsedMilliseconds;
            return(senderRet);
        }
Exemplo n.º 18
0
 public static SenderRet PushMsgList(PushChannelModel channel, List <PushMsgModel> msgList)
 {
     return(pushApplicationSession.IPushAndroidMulticast.SendMessage(channel, msgList));
 }
Exemplo n.º 19
0
 public static SenderRet PushMsg(PushChannelModel channel, PushMsgModel msg)
 {
     return(pushApplicationSession.IPushAndroidUnicast.SendMessage(channel, msg));
 }