Пример #1
0
        /// <summary>
        /// 批量推送消息
        /// </summary>
        /// <param name="processList">推送消息</param>
        /// <param name="channelDto">通道信息</param>
        /// <param name="retMsg"></param>
        ///<param name="sprint">3</param>
        /// <returns></returns>
        public bool SendProcessList(List <SendProcessDto> processList, out string retMsg)
        {
            Stopwatch stop = new Stopwatch();

            retMsg = string.Empty;
            if (processList == null)
            {
                retMsg = "SendProcessDtoList为空";
                return(false);
            }
            //processList 必须要有值,否则报错
            var process = processList.First();
            //获取通道的信息
            long?channelId = process.ChannelId;

            if (!channelId.HasValue)
            {
                retMsg = "推送消息中,通道Id为空";
                return(false);
            }
            ChannelDto channelDto;
            bool       flag = _channelLogic.CheckChannel(channelId.Value, out channelDto, out retMsg);

            if (!flag)
            {
                return(false);
            }
            stop.Start();
            //底层发送消息
            //分两种情况 1、IOS 消息推送 2、Android 消息推送
            int requestTime;
            //IOS逻辑
            var       iosProcessList = processList.Where(t => _tokenBrandLogic.MatchSystemType(t.BrandId.Value) == (int)SystemTypeEnum.IOS).ToList();
            SenderRet iosSenderRet   = SendPushMsgListToProvider(iosProcessList, SystemTypeEnum.IOS, channelDto, out requestTime);

            SendMsgListToDB(iosSenderRet, iosProcessList, requestTime);
            //Android逻辑
            var       androidProcessList = processList.Where(t => _tokenBrandLogic.MatchSystemType(t.BrandId.Value) == (int)SystemTypeEnum.Android).ToList();
            SenderRet androidSenderRet   = SendPushMsgListToProvider(androidProcessList, SystemTypeEnum.Android, channelDto, out requestTime);

            SendMsgListToDB(androidSenderRet, androidProcessList, requestTime);
            //推送成功
            return(true);
        }
Пример #2
0
 /// <summary>
 /// 从Process表取出待发送的BatchNO
 /// </summary>
 /// <param name="retMsg"></param>
 /// <returns></returns>
 public string GetProcessBatchNO(out string retMsg)
 {
     retMsg = "";
     try
     {
         var timeNow = DateTimeHelper.GetNow();
         PushSendProcessAppChannelDomainModel pushSendProcessAppChannelDomainModel = _pushSendProcessService.GetAppIdAndChannelIdAsync(timeNow).Result;
         //AppChannelDto appChannelDto = _mapper.Map<AppChannelDto>(pushSendProcessAppChannelDomainModel);
         //获取第一条推送消息的AppId和ChannelId,如果没有,返回批次号为空
         if (pushSendProcessAppChannelDomainModel == null)
         {
             return(string.Empty);
         }
         Guid batchNO    = Guid.NewGuid();
         var  expireTime = timeNow.AddMinutes(3);
         //获取通道
         ChannelDto channelDto;
         if (!_channelLogic.CheckChannel(pushSendProcessAppChannelDomainModel.ChannelId, out channelDto, out retMsg))
         {
             return(string.Empty);
         }
         int topNum = channelDto.PushNum.HasValue ? channelDto.PushNum.Value : 200;//可以从配置中获取数据,默认给200
         BatchProcessParmsDomainModel batchProcessParmsDomainModel = new BatchProcessParmsDomainModel
         {
             TopNum     = topNum,
             AppId      = pushSendProcessAppChannelDomainModel.AppId,
             ChannelId  = pushSendProcessAppChannelDomainModel.ChannelId,
             BatchNo    = batchNO,
             TimeNow    = timeNow,
             ExpireTime = expireTime
         };
         var updateNum = _pushSendProcessService.UpdateBatchNOByAppIdAndChannelIdAsync(batchProcessParmsDomainModel).Result;
         if (updateNum == 0)
         {
             return(string.Empty);
         }
         return(batchNO.ToString());
     }
     catch (Exception ex)
     {
         retMsg = ex.StackTrace + "\r\n" + ex.Message;
         return(null);
     }
 }