Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #8
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);
        }