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); }
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); }
/// <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); }
/// <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); }
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); }
/* * * 所有推送接口均支持四个消息模板,依次为透传模板,通知透传模板,通知链接模板,通知弹框下载模板 * 注: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); }
/* * * 所有推送接口均支持四个消息模板,依次为透传模板,通知透传模板,通知链接模板,通知弹框下载模板 * 注: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); }
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); }
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); }
/// <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); }
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; }
/// <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); }