Beispiel #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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public static SenderRet PushMsg(PushChannelModel channel, PushMsgModel msg)
        {
            AndroidPushDto androidpush = PushMsgModelToAndroidPushDto(channel, msg);

            int timeOut = channel.PushNum == 0 ? 2 : (int)Math.Ceiling((double)channel.TimeOut / channel.PushNum);

            return(pushApplicationSession.IPushAndroidUnicast.SendMessage(androidpush, timeOut));
        }