Ejemplo n.º 1
0
        /// <summary>
        /// ios个推离线通知
        /// </summary>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="token"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string APNsPushToSingle(string title, string content, string token, object data)
        {
            APNTemplate        template   = new APNTemplate();
            APNPayload         apnpayload = new APNPayload();
            DictionaryAlertMsg alertMsg   = new DictionaryAlertMsg();

            alertMsg.Body         = content; //通知文本消息字符串
            alertMsg.ActionLocKey = "";
            alertMsg.LocKey       = "";
            alertMsg.addLocArg("");
            alertMsg.LaunchImage = "";    //指定启动界面图片名
            //IOS8.2支持字段
            alertMsg.Title       = title; //通知标题
            alertMsg.TitleLocKey = "";
            alertMsg.addTitleLocArg("");
            apnpayload.AlertMsg = alertMsg;
            //apnpayload.Badge = 1;//应用icon上显示的数字
            apnpayload.ContentAvailable = 1;       //推送直接带有透传数据
            apnpayload.Category         = "";
            apnpayload.Sound            = "";      //通知铃声文件名
            apnpayload.addCustomMsg("data", data); //增加自定义的数据
            template.setAPNInfo(apnpayload);
            IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
            /*单个用户推送接口*/
            SingleMessage Singlemessage = new SingleMessage();

            Singlemessage.Data = template;
            String pushResult = push.pushAPNMessageToSingle(APPID, token, Singlemessage);

            Console.Out.WriteLine(pushResult);
            return(pushResult);
        }
Ejemplo n.º 2
0
        public static void apnPush(string title, string text, string iconUrl, List <string> pushChannels)
        {
            //APN简单推送
            //IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
            //APNTemplate template = new APNTemplate();
            //APNPayload apnpayload = new APNPayload();
            //SimpleAlertMsg alertMsg = new SimpleAlertMsg("");
            //apnpayload.AlertMsg = alertMsg;
            //apnpayload.Badge = 11;
            //apnpayload.ContentAvailable = 1;
            //apnpayload.Category = "";
            //apnpayload.Sound = "com.gexin.ios.silence";
            //apnpayload.addCustomMsg("", "");
            //template.setAPNInfo(apnpayload);

            //APN高级推送
            IGtPush            push       = new IGtPush(HOST, APPKEY, MASTERSECRET);
            APNTemplate        template   = new APNTemplate();
            APNPayload         apnpayload = new APNPayload();
            DictionaryAlertMsg alertMsg   = new DictionaryAlertMsg();

            alertMsg.Body         = text;
            alertMsg.ActionLocKey = title;
            alertMsg.LocKey       = title;
            alertMsg.addLocArg("");
            alertMsg.LaunchImage = iconUrl;
            //IOS8.2支持字段
            alertMsg.Title       = "";
            alertMsg.TitleLocKey = "";
            alertMsg.addTitleLocArg("");

            apnpayload.AlertMsg         = alertMsg;
            apnpayload.Badge            = 10;
            apnpayload.ContentAvailable = 1;
            apnpayload.Category         = "";
            apnpayload.Sound            = "";
            apnpayload.addCustomMsg("", "");
            template.setAPNInfo(apnpayload);



            /*单个用户推送接口*/
            //SingleMessage Singlemessage = new SingleMessage();
            //Singlemessage.Data = template;
            //String pushResult = push.pushAPNMessageToSingle(APPID, DeviceToken, Singlemessage);
            //Console.Out.WriteLine(pushResult);

            /*多个用户推送接口*/
            ListMessage listmessage = new ListMessage();

            listmessage.Data = template;
            String contentId = push.getAPNContentId(APPID, listmessage);
            //Console.Out.WriteLine(contentId);
            //List<String> devicetokenlist = new List<string>();
            //devicetokenlist.Add(DeviceToken);
            //String ret = push.pushAPNMessageToList(APPID, contentId, devicetokenlist);
            //Console.Out.WriteLine(ret);
            String ret = push.pushAPNMessageToList(APPID, contentId, pushChannels);
        }
Ejemplo n.º 3
0
        static void apnPush(int PaltForm, string clientId, string NoticeTitle, string NoticeContent, string custom_content)
        {
            //APN高级推送
            IGtPush            push       = new IGtPush(HOST, APPKEY, MASTERSECRET);
            APNTemplate        template   = new APNTemplate();
            APNPayload         apnpayload = new APNPayload();
            DictionaryAlertMsg alertMsg   = new DictionaryAlertMsg();

            alertMsg.Body         = NoticeContent;
            alertMsg.ActionLocKey = "";
            alertMsg.LocKey       = "";
            alertMsg.addLocArg("");
            alertMsg.LaunchImage = "";
            //IOS8.2支持字段
            alertMsg.Title       = NoticeTitle;
            alertMsg.TitleLocKey = "";
            alertMsg.addTitleLocArg("");

            apnpayload.AlertMsg         = alertMsg;
            apnpayload.Badge            = 10;
            apnpayload.ContentAvailable = 1;
            apnpayload.Category         = "";
            apnpayload.Sound            = "";
            apnpayload.addCustomMsg("", "");
            template.setAPNInfo(apnpayload);


            /*单个用户推送接口*/
            SingleMessage Singlemessage = new SingleMessage();

            Singlemessage.Data = template;
            String pushResult = push.pushAPNMessageToSingle(APPID, DeviceToken, Singlemessage);

            /*多个用户推送接口*/
            //ListMessage listmessage = new ListMessage();
            //listmessage.Data = template;
            //String contentId = push.getAPNContentId(APPID, listmessage);
            ////Console.Out.WriteLine(contentId);
            //List<String> devicetokenlist = new List<string>();
            //devicetokenlist.Add(DeviceToken);
            //String ret = push.pushAPNMessageToList(APPID, contentId, devicetokenlist);
            //Console.Out.WriteLine(ret);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 发送推送[目前仅支持传透和通知,支持Android和IOS]
        /// </summary>
        /// <param name="condtion"></param>
        internal static SendGeTuiPushReplay PushMessage(SendGeTuiPushBySetRequestModel condtion)
        {
            SendGeTuiPushReplay result      = new SendGeTuiPushReplay();
            IGtPush             push        = new IGtPush(HOST, APPKEY, MASTERSECRET);
            ListMessage         listMessage = new ListMessage()
            {
                IsOffline         = IsOffline,
                OfflineExpireTime = OfflineExpireTime,
                PushNetWorkType   = PushNetWorkType
            };
            SingleMessage singleMessage = new SingleMessage()
            {
                IsOffline         = IsOffline,
                OfflineExpireTime = OfflineExpireTime,
                PushNetWorkType   = PushNetWorkType
            };
            TransmissionTemplate tt = TransmissionTemplateDemo(); //传透
            NotificationTemplate nt = NotificationTemplateDemo(); //通知

            if (condtion.sets.Count > 0)
            {
                //分离请求中的设备类型
                List <GeTuiSetModel> ios     = condtion.sets.Where(p => p.deviceType != EnumUserDeviceType.Android).ToList();
                List <GeTuiSetModel> android = condtion.sets.Where(p => p.deviceType == EnumUserDeviceType.Android).ToList();

                //IOS和安卓分开处理
                if (ios.Count > 0)
                {
                    //IOS设备发送
                    //IOS需使用传透方式来发送
                    APNTemplate        template   = new APNTemplate();
                    APNPayload         apnpayload = new APNPayload();
                    DictionaryAlertMsg alertMsg   = new DictionaryAlertMsg();
                    alertMsg.Body         = condtion.msg;
                    alertMsg.ActionLocKey = "";
                    alertMsg.LocKey       = "";
                    alertMsg.addLocArg("");
                    alertMsg.LaunchImage = "";
                    //IOS8.2支持字段
                    alertMsg.Title       = condtion.title;
                    alertMsg.TitleLocKey = "";
                    alertMsg.addTitleLocArg("");

                    apnpayload.AlertMsg         = alertMsg;
                    apnpayload.Badge            = 1;
                    apnpayload.ContentAvailable = 1;
                    //apnpayload.Category = "";
                    apnpayload.Sound = "sms-received1.caf";
                    apnpayload.addCustomMsg("customInfo", condtion.customInfo);
                    template.setAPNInfo(apnpayload);
                    template.AppId  = APPID;
                    template.AppKey = APPKEY;

                    if (ios.Count > 1)
                    {
                        //批量
                        listMessage.Data = template;
                        List <string> devicetokenlist = new List <string>();
                        foreach (GeTuiSetModel set in ios)
                        {
                            devicetokenlist.Add(set.clientId);
                        }
                        string contentId = push.getAPNContentId(APPID, listMessage);
                        result.sentResultIos = push.pushAPNMessageToList(APPID, contentId, devicetokenlist);
                    }
                    else if (ios.Count == 1)
                    {
                        //单个
                        singleMessage.Data   = template;
                        result.sentResultIos = push.pushAPNMessageToSingle(APPID, ios[0].clientId, singleMessage);
                    }
                }
                if (android.Count > 0)
                {
                    switch (condtion.messageType)
                    {
                    case EnumPushMessagesType.透传消息:
                        tt.TransmissionContent = condtion.msg;
                        listMessage.Data       = tt;
                        singleMessage.Data     = tt;
                        break;

                    case EnumPushMessagesType.通知:
                        nt.Title = condtion.title;
                        nt.Text  = condtion.msg;
                        nt.TransmissionContent = Newtonsoft.Json.JsonConvert.SerializeObject(condtion.customInfo);
                        listMessage.Data       = nt;
                        singleMessage.Data     = nt;
                        break;
                    }

                    //安卓设备发送
                    if (android.Count > 1)
                    {
                        //多个用户
                        List <Target> ts = new List <Target>();
                        foreach (GeTuiSetModel set in android)
                        {
                            ts.Add(new Target()
                            {
                                appId    = APPID,
                                clientId = set.clientId
                            });
                        }
                        string contentId = push.getContentId(listMessage, "ToList_" + DateTime.Now.ToString("yyyyMMddHHmmss"));
                        result.sentResultAndroid = push.pushMessageToList(contentId, ts);
                    }
                    else if (android.Count == 1)
                    {
                        //单个用户
                        Target t = new Target();
                        t.appId    = APPID;
                        t.clientId = android[0].clientId;
                        result.sentResultAndroid = push.pushMessageToSingle(singleMessage, t);
                    }
                }
                result.ReturnCode = EnumErrorCode.Success;
            }
            else
            {
                result.ReturnCode    = EnumErrorCode.EmptyDate;
                result.ReturnMessage = "没有设置任何的接收者";
                SysManagerService.SysSaveSysLog("推送消息:[" + condtion.msg + "]没有设置任何的接收者", EnumSysLogType.警告);
            }
            return(result);
        }