/// <summary> /// 推送所有用户 /// </summary> /// <param name="template"></param> /// <returns></returns> public string PushAll(ITemplate template) { IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); AppMessage message = new AppMessage(); message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选 message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 message.Data = template; //message.PushNetWorkType = 0; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境 message.Speed = 1; 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("浙江"); List <String> tagList = new List <string>(); //tagList.Add("标签5"); message.AppIdList = appIdList; message.PhoneTypeList = phoneTypeList; message.ProvinceList = provinceList; message.TagList = tagList; return(push.pushMessageToApp(message, "toAPP任务别名")); }
//pushMessageToApp接口测试代码 private static void pushMessageToApp() { IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); AppMessage message = new AppMessage(); /*消息模版: * 1.TransmissionTemplate:透传模板 * 2.LinkTemplate:通知链接模板 * 3.NotificationTemplate:通知透传模板 * 4.NotyPopLoadTemplate:通知弹框下载模板 */ //TransmissionTemplate template = TransmissionTemplateDemo(); NotificationTemplate template = NotificationTemplateDemo(); //LinkTemplate template = LinkTemplateDemo(); //NotyPopLoadTemplate template = NotyPopLoadTemplateDemo(); message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选 message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 message.Data = template; //message.PushNetWorkType = 0; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境 //message.Speed = 1; 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, "toAPP任务别名"); System.Console.WriteLine("-----------------------------------------------"); System.Console.WriteLine("服务端返回结果:" + pushResult); }
//pushMessageToApp接口测试代码 public static string PushMessageToApp(string title, string messageText) { IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); AppMessage message = new AppMessage(); /*消息模版: * 1.TransmissionTemplate:透传模板 * 2.LinkTemplate:通知链接模板 * 3.NotificationTemplate:通知透传模板 * 4.NotyPopLoadTemplate:通知弹框下载模板 */ //TransmissionTemplate template = TransmissionTemplateDemo(); NotificationTemplate template = NotificationTemplateDemo(title, messageText); //LinkTemplate template = LinkTemplateDemo(); //NotyPopLoadTemplate template = NotyPopLoadTemplateDemo(); message.IsOffline = false; // 用户当前不在线时,是否离线存储,可选 message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 message.Data = template; 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); return(pushResult); }
//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); }
//pushMessageToApp接口测试代码 private static void pushMessageToApp() { IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); AppMessage message = new AppMessage(); //通知模版:支持TransmissionTemplate、LinkTemplate、NotificationTemplate,此处以LinkTemplate为例 LinkTemplate template = new LinkTemplate(); template.AppId = APPID; //应用APPID template.AppKey = APPKEY; // 应用APPKEY template.Title = "toAPP消息"; // 通知标题 template.Text = "toAPP消息"; // 通知内容 template.Logo = "icon.png"; // 通知Logo template.LogoURL = "http://www.photophoto.cn/m23/086/010/0860100017.jpg"; //通知栏网络图片展示 template.Url = "http://www.baidu.com"; // 跳转地址 //template.IsRing = true; // 收到通知是否响铃,可选,默认响铃 //template.IsVibrate = true; // 收到通知是否震动,可选,默认振动 //template.IsClearable = true; // 通知是否可清除,可选,默认可清除 message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选 message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 message.Data = template; 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("北京"); message.AppIdList = appIdList; message.PhoneTypeList = phoneTypeList; message.ProvinceList = provinceList; String pushResult = push.pushMessageToApp(message); System.Console.WriteLine("-----------pushMessageToApp--------------" + pushResult); }
//pushMessageToApp接口测试代码 public void Push(string msg, params string[] tagList) { IGtPush push = new IGtPush(HOST, AppKey, MasterSecret); // 定义"AppMessage"类型消息对象,设置消息内容模板、发送的目标App列表、是否支持离线发送、以及离线消息有效期(单位毫秒) AppMessage appMessage = new AppMessage(); TransmissionTemplate template = TransmissionTemplateDemo(msg); appMessage.IsOffline = true; // 用户当前不在线时,是否离线存储,可选 appMessage.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 appMessage.Data = template; //判断是否客户端是否wifi环境下推送,2:4G/3G/2G,1为在WIFI环境下,0为无限制环境 //message.PushNetWorkType = 0; //message.Speed = 1000; 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("北京"); //tagList.Add("中文"); appMessage.AppIdList = appIdList; appMessage.PhoneTypeList = phoneTypeList; appMessage.ProvinceList = provinceList; appMessage.TagList = tagList.ToList(); String pushResult = push.pushMessageToApp(appMessage); System.Console.WriteLine("-----------------------------------------------"); System.Console.WriteLine("服务端返回结果:" + pushResult); }
//pushMessageToApp接口测试代码 public static void pushMessageToApp(int id, string title, string des) { IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); // 定义"AppMessage"类型消息对象,设置消息内容模板、发送的目标App列表、是否支持离线发送、以及离线消息有效期(单位毫秒) AppMessage message = new AppMessage(); NotificationTemplate template = NotificationTemplateDemo(id, title, des); message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选 message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选 message.Data = template; //判断是否客户端是否wifi环境下推送,2:4G/3G/2G,1为在WIFI环境下,0为无限制环境 //message.PushNetWorkType = 0; //message.Speed = 1000; 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); }
/// <summary> /// 推送所有用户(向app应用内发送) /// </summary> /// <param name="pushMessageInfo"></param> public void pushMessageToApp(PushMessageInfo pushMessageInfo) { IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); string content = pushMessageInfo.Contents; string title = string.Empty; //为接收者组织数据 var transmissionContent = new { Template = pushMessageInfo.Template, Content = pushMessageInfo.Contents, Url = pushMessageInfo.Url, Section = pushMessageInfo.TypeID + "/" + pushMessageInfo.Section, NodeId = pushMessageInfo.DataID }; string jsonContent = JsonHelper.ConvertToJson(transmissionContent); PushLog("- - - - - - - - - - - - - "); PushLog(string.Format("推送类型:{0}", pushMessageInfo.PushType)); PushLog(string.Format("推送内容:{0}", pushMessageInfo.Contents)); PushLog(string.Format("推送目标:{0}", "应用内的所有用户")); if (pushMessageInfo.TypeID != 0) { title = Enum.GetName(typeof(SectionSecondType), pushMessageInfo.Section); } //透传模板 TransmissionTemplate template = TransmissionTemplateDemo(content, title, jsonContent, 0); template.TransmissionType = "2"; template.TransmissionContent = jsonContent; //透传内容 AppMessage message = new AppMessage(); message.IsOffline = true; message.OfflineExpireTime = 1000 * 3600 * 12; message.Data = template; //账号APPID List <string> appIdList = new List <string>(); appIdList.Add(APPID); //推送手机的类型 List <string> phoneTypeList = new List <string>(); if (pushMessageInfo.ChannelID == 0) { phoneTypeList.Add("IOS"); phoneTypeList.Add("ANDROID"); } else if (pushMessageInfo.ChannelID == 1) { phoneTypeList.Add("IOS"); } else { phoneTypeList.Add("ANDROID"); } message.AppIdList = appIdList; message.PhoneTypeList = phoneTypeList; string pushResult = push.pushMessageToApp(message); try { var result = JsonHelper.ConvertToObj <PushResult>(pushResult); PushLog("推送结果:" + result.result); } catch { PushLog("推送结果转换异常"); } }