//PushMessageToSingle接口测试代码 private static void PushMessageToSingle() { // 推送主类 IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); //通知模版:支持TransmissionTemplate、LinkTemplate、NotificationTemplate,此处以TransmissionTemplate为例 TransmissionTemplate template = new TransmissionTemplate(); template.AppId = APPID; // 应用APPID template.AppKey = APPKEY; // 应用APPKEY template.TransmissionType = "1"; // 收到消息是否立即启动应用,1为立即启动,2则广播等待客户端自启动 template.TransmissionContent = "您需要透传的内容"; // 需要透传的内容 //iOS推送需要的pushInfo字段 //template.setPushInfo(actionLocKey, badge, message, sound, payload, locKey, locArgs, launchImage); // 单推消息模型 SingleMessage message = new SingleMessage(); message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选 message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 message.Data = template; com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target(); target.appId = APPID; target.clientId = CLIENTID; String pushResult = push.pushMessageToSingle(message, target); System.Console.WriteLine("-----------PushMessageToSingle--------------" + pushResult); }
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> /// 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); }
/// <summary> /// 透传模版 /// </summary> /// <returns></returns> private TransmissionTemplate TransmissionTemplateDemo(string title, string text, string content) { TransmissionTemplate template = new TransmissionTemplate(); template.AppId = Appid; template.AppKey = Appkey; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = "2"; //透传内容 template.TransmissionContent = content; #region APN高级推送 ////APN高级推送 //APNPayload apnpayload = new APNPayload(); //DictionaryAlertMsg alertMsg = new DictionaryAlertMsg(); //alertMsg.Body = text; //alertMsg.ActionLocKey = ""; //alertMsg.LocKey = ""; //alertMsg.addLocArg(""); //alertMsg.LaunchImage = ""; //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 return(template); }
//private static String DeviceToken = ""; //填写IOS系统的DeviceToken /// <summary> /// 单个消息推送 /// </summary> /// <param name="TransmissionType">应用启动类型,1:强制应用启动 2:等待应用启动</param> /// <param name="TransmissionContent">透传内容</param> /// <param name="beginTime">设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)</param> /// <param name="endTime">设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)</param> /// <param name="CLIENTID">个推clientId</param> public static void PushMessageToSingle(string TransmissionType, string TransmissionTitle, string TransmissionContent, string beginTime, string endTime, string CLIENTID) { IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); //消息模版:TransmissionTemplate:透传模板 TransmissionTemplate template = TransmissionTemplate(TransmissionType, TransmissionTitle, TransmissionContent, beginTime, endTime); // 单推消息模型 SingleMessage message = new SingleMessage(); message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选 message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 message.Data = template; //判断是否客户端是否wifi环境下推送,2为4G/3G/2G,1为在WIFI环境下,0为不限制环境 //message.PushNetWorkType = 1; com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target(); target.appId = APPID; target.clientId = CLIENTID; //target.alias = ALIAS; try { String pushResult = push.pushMessageToSingle(message, target); } catch (RequestException e) { String requestId = e.RequestId; //发送失败后的重发 String pushResult = push.pushMessageToSingle(message, target, requestId); } }
/* * * 所有推送接口均支持四个消息模板,依次为透传模板,通知透传模板,通知链接模板,通知弹框下载模板 * 注: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); }
private static TransmissionTemplate GetTransTemplate(string content) { TransmissionTemplate transmissionTemplate = new TransmissionTemplate(); transmissionTemplate.AppId = Push.APPID; transmissionTemplate.AppKey = Push.APPKEY; transmissionTemplate.TransmissionType = "2"; transmissionTemplate.TransmissionContent = content; return(transmissionTemplate); }
public static bool SendNotiMsgToSingle(string clientid, string title, string content, bool isIOS) { if (isIOS) { TransmissionTemplate iOSNotiTemplate = Push.GetIOSNotiTemplate(title, content); return(Push.PushMsgToSingleDevice(clientid, iOSNotiTemplate)); } NotificationTemplate androidNotiTemplate = Push.GetAndroidNotiTemplate(title, content); return(Push.PushMsgToSingleDevice(clientid, androidNotiTemplate)); }
public static bool SendNotiMsgToList(List <string> clientidlist, string title, string content, bool isIOS) { if (isIOS) { TransmissionTemplate iOSNotiTemplate = Push.GetIOSNotiTemplate(title, content); return(Push.PushMsgToList(clientidlist, iOSNotiTemplate)); } NotificationTemplate androidNotiTemplate = Push.GetAndroidNotiTemplate(title, content); return(Push.PushMsgToList(clientidlist, androidNotiTemplate)); }
//透传模板动作内容 public static TransmissionTemplate TransmissionTemplateDemo(string data) { TransmissionTemplate template = new TransmissionTemplate(); template.AppId = APPID; template.AppKey = APPKEY; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = 1; //透传内容 template.TransmissionContent = data; return(template); }
public static TransmissionTemplate TransmissionTemplateDemo(string title, string content) { TransmissionTemplate template = new TransmissionTemplate(); template.AppId = APPID; template.AppKey = APPKEY; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = "2"; //透传内容 template.TransmissionContent = title + "|" + content; return(template); }
private static TransmissionTemplate TransmissionContent(string msgTitle, string msgBody, string appid, string appkey) { var template = new TransmissionTemplate { AppId = appid, AppKey = appkey, TransmissionType = "1", TransmissionContent = "{title:\"" + msgTitle + "\",content:\"" + msgBody + "\",payload:\"payload\"}" }; return(template); }
/// <summary> /// 2 群组动态 /// </summary> /// <param name="deviceid"></param> /// <param name="msg"></param> /// <returns></returns> public static async Task PushGroupDynamic(string deviceid, string touid, string msg) { var currentMethod = "PushGroupDynamic"; var title = "群组动态通知"; var content = "新的群组动态"; var model = JsonConvert.DeserializeObject <AppGroupDynamic>(msg); title = model.GroupName; IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); //消息模版:TransmissionTemplate:透传模板 var intent = $"intent:#Intent;component=net.cnki.okms/.pages.base.BootActivity;end"; var getui = new GeTuiMessage { mtype = 2, mcontent = model, }; TransmissionTemplate template = TransmissionTemplate(title, content, intent, JsonConvert.SerializeObject(getui)); // 单推消息模型 SingleMessage message = new SingleMessage(); message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选 message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 message.Data = template; com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target(); target.appId = APPID; target.clientId = deviceid; var messageJson = JsonConvert.SerializeObject(message); LoggerHelper.AndroidPush($"1.个推-群组动态类消息[{touid}]推送的消息内容为:{Environment.NewLine}{messageJson}"); try { String pushResult = push.pushMessageToSingle(message, target); LoggerHelper.AndroidPush($"2.个推-群组动态类消息[{touid}]推送的返回结果:{Environment.NewLine}{pushResult}"); } catch (RequestException e) { String requestId = e.RequestId; //发送失败后的重发 String pushResult = push.pushMessageToSingle(message, target, requestId); LoggerHelper.AndroidPush($"3.个推-群组动态类消息[{touid}]发生了异常,重发后,服务端返回结果:----------------" + pushResult); } }
/* * * 所有推送接口均支持四个消息模板,依次为透传模板,通知透传模板,通知链接模板,通知弹框下载模板 * 注:IOS离线推送需通过APN进行转发,需填写pushInfo字段,目前仅不支持通知弹框下载功能 * */ //透传模板动作内容 public static TransmissionTemplate TransmissionTemplateDemo(string messageText) { TransmissionTemplate template = new TransmissionTemplate(); template.AppId = APPID; template.AppKey = APPKEY; template.TransmissionType = "1"; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionContent = messageText; //透传内容 //iOS推送需要的pushInfo字段 //template.setPushInfo(actionLocKey, badge, message, sound, payload, locKey, locArgs, launchImage); //template.setPushInfo("", 4, "", "", "", "", "", ""); return(template); }
//pushMessageToApp透传 public void pushMessageToApp() { // 推送主类(方式1,不可与方式2共存) IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); // 推送主类(方式2,不可与方式1共存)此方式可通过获取服务端地址列表判断最快域名后进行消息推送,每10分钟检查一次最快域名 //IGtPush push = new IGtPush("",APPKEY,MASTERSECRET); AppMessage message = new AppMessage(); // 设置群推接口的推送速度,单位为条/秒,仅对pushMessageToApp(对指定应用群推接口)有效 message.Speed = 100; TransmissionTemplate template = TransmissionTemplateDemo(); // 用户当前不在线时,是否离线存储,可选 message.IsOffline = false; // 离线有效时间,单位为毫秒,可选 message.OfflineExpireTime = 1000 * 3600 * 12; message.Data = template; //message.PushNetWorkType = 0; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为不限制网络环境。 List <String> appIdList = new List <string>(); appIdList.Add(APPID); //通知接收者的手机操作系统类型 List <String> phoneTypeList = new List <string>(); phoneTypeList.Add("ANDROID"); //phoneTypeList.Add("IOS"); //通知接收者所在省份 List <String> provinceList = new List <string>(); //provinceList.Add("浙江"); //provinceList.Add("上海"); //provinceList.Add("北京"); List <String> tagList = new List <string>(); //tagList.Add("开心"); message.AppIdList = appIdList; message.PhoneTypeList = phoneTypeList; message.ProvinceList = provinceList; message.TagList = tagList; String pushResult = push.pushMessageToApp(message); System.Console.WriteLine("-----------------------------------------------"); System.Console.WriteLine("服务端返回结果:" + pushResult); }
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); }
public static TransmissionTemplate TransmissionTemplateDemo() { TransmissionTemplate template = new TransmissionTemplate(); template.AppId = APPID; template.AppKey = APPKEY; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = "2"; //透传内容 template.TransmissionContent = "您有一条新消息"; template.setPushInfo("actionLocKey", 4, "message", "sound", "payload", "locKey", "locArgs", "launchImage"); /*IOS 推送需要对该字段进行设置具体参数详见2.5*/ 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); }
/// <summary> /// 给多个用户发送推送(DEMO) /// </summary> private static void PushMessageToList() { IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); ListMessage message = new ListMessage(); /*消息模版: * 1.TransmissionTemplate:透传功能模板 * 2.LinkTemplate:通知打开链接功能模板 * 3.NotificationTemplate:通知透传功能模板 * 4.NotyPopLoadTemplate:通知弹框下载功能模板 */ TransmissionTemplate template = TransmissionTemplateDemo(); //NotificationTemplate template = NotificationTemplateDemo(); //LinkTemplate template = LinkTemplateDemo(); //NotyPopLoadTemplate template = NotyPopLoadTemplateDemo(); template.TransmissionContent = "测试"; message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选 message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 message.Data = template; //message.PushNetWorkType = 0; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境 //设置接收者 List <com.igetui.api.openservice.igetui.Target> targetList = new List <com.igetui.api.openservice.igetui.Target>(); com.igetui.api.openservice.igetui.Target target1 = new com.igetui.api.openservice.igetui.Target(); target1.appId = APPID; //target1.clientId = CLIENTID; target1.clientId = CLIENTID; // 如需要,可以设置多个接收者 com.igetui.api.openservice.igetui.Target target2 = new com.igetui.api.openservice.igetui.Target(); target2.appId = APPID; //target2.clientId = "f563cffaba68587e7ff2f23110f6defd"; target2.clientId = CLIENTID; targetList.Add(target1); targetList.Add(target2); String contentId = push.getContentId(message, "ToList_任务组名"); String pushResult = push.pushMessageToList(contentId, targetList); System.Console.WriteLine("-----------------------------------------------"); System.Console.WriteLine("服务端返回结果:" + pushResult); }
///// <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); }
//透传模板动作内容 private TransmissionTemplate TransmissionTemplateDemo(string message) { TransmissionTemplate template = new TransmissionTemplate(); template.AppId = AppID; template.AppKey = AppKey; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = "1"; //透传内容 template.TransmissionContent = message; //设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟) //String begin = "2015-03-06 14:36:10"; //String end = "2015-03-06 14:46:20"; //template.setDuration(begin, end); return(template); }
//透传模板动作内容 public TransmissionTemplate TransmissionTemplateDemo() { TransmissionTemplate template = new TransmissionTemplate(); template.AppId = APPID; template.AppKey = APPKEY; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = "1"; //透传内容 template.TransmissionContent = "派工信息"; //设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟) String begin = "2015-03-06 14:36:10"; String end = "2017-03-06 14:46:20"; template.setDuration(begin, end); return(template); }
/// <summary> /// 透传模板动作内容 /// </summary> /// <param name="transContent">透传内容</param> /// <param name="beginTM">客户端展示开始时间</param> /// <param name="endTM">客户端展示结束时间</param> /// <returns></returns> public TransmissionTemplate TransmissionTemplate(string transContent, string beginTM, string endTM) { TransmissionTemplate template = new TransmissionTemplate(); template.AppId = APPID; template.AppKey = APPKEY; template.TransmissionType = "1"; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionContent = transContent; //透传内容 //iOS推送需要的pushInfo字段 //template.setPushInfo(actionLocKey, badge, message, sound, payload, locKey, locArgs, launchImage); template.setPushInfo("1", 4, "2", "", "", "", "", ""); //设置客户端展示时间 String begin = beginTM; String end = endTM; template.setDuration(begin, end); return(template); }
//static void Main() //{ // //toList接口每个用户状态返回是否开启,可选 // Console.OutputEncoding = Encoding.GetEncoding(936); // Environment.SetEnvironmentVariable("needDetails", "true"); // //2.PushMessageToList接口 // PushToList(); //} //PushMessageToList接口测试代码 public static void PushToList(string title, string content, List <string> clientList, bool istz) { // 推送主类(方式1,不可与方式2共存) IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); // 推送主类(方式2,不可与方式1共存)此方式可通过获取服务端地址列表判断最快域名后进行消息推送,每10分钟检查一次最快域名 //IGtPush push = new IGtPush("",APPKEY,MASTERSECRET); ListMessage message = new ListMessage(); //NotificationTemplate template = NotificationTemplateDemo(title, content); if (istz) { NotificationTemplate template = NotificationTemplateDemo(title, content); message.Data = template; } else { TransmissionTemplate template = TransmissionTemplateDemo(title, content); message.Data = template; } // 用户当前不在线时,是否离线存储,可选 message.IsOffline = false; // 离线有效时间,单位为毫秒,可选 message.OfflineExpireTime = 1000 * 3600 * 12; message.PushNetWorkType = 0; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为不限制网络环境。 //设置接收者 List <com.igetui.api.openservice.igetui.Target> targetList = new List <com.igetui.api.openservice.igetui.Target>(); foreach (var cid in clientList) { com.igetui.api.openservice.igetui.Target target1 = new com.igetui.api.openservice.igetui.Target(); target1.appId = APPID; target1.clientId = cid; //target1.alias = ALIAS1; targetList.Add(target1); } String contentId = push.getContentId(message); String pushResult = push.pushMessageToList(contentId, targetList); System.Console.WriteLine("-----------------------------------------------"); System.Console.WriteLine("服务端返回结果:" + pushResult); }
/// <summary> /// 18.个推-工作交办 todolist(群组日程、待办)消息通知(刘静杰) /// </summary> /// <param name="deviceid"></param> /// <param name="touid"></param> /// <param name="msg"></param> /// <returns></returns> public static async Task PushToDoMessage(string deviceid, string touid, ScheduleModel msg) { var currentMethod = "PushToDoMessage"; IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); var intent = $"intent:#Intent;component=net.cnki.okms/.pages.base.BootActivity;end"; var title = "待办任务"; var content = msg.title; var getui = new GeTuiMessage { mtype = 18, mcontent = msg, }; TransmissionTemplate template = TransmissionTemplate(title, content, intent, JsonConvert.SerializeObject(getui)); // 单推消息模型 SingleMessage message = new SingleMessage(); message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选 message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 message.Data = template; com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target(); target.appId = APPID; target.clientId = deviceid; var messageJson = JsonConvert.SerializeObject(message); LoggerHelper.AndroidPush($"1.(个推-待办任务)给[{touid}]推送的内容:" + messageJson); try { String pushResult = push.pushMessageToSingle(message, target); LoggerHelper.AndroidPush($"2.(个推-待办任务)给[{touid}]返回结果:" + pushResult); } catch (RequestException e) { String requestId = e.RequestId; //发送失败后的重发 String pushResult = push.pushMessageToSingle(message, target, requestId); LoggerHelper.AndroidPush($"3.(个推-待办任务)给[{touid}]发生了异常,重发后,服务端返回结果:----------------" + pushResult); } }
/// <summary> /// 给单个用户发送推送(DEMO) /// </summary> private static void PushMessageToSingle() { IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); TransmissionTemplate template = TransmissionTemplateDemo(); template.TransmissionContent = "测试"; // 单推消息模型 SingleMessage message = new SingleMessage(); message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选 message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 message.Data = template; message.PushNetWorkType = 0; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境 com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target(); target.appId = APPID; target.clientId = CLIENTID; String pushResult = push.pushMessageToSingle(message, target); }
/* * * 所有推送接口均支持四个消息模板,依次为透传模板,通知透传模板,通知链接模板,通知弹框下载模板 * 注:IOS离线推送需通过APN进行转发,需填写pushInfo字段,目前仅不支持通知弹框下载功能 * */ //透传模板动作内容--模版1 public static TransmissionTemplate TransmissionTemplateDemo(int PaltForm, string title, string content, string custom_content) { TransmissionTemplate template = new TransmissionTemplate(); template.AppId = APPID; template.AppKey = APPKEY; template.TransmissionType = "1"; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionContent = content; //透传内容 //iOS推送需要的pushInfo字段 if (PaltForm == 1) { //iOS推送需要的pushInfo字段 template.setPushInfo("actionLocKey", 4, "message", "sound", "payload", "locKey", "locArgs", "launchImage"); } //template.setPushInfo(actionLocKey, badge, message, sound, payload, locKey, locArgs, launchImage); //template.setPushInfo("", 4, "", "", "", "", "", ""); return(template); }
private static string PushMessageToSingle(string clientID) { // 推送主类 IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); // LinkTemplate template = LinkTemplateDemo(strAdvice); TransmissionTemplate transmissionTemplate = TransmissionTemplateDemo(); SingleMessage message = new SingleMessage(); // 用户当前不在线时,是否离线存储,可选 message.IsOffline = false; // 离线有效时间,单位为毫秒,可选 message.OfflineExpireTime = 1000 * 3600 * 12; message.Data = transmissionTemplate; com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target(); target.appId = APPID; target.clientId = clientID; String pushResult = push.pushMessageToSingle(message, target); return pushResult; }
public static string DeviceToken = "";//填写IOS系统的DeviceToken #endregion /// <summary> /// 透传模板 /// </summary> /// <param name="transContent">透传内容</param> /// <param name="beginTM">客户端展示开始时间</param> /// <param name="endTM">客户端展示结束时间</param> public string PushTemplate(int pushType, string transContent, string beginTM, string endTM) { TransmissionTemplate template = TransmissionTemplate(transContent, beginTM, endTM); switch (pushType) { case Enum_Push.Single: return(PushSingle(template)); case Enum_Push.Multiple: return(PushMultiple(template)); case Enum_Push.All: return(PushAll(template)); default: return("false"); } }
/// <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); }