예제 #1
0
        public void setPushInfo(
            string actionLocKey,
            int badge,
            string message,
            string sound,
            string payload,
            string locKey,
            string locArgs,
            string launchImage,
            int contentAvailable)
        {
            APNPayload         apnPayload         = new APNPayload();
            DictionaryAlertMsg dictionaryAlertMsg = new DictionaryAlertMsg();

            dictionaryAlertMsg.ActionLocKey = actionLocKey;
            dictionaryAlertMsg.Body         = message;
            dictionaryAlertMsg.LocKey       = locKey;
            dictionaryAlertMsg.addLocArg(locArgs);
            dictionaryAlertMsg.LaunchImage = launchImage;
            apnPayload.AlertMsg            = (AlertMsg)dictionaryAlertMsg;
            apnPayload.Badge = badge;
            apnPayload.Sound = sound;
            if (string.IsNullOrEmpty(payload))
            {
                apnPayload.addCustomMsg(nameof(payload), (object)payload);
            }
            apnPayload.ContentAvailable = contentAvailable;
            this.setAPNInfo((Payload)apnPayload);
        }
예제 #2
0
        private static TransmissionTemplate GetIOSNotiTemplate(string title, string content)
        {
            TransmissionTemplate transmissionTemplate = new TransmissionTemplate();

            transmissionTemplate.AppId               = Push.APPID;
            transmissionTemplate.AppKey              = Push.APPKEY;
            transmissionTemplate.TransmissionType    = "2";
            transmissionTemplate.TransmissionContent = "newmsg";
            APNPayload         aPNPayload         = new APNPayload();
            DictionaryAlertMsg dictionaryAlertMsg = new DictionaryAlertMsg();

            dictionaryAlertMsg.Body         = content;
            dictionaryAlertMsg.ActionLocKey = "";
            dictionaryAlertMsg.LocKey       = "";
            dictionaryAlertMsg.addLocArg("");
            dictionaryAlertMsg.LaunchImage = "";
            dictionaryAlertMsg.Title       = title;
            dictionaryAlertMsg.TitleLocKey = "";
            dictionaryAlertMsg.addTitleLocArg("");
            aPNPayload.AlertMsg         = dictionaryAlertMsg;
            aPNPayload.ContentAvailable = 1;
            aPNPayload.Sound            = "";
            aPNPayload.addCustomMsg("payload", "payload");
            transmissionTemplate.setAPNInfo(aPNPayload);
            return(transmissionTemplate);
        }
예제 #3
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);
        }
예제 #4
0
        /// <summary>
        /// Android 与IOS 透传模板 初始化设置
        /// </summary>
        /// <param name="content">内容主体</param>
        /// <param name="title">标题 </param>
        /// <param name="jsonContent">透传主体</param>
        /// <returns></returns>
        public static TransmissionTemplate TransmissionTemplateDemo(string content, string title, string jsonContent, int isMute)
        {
            TransmissionTemplate template = new TransmissionTemplate();

            template.AppId  = APPID;
            template.AppKey = APPKEY;

            //APN高级推送
            APNPayload         apnpayload = new APNPayload();
            DictionaryAlertMsg alertMsg   = new DictionaryAlertMsg();

            alertMsg.Body         = "Body";
            alertMsg.ActionLocKey = "ActionLocKey";
            alertMsg.LocKey       = content;
            alertMsg.addLocArg("LocArg");
            alertMsg.LaunchImage = "LaunchImage";
            //IOS8.2支持字段
            alertMsg.Title       = "Title";
            alertMsg.TitleLocKey = title;   //IOS 标题
            alertMsg.addTitleLocArg("TitleLocArg");
            apnpayload.AlertMsg = alertMsg; //IOS 消息
            apnpayload.Badge    = 0;
            if (isMute == 1)
            {
                apnpayload.Sound = "com.gexin.ios.silence";
            }
            else
            {
                apnpayload.Sound = "default";
            }
            apnpayload.addCustomMsg("payload", jsonContent);
            template.setAPNInfo(apnpayload);
            return(template);
        }
예제 #5
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);
        }
예제 #6
0
        /*
         *
         * 所有推送接口均支持四个消息模板,依次为透传模板,通知透传模板,通知链接模板,通知弹框下载模板
         * 注:IOS离线推送需通过APN进行转发,需填写pushInfo字段,目前仅不支持通知弹框下载功能
         *
         */
        //透传模板动作内容
        public static TransmissionTemplate TransmissionTemplateDemo(string title, string text, string transmissioncontent, string iconUrl, List <string> pushChannels)
        {
            TransmissionTemplate template = new TransmissionTemplate();

            template.AppId               = APPID;
            template.AppKey              = APPKEY;
            template.TransmissionType    = "2"; //应用启动类型,1:强制应用启动 2:等待应用启动
            template.TransmissionContent = "";  //透传内容
            //iOS简单推送
            //APNPayload apnpayload = new APNPayload();
            //SimpleAlertMsg alertMsg = new SimpleAlertMsg("alertMsg");
            //apnpayload.AlertMsg = alertMsg;
            //apnpayload.Badge = 11;
            //apnpayload.ContentAvailable = 1;
            //apnpayload.Category = "";
            //apnpayload.Sound = "";
            //apnpayload.addCustomMsg("", "");
            //template.setAPNInfo(apnpayload);

            //APN高级推送
            APNPayload         apnpayload = new APNPayload();
            DictionaryAlertMsg alertMsg   = new DictionaryAlertMsg();

            if (text == "您有一个任务将在1小时后截止,请尽快完成")
            {
                alertMsg.Body = "您有一个任务将在1小时后截止,请尽快完成";
            }
            else
            {
                alertMsg.Body = "您有一条新消息";
            }
            alertMsg.ActionLocKey = "您有一条新消息";
            alertMsg.LocKey       = text;//内容
            alertMsg.addLocArg("LocArg");
            alertMsg.LaunchImage = "LaunchImage";

            //IOS8.2支持字段
            alertMsg.Title       = "喻佰信息管理指挥系统";
            alertMsg.TitleLocKey = title;//标题
            alertMsg.addTitleLocArg("TitleLocArg");

            apnpayload.AlertMsg         = alertMsg;
            apnpayload.Badge            = 1;
            apnpayload.ContentAvailable = 1;
            //apnpayload.Category = "Category";
            apnpayload.Sound = "test1.wav";
            apnpayload.addCustomMsg("payload", transmissioncontent);
            template.setAPNInfo(apnpayload);


            //设置客户端展示时间
            //String begin = "2015-03-06 14:28:10";
            //String end = "2015-03-06 14:38:20";
            //template.setDuration(begin, end);

            return(template);
        }
예제 #7
0
        /*
         *
         * 所有推送接口均支持四个消息模板,依次为透传模板,通知透传模板,通知链接模板,通知弹框下载模板
         * 注:IOS离线推送需通过APN进行转发,需填写pushInfo字段,目前仅不支持通知弹框下载功能
         *
         */

        /// <summary>
        /// 透传模板
        /// </summary>
        /// <returns></returns>
        private static TransmissionTemplate TransmissionTemplateDemo()
        {
            TransmissionTemplate template = new TransmissionTemplate();

            template.AppId               = APPID;
            template.AppKey              = APPKEY;
            template.TransmissionType    = "1"; //应用启动类型,1:强制应用启动 2:等待应用启动
            template.TransmissionContent = "";  //透传内容

            //iOS简单推送
            //APNPayload apnpayload = new APNPayload();
            //SimpleAlertMsg alertMsg = new SimpleAlertMsg("alertMsg");
            //apnpayload.AlertMsg = alertMsg;
            //apnpayload.Badge = 11;
            //apnpayload.ContentAvailable = 1;
            //apnpayload.Category = "";
            //apnpayload.Sound = "";
            //apnpayload.addCustomMsg("", "");
            //template.setAPNInfo(apnpayload);

            //APN高级推送
            APNPayload         apnpayload = new APNPayload();
            DictionaryAlertMsg alertMsg   = new DictionaryAlertMsg();

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

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


            //设置客户端展示时间
            //String begin = "2015-03-06 14:28:10";
            //String end = "2015-03-06 14:38:20";
            //template.setDuration(begin, end);

            return(template);
        }
예제 #8
0
        public static TransmissionTemplate TransmissionTemplateIOS(string title, string content, string text)
        {
            TransmissionTemplate template = new TransmissionTemplate();

            template.AppId               = Appid;
            template.AppKey              = Appkey;
            template.TransmissionType    = "1";     //应用启动类型,1:强制应用启动 2:等待应用启动
            template.TransmissionContent = content; //透传内容

            #region iOS简单推送
            //iOS简单推送
            //APNPayload apnpayload = new APNPayload();
            //SimpleAlertMsg alertMsg = new SimpleAlertMsg(content);
            //apnpayload.AlertMsg = alertMsg;
            //apnpayload.Badge = 11;
            //apnpayload.ContentAvailable = 1;
            //apnpayload.Category = "";
            //apnpayload.Sound = "";
            //apnpayload.addCustomMsg("", "");

            //template.setAPNInfo(apnpayload);
            #endregion

            #region APN高级推送
            //APN高级推送
            APNPayload         apnpayload = new APNPayload();
            DictionaryAlertMsg alertMsg   = new DictionaryAlertMsg();
            alertMsg.Body         = text;
            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            = "test1.wav";
            apnpayload.addCustomMsg("", "");
            template.setAPNInfo(apnpayload);
            #endregion

            //设置客户端展示时间
            //String begin = "2015‐03‐06 14:28:10";//String end = "2015‐03‐06 14:38:20";
            //template.setDuration(begin, end);
            return(template);
        }
예제 #9
0
        ///// <summary>
        /////执行状态的枚举
        ///// </summary>
        //public enum PushType
        //{
        //    [DescriptionAttribute("好友验证申请")]
        //    FriendRquest,
        //    [DescriptionAttribute("订单已消费")]
        //    OrderConsume,
        //    [DescriptionAttribute("通知")]
        //    Notice
        //}

        //#region 函数:获取枚举类子项属性 GetEnumDescription<T>(T item)
        ///// <summary>获取枚举类子项属性信息</summary>
        ///// <param name="item">枚举类子项</param>
        ///// <returns>操作结果</returns>
        //public string GetEnumDescription<T>(T item)
        //{
        //    string strValue = item.ToString();

        //    FieldInfo fieldinfo = item.GetType().GetField(strValue);
        //    if (fieldinfo == null)
        //    {
        //        return strValue;
        //    }

        //    Object[] objs = fieldinfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
        //    if (objs == null || objs.Length == 0)
        //    {
        //        return strValue;
        //    }
        //    else
        //    {
        //        DescriptionAttribute da = (DescriptionAttribute)objs[0];
        //        return da.Description;
        //    }
        //}
        //#endregion

        //#region 函数:推送消息到指定客户端 PushMessageToList(PushType type, string accountIds, string content, string payload)
        ///// <summary>推送消息到指定客户端</summary>
        ///// <param name="type">推送类型 枚举PushType类型</param>
        ///// <param name="accountIds">接收人标识 多人用,分隔</param>
        ///// <param name="content">推送信息</param>
        ///// <param name="payload">透传信息 JSON字符串格式,如:{"property1":"value1","property2":"value2"}</param>
        ///// <returns>操作结果</returns>
        //public string PushMessageToList(string title, string content, string accountIds, string payload)
        //{
        //    IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);

        //    ListMessage message = new ListMessage();
        //    // 用户当前不在线时,是否离线存储 (可选)
        //    message.IsOffline = true;
        //    // 离线有效时间,单位为毫秒,可选
        //    message.OfflineExpireTime = 1000 * 3600 * 12;
        //    // 判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为不限制网络环境。
        //    message.PushNetWorkType = 0;

        //    // 拼装透传内容
        //    string transmissionContent = "{\"title\":\"" + title + "\",\"content\":\"" + content + "\",\"payload\":" + payload + "}";

        //    message.Data = GetTransmissionTemplate(transmissionContent, APPID, APPKEY);

        //    IList<string> pushClientList = MembershipManagement.Instance.AccountBindingService.FindAllBindingObjectIds(accountIds, "Getui");

        //    //设置接收者
        //    List<Target> targetList = new List<Target>();

        //    foreach (var item in pushClientList)
        //    {
        //        Target target1 = new Target();
        //        target1.appId = APPID;
        //        target1.clientId = item;
        //        targetList.Add(target1);
        //    }

        //    string contentId = push.getContentId(message);
        //    string result = push.pushMessageToList(contentId, targetList);

        //    return result;
        //}
        //#endregion

        #region 私有函数:透传消息模板 GetTransmissionTemplate()
        /// <summary>透传消息模板</summary>
        /// <param name="transmissionContent">透传内容</param>
        /// <returns>操作结果</returns>
        private TransmissionTemplate GetTransmissionTemplate(string transmissionContent, string id, string key)
        {
            TransmissionTemplate template = new TransmissionTemplate();

            template.AppId  = id;
            template.AppKey = key;
            // 应用启动类型,1:强制应用启动 2:等待应用启动
            template.TransmissionType = "2";
            // 透传内容
            template.TransmissionContent = transmissionContent;

            JsonData data = JsonMapper.ToObject(transmissionContent);

            /********************************************/
            /************** APN高级推送 **************/
            /*******************************************/
            APNPayload apnpayload = new APNPayload();

            DictionaryAlertMsg alertMsg = new DictionaryAlertMsg();

            alertMsg.Body = data["content"].ToString();
            //alertMsg.ActionLocKey = "ActionLocKey";
            //alertMsg.LocKey = "LocKey";
            //alertMsg.addLocArg("LocArg");
            //alertMsg.LaunchImage = "LaunchImage";
            ////IOS8.2支持字段
            alertMsg.Title = data["title"].ToString();
            //alertMsg.TitleLocKey = "TitleLocKey";
            //alertMsg.addTitleLocArg("TitleLocArg");

            apnpayload.AlertMsg         = alertMsg;
            apnpayload.ContentAvailable = 1;
            apnpayload.Badge            = 0;
            //apnpayload.Category = "";
            //apnpayload.Sound = "test1.wav";


            //foreach (JProperty jp in data["payload"])
            //{
            //    apnpayload.addCustomMsg(jp.Name, jp.Value.ToString());
            //}


            template.setAPNInfo(apnpayload);

            return(template);
        }
예제 #10
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);
        }
예제 #11
0
        /// <summary>
        /// 透传模板动作内容
        /// </summary>
        /// <param name="TransmissionType">应用启动类型,1:强制应用启动 2:等待应用启动</param>
        /// <param name="TransmissionContent">透传内容</param>
        /// <param name="beginTime">设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)</param>
        /// <param name="endTime">设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)</param>
        /// <returns></returns>
        public static TransmissionTemplate TransmissionTemplate(string TransmissionType, string Transmissiontitle, string TransmissionContent, string beginTime, string endTime)
        {
            TransmissionTemplate template = new TransmissionTemplate();

            template.AppId  = APPID;
            template.AppKey = APPKEY;
            //应用启动类型,1:强制应用启动 2:等待应用启动
            template.TransmissionType = TransmissionType;
            //透传内容
            template.TransmissionContent = TransmissionContent;

            APNPayload         apnpayload = new APNPayload();
            DictionaryAlertMsg alertMsg   = new DictionaryAlertMsg();

            alertMsg.Body         = string.Empty;
            alertMsg.ActionLocKey = TransmissionContent;
            alertMsg.LocKey       = Transmissiontitle;
            //alertMsg.addLocArg("LocArg");
            alertMsg.addLocArg(Transmissiontitle);
            alertMsg.LaunchImage = "";
            ////IOS8.2支持字段
            alertMsg.Title       = "您收到了一条消息";
            alertMsg.TitleLocKey = Transmissiontitle;
            //alertMsg.addTitleLocArg("TitleLocArg");
            alertMsg.addTitleLocArg(Transmissiontitle);
            apnpayload.AlertMsg         = alertMsg;
            apnpayload.Badge            = 1;
            apnpayload.ContentAvailable = 1;
            ////apnpayload.Category = "";
            //apnpayload.Sound = "test1.wav";
            apnpayload.addCustomMsg("payload", "payload");
            template.setAPNInfo(apnpayload);
            //设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)
            String begin = beginTime;
            String end   = endTime;

            if (!string.IsNullOrEmpty(begin) && !string.IsNullOrEmpty(end))
            {
                template.setDuration(begin, end);
            }
            return(template);
        }
예제 #12
0
        private TransmissionTemplate TransmissionTemplateIOS(string title)
        {
            TransmissionTemplate template = new TransmissionTemplate();

            template.AppId = APPID;
            template.AppKey = APPKEY;
            template.TransmissionType = "2";            //应用启动类型,1:强制应用启动 2:等待应用启动
            template.TransmissionContent = "";  //透传内容

            //iOS简单推送
            //APNPayload apnpayload = new APNPayload();
            //SimpleAlertMsg alertMsg = new SimpleAlertMsg("alertMsg");
            //apnpayload.AlertMsg = alertMsg;
            //apnpayload.Badge = 11;
            //apnpayload.ContentAvailable = 1;
            //apnpayload.Category = "";
            //apnpayload.Sound = "";
            //apnpayload.addCustomMsg("", "");
            //template.setAPNInfo(apnpayload);

            //APN高级推送
            APNPayload apnpayload = new APNPayload();
            DictionaryAlertMsg alertMsg = new DictionaryAlertMsg();
            alertMsg.Body = "Body";
            alertMsg.ActionLocKey = "查看";
            alertMsg.LocKey = title;
            alertMsg.addLocArg("LocArg");
            alertMsg.LaunchImage = "LaunchImage";
            //IOS8.2支持字段
            //alertMsg.Title = "Title";
            //alertMsg.TitleLocKey = "TitleLocKey";
            //alertMsg.addTitleLocArg("TitleLocArg");

            apnpayload.AlertMsg = alertMsg;
            apnpayload.Badge = 1;
            apnpayload.ContentAvailable = 1;
            //apnpayload.Category = "";
            apnpayload.Sound = "test1.wav";
            apnpayload.addCustomMsg("payload", "payload");
            template.setAPNInfo(apnpayload);

            //设置客户端展示时间
            //String begin = "2015-03-06 14:28:10";
            //String end = "2015-03-06 14:38:20";
            //template.setDuration(begin, end);

            return template;
        }
예제 #13
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);
        }
예제 #14
0
        protected TransmissionTemplate TransmissionTemplateDemo(AppPushChannelInfo channelInfo, NoticeMsg message)
        {
            if (channelInfo == null)
            {
                throw new Exception("推送通道信息为空。");
            }
            TransmissionTemplate template = new TransmissionTemplate();

            try
            {
                template.AppId  = channelInfo.AppId;
                template.AppKey = channelInfo.AppKey;
                //应用启动类型,1:强制应用启动 2:等待应用启动
                template.TransmissionType = "1";
                //透传内容
                template.TransmissionContent = "透传内容";
                //设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)
                //String begin = "2017-03-13 00:36:10";
                //String end = "2017-03-13 23:46:20";
                //template.setDuration(begin, end);

                //APN高级推送 开始
                APNPayload         apnpayload = new APNPayload();
                DictionaryAlertMsg alertMsg   = new DictionaryAlertMsg();
                alertMsg.Body = message.Message;

                //alertMsg.Body = "您有新的异常消息,请尽快处理。";
                //(用于多语言支持)指定执行按钮所使用的Localizable.strings
                //alertMsg.ActionLocKey = "ActionLocKey";
                //(用于多语言支持)指定Localizable.strings文件中相应的key
                //alertMsg.LocKey = "LocKey";
                ////如果loc-key中使用的占位符,则在loc-args中指定各参数
                //alertMsg.addLocArg("LocArg");
                //指定启动界面图片名
                //alertMsg.LaunchImage = "LaunchImage";
                //iOS8.2支持字段
                //通知标题
                alertMsg.Title = message.Title;
                //(用于多语言支持)对于标题指定执行按钮所使用的Localizable.strings
                //alertMsg.TitleLocKey = "TitleLocKey";
                //对于标题, 如果loc-key中使用的占位符,则在loc-args中指定各参数
                //alertMsg.addTitleLocArg("TitleLocArg");

                apnpayload.AlertMsg = alertMsg;
                //应用icon上显示的数字
                //apnpayload.Badge = 1;
                apnpayload.ContentAvailable = 1;
                //apnpayload.Category = "";
                //通知铃声文件名
                //apnpayload.Sound = "test1.wav";
                //增加自定义的数据
                apnpayload.addCustomMsg("pushMsgType", "message");
                template.setAPNInfo(apnpayload);
                //APN高级推送 结束
            }
            catch (Exception)
            {
                throw;
            }
            return(template);
        }