using com.gexin.rp.sdk.dto; using com.igetui.api.openservice; using com.igetui.api.openservice.igetui; using com.igetui.api.openservice.igetui.template; using com.igetui.api.openservice.igetui.template.notify; using com.igetui.api.openservice.payload; using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace VueWebApi.Tools { /// /// 个推 /// public class GeTuiMessage { public const string HOST = "http://sdk.open.api.igexin.com/apiex.htm"; public const string APPID = ""; public const string APPKEY = ""; public const string AppSecret = ""; public const string MASTERSECRET = ""; /// /// 推送一批用户 /// /// 标题 例如 抢购会 /// 内容 例如 华为Mate30 5G抢购 /// APP跳转地址 商品单页 活动页 或者其它页面 /// 数据库pushclientid字段集合 /// 推送结果 public static string pushMessageToList(string title, string content, string url, string[] cids) { IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); ListMessage message = new ListMessage(); NotificationTemplate template = NotificationTemplateAndroidiOS(title, content, url); message.IsOffline = true; message.OfflineExpireTime = 1000 * 3600 * 12; message.Data = template; message.PushNetWorkType = 0; List targetList = new List(); for (int i = 0; i < cids.Length; i++) { com.igetui.api.openservice.igetui.Target target1 = new com.igetui.api.openservice.igetui.Target(); target1.appId = APPID; target1.clientId = cids[i]; targetList.Add(target1); } String contentId = push.getContentId(message); String pushResult = push.pushMessageToList(contentId, targetList); return pushResult; } /// /// 模版一 /// /// 标题 /// 内容 /// 链接 APP中要跳转的页面 /// public static NotificationTemplate NotificationTemplateAndroidiOS(string title, string content, string url) { NotificationTemplate template = new NotificationTemplate(); template.AppId = APPID; template.AppKey = APPKEY; template.Title = title; //通知栏标题 template.Text = content; //通知栏内容 template.Logo = ""; //通知栏显示本地图片 template.LogoURL = ""; //通知栏显示网络图标 template.TransmissionType = 1;//通知栏显示网络图标 template.TransmissionContent = "{\"url\":\"" + url + "\"}"; //透传内容 template.IsRing = true; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsVibrate = true; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsClearable = true; //接收到消息是否可清除,true:可清除 false:不可清除 //安卓透传厂商通道 Notify notify = new Notify(); notify.Content = title; notify.Title = content; string newUrl = "{\"url\":\"" + url + "\"}"; notify.Intent = $"intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=您的安卓包名/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title={title};S.content={content};S.payload={newUrl};end"; notify.Type = NotifyInfo.Types.Type._intent; template.set3rdNotifyInfo(notify); //苹果透传配置 APNPayload apnpayload = new APNPayload(); DictionaryAlertMsg alertMsg = new DictionaryAlertMsg(); // IOS 的body用这个 alertMsg.Body = content; 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 = 0 +1; apnpayload.ContentAvailable = 0; apnpayload.Sound = "default"; apnpayload.addCustomMsg("payload", "{\"url\":\"" + url + "\"}"); template.setAPNInfo(apnpayload); string begin = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string end = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss"); template.setDuration(begin, end); return template; } } }