/* * * 所有推送接口均支持四个消息模板,依次为透传模板,通知透传模板,通知链接模板,通知弹框下载模板 * 注:IOS离线推送需通过APN进行转发,需填写pushInfo字段,目前仅不支持通知弹框下载功能 * */ //透传模板动作内容 public static NotificationTemplate NotificationTemplateDemo(int id, string title, string des) { NotificationTemplate template = new NotificationTemplate(); template.AppId = APPID; template.AppKey = APPKEY; //通知栏标题 template.Title = title; //通知栏内容 template.Text = des; //通知栏显示本地图片 template.Logo = ""; //通知栏显示网络图标 template.LogoURL = ""; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = "1"; //透传内容 template.TransmissionContent = id.ToString(); //接收到消息是否响铃,true:响铃 false:不响铃 template.IsRing = true; //接收到消息是否震动,true:震动 false:不震动 template.IsVibrate = true; //接收到消息是否可清除,true:可清除 false:不可清除 template.IsClearable = true; //设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟) String begin = DateTime.Now.ToString(); String end = DateTime.Now.AddMinutes(10).ToString(); template.setDuration(begin, end); return(template); }
public void ValidateTemplate_NonWnsPlatformThrowsWhenHeadersNonNull(string platform) { // Pass condition = exception thrown. bool testPass = false; NotificationTemplate template = new NotificationTemplate() { Body = "someString", Tags = new List <string> { "tag1", "tag2" }, Headers = new Dictionary <string, string>() }; NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock(); try { mock.ValidateTemplate(template, platform); } catch { testPass = true; } Assert.True(testPass); }
/// <summary> /// 多消息推送 /// </summary> /// <param name="Title">通知栏标题</param> /// <param name="Text">通知栏内容</param> /// <param name="Logo">通知栏显示本地图片</param> /// <param name="LogoURL">通知栏显示网络图标</param> /// <param name="TransmissionType">应用启动类型,1:强制应用启动 2:等待应用启动</param> /// <param name="TransmissionContent">透传内容</param> /// <param name="IsRing">接收到消息是否响铃,true:响铃 false:不响铃</param> /// <param name="IsVibrate">接收到消息是否震动,true:震动 false:不震动</param> /// <param name="IsClearable">接收到消息是否可清除,true:可清除 false:不可清除</param> /// <param name="beginTime">设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)</param> /// <param name="endTime">设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)</param> /// <param name="clientIdList">client列表</param> public static void PushMessageToList(string Title, string Text, string Logo, string LogoURL, string TransmissionType, string TransmissionContent, bool IsRing, bool IsVibrate, bool IsClearable, string beginTime, string endTime, List <string> clientIdList) { // 推送主类(方式1,不可与方式2共存) IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); // 推送主类(方式2,不可与方式1共存)此方式可通过获取服务端地址列表判断最快域名后进行消息推送,每10分钟检查一次最快域名 //IGtPush push = new IGtPush("",APPKEY,MASTERSECRET); ListMessage message = new ListMessage(); NotificationTemplate template = NotificationTemplate(Title, Text, Logo, LogoURL, TransmissionType, TransmissionContent, IsRing, IsVibrate, IsClearable, beginTime, endTime); // 用户当前不在线时,是否离线存储,可选 message.IsOffline = true; // 离线有效时间,单位为毫秒,可选 message.OfflineExpireTime = 1000 * 3600 * 12; message.Data = template; //message.PushNetWorkType = 0; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为不限制网络环境。 //设置接收者 List <com.igetui.api.openservice.igetui.Target> targetList = new List <com.igetui.api.openservice.igetui.Target>(); foreach (string item in clientIdList) { com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target(); target.appId = APPID; target.clientId = item; targetList.Add(target); } String contentId = push.getContentId(message); String pushResult = push.pushMessageToList(contentId, targetList); }
/// <summary> /// 创建消息模板 /// </summary> /// <param name="content">json格式字符串</param> /// <returns></returns> public static NotificationTemplate Create(string title, string text, string logo, string logourl, string content) { NotificationTemplate template = new NotificationTemplate(); template.AppId = appId; template.AppKey = appKey; //通知栏标题 template.Title = title; //通知栏内容 template.Text = text; //通知栏显示本地图片 template.Logo = logo; //通知栏显示网络图标 template.LogoURL = logourl; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = "1"; //透传内容 template.TransmissionContent = content; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsRing = true; //接收到消息是否震动,true:震动 false:不震动 template.IsVibrate = true; //接收到消息是否可清除,true:可清除 false:不可清除 template.IsClearable = true; //设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟) 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); }
/// <summary> /// 通知透传模板动作内容--模版2 /// </summary> /// <param name="PaltForm">1:苹果 2:安卓</param> /// <param name="title"></param> /// <param name="content"></param> /// <returns></returns> public static NotificationTemplate NotificationTemplateDemo(int PaltForm, string title, string content, string custom_content) { NotificationTemplate template = new NotificationTemplate(); template.AppId = APPID; template.AppKey = APPKEY; template.Title = title; //通知栏标题 template.Text = content; //通知栏内容 template.Logo = ""; //通知栏显示本地图片 template.LogoURL = ""; //通知栏显示网络图标 template.TransmissionType = "1"; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionContent = custom_content; //透传内容 if (PaltForm == 2) { //iOS推送需要的pushInfo字段 template.setPushInfo("actionLocKey", 4, "message", "sound", "payload", "locKey", "locArgs", "launchImage"); //template.setPushInfo(actionLocKey, badge, message, sound, payload, locKey, locArgs, launchImage); } template.IsRing = true; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsVibrate = true; //接收到消息是否震动,true:震动 false:不震动 template.IsClearable = true; //接收到消息是否可清除,true:可清除 false:不可清除 return(template); }
//通知透传模板动作内容 public static NotificationTemplate NotificationTemplateDemo(string title, string content, string data) { NotificationTemplate template = new NotificationTemplate(); template.AppId = APPID; template.AppKey = APPKEY; //通知栏标题 template.Title = title; //通知栏内容 template.Text = content; //通知栏显示本地图片 template.Logo = ""; //通知栏显示网络图标 template.LogoURL = ""; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = 1; //透传内容 template.TransmissionContent = data; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsRing = true; //接收到消息是否震动,true:震动 false:不震动 template.IsVibrate = true; //接收到消息是否可清除,true:可清除 false:不可清除 template.IsClearable = true; //设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟) //string firsttime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //double time = 10; //string lasttime = DateTime.Now.AddMinutes(time).ToString("yyyy-MM-dd HH:mm:ss"); //String begin = firsttime; //String end = lasttime; //template.setDuration(begin, end); return(template); }
public static void Push(Guid?userId, NotificationTemplate template) { Push(new List <Guid?>() { userId }, template); }
//通知透传模板动作内容 public static NotificationTemplate NotificationTemplateDemo(string[] arr) { NotificationTemplate template = new NotificationTemplate(); template.AppId = APPID; template.AppKey = APPKEY; //通知栏标题 template.Title = arr[0]; //通知栏内容 template.Text = arr[1]; //通知栏显示本地图片 template.Logo = ""; //通知栏显示网络图标 template.LogoURL = ""; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = "1"; //透传内容 template.TransmissionContent = arr[2]; // template.TransmissionContent = "{'type':'handover'}"; // template.TransmissionContent = "{'type':'maintain'}"; // template.TransmissionContent = "{'type':'repair'}"; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsRing = true; //接收到消息是否震动,true:震动 false:不震动 template.IsVibrate = false; //接收到消息是否可清除,true:可清除 false:不可清除 template.IsClearable = true; //设置通知定时展示时间,结束时间与开始时间相差需大于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 void NotificationQueue_Constructor_01() { // Arrange var date = DateTime.UtcNow; var template = new NotificationTemplate("template", "subject", "body") { BodyType = NotificationBodyTypes.Text, Priority = NotificationPriorities.Low, Encoding = NotificationEncodings.Base64, Tag = "tag" }; var project = EntityHelper.CreateProject(1, 1); // Act var queue = new NotificationQueue(template, project, "to", "subject", "body"); // Assert queue.Id.Should().Be(0); queue.Key.Should().NotBeEmpty(); queue.TemplateId.Should().Be(template.Id); queue.Template.Should().Be(template); queue.Subject.Should().Be("subject"); queue.Body.Should().Be("body"); queue.BodyType.Should().Be(template.BodyType); queue.Priority.Should().Be(template.Priority); queue.Encoding.Should().Be(template.Encoding); queue.Tag.Should().Be(template.Tag); queue.ProjectId.Should().Be(project.Id); queue.Project.Should().Be(project); queue.To.Should().Be("to"); queue.SendOn.Should().BeOnOrAfter(date); }
private static string HOST = "http://sdk.open.api.igexin.com/apiex.htm"; //HOST:OpenService接口地址 //PushMessageToSingle接口测试代码 public static string PushMessageToSingle(string cid, string title, string messageText) { // 推送主类 IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); /*消息模版: * 1.TransmissionTemplate:透传模板 * 2.LinkTemplate:通知链接模板 * 3.NotificationTemplate:通知透传模板 * 4.NotyPopLoadTemplate:通知弹框下载模板 */ //TransmissionTemplate template = TransmissionTemplateDemo(); NotificationTemplate template = NotificationTemplateDemo(title, messageText); //LinkTemplate template = LinkTemplateDemo(); //NotyPopLoadTemplate template = NotyPopLoadTemplateDemo(); // 单推消息模型 SingleMessage message = new SingleMessage(); message.IsOffline = false; // 用户当前不在线时,是否离线存储,可选 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 = cid; string pushResult = push.pushMessageToSingle(message, target); return(pushResult); }
public async Task <int> AddAsync(NotificationTemplate entity) { int result = 0; try { using (var connection = new SqlConnection(connString)) { entity.DateCreated = DateTime.Now; connection.Open(); result = await connection.ExecuteAsync("Sp_NotificationTemplate_Insert", new { entity.Name, entity.CreatedBy, entity.DateCreated, entity.Description, entity.NotificationTypeId, entity.NotificationChannelId, }, commandType : CommandType.StoredProcedure); return(result); } } catch (Exception ex) { ex.Message.ToString(); return(result); } }
public void SeedNotificationTemplates() { var notificationTemplate = new NotificationTemplate { Name = "Activation of an account after registration", Abbreviation = "ARR", Description = "This template is using for notify users who has just registered their account and need a full activation.", Body = "Dear user {UserName}, <br /> Here is your activation link: <a href=\"{ActivationUri}\">{ActivationUri}</a>.", Subject = "Account activation" }; context.Add(notificationTemplate); notificationTemplate = new NotificationTemplate { Name = "Reset password of an account", Abbreviation = "RPS", Description = "This template is using for notify users who want to reset their accounts passwords.", Body = "Dear user {UserName}, <br /> In order to reset account password please use following link: <a href=\"{ResetPasswordUri}\">{ResetPasswordUri}</a>.", Subject = "Reset account password" }; context.Add(notificationTemplate); context.SaveChanges(); }
/// <summary> /// 点击通知打开应用 /// </summary> /// <param name="title">通知栏标题</param> /// <param name="text">通知栏内容</param> /// <param name="content">透传内容</param> /// <param name="logo">通知栏显示本地图片</param> /// <param name="logUrl">通知栏显示网络图标</param> /// <param name="transmissionType">应用启动类型,1:强制应用启动 2:等待应用启动</param> /// <param name="isRing">接收到消息是否响铃,true:响铃 false:不响铃</param> /// <param name="isVibrate">接收到消息是否震动,true:震动 false:不震动</param> /// <param name="isClearable">接收到消息是否可清除,true:可清除 false:不可清除</param> /// <returns></returns> private NotificationTemplate NotificationTemplateDemo(string title, string text, string content, string logo = "", string logUrl = "", string transmissionType = "1", bool isRing = true, bool isVibrate = true, bool isClearable = true) { NotificationTemplate template = new NotificationTemplate(); template.AppId = Appid; template.AppKey = Appkey; //通知栏标题 template.Title = title; //通知栏内容 template.Text = text; //通知栏显示本地图片 template.Logo = logo; //通知栏显示网络图标 template.LogoURL = logUrl; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = transmissionType; //透传内容 template.TransmissionContent = content; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsRing = isRing; //接收到消息是否震动,true:震动 false:不震动 template.IsVibrate = isVibrate; //接收到消息是否可清除,true:可清除 false:不可清除 template.IsClearable = isClearable; //设置客户端展示时间 //String begin = "2015‐03‐06 14:36:10"; //String end = "2015‐03‐06 14:46:20"; //template.setDuration(begin, end); return(template); }
internal void ValidateTemplate(NotificationTemplate template, string platform) { if (template == null) { throw new HttpResponseException(this.Request.CreateBadRequestResponse(RResources.NotificationHub_TemplateWasNull.FormatForUser())); } if (template.Body == null) { template.Body = string.Empty; } if (platform.Equals(WindowsStorePlatform, StringComparison.OrdinalIgnoreCase)) { if (template.Headers != null) { foreach (string headerName in template.Headers.Keys) { if (string.IsNullOrEmpty(template.Headers[headerName])) { throw new HttpResponseException(this.Request.CreateBadRequestResponse(RResources.NotificationHub_EmptyHeaderValueInSecondaryTileForHeaderName.FormatForUser(headerName))); } } } } else if (platform.Equals(ApplePlatform, StringComparison.OrdinalIgnoreCase) || platform.Equals(GooglePlatform, StringComparison.OrdinalIgnoreCase)) { if (template.Headers != null) { throw new HttpResponseException(this.Request.CreateBadRequestResponse(RResources.NotificationHub_DoesNotSupportTemplateHeaders.FormatForUser(platform))); } } }
public static NotificationTemplate NotificationTemplateDemo(string strAdvice) { NotificationTemplate template = new NotificationTemplate(); template.AppId = APPID; template.AppKey = APPKEY; //通知栏标题 template.Title = "来自的医生意见"; //通知栏内容 template.Text =strAdvice; //通知栏显示本地图片 template.Logo = ""; //通知栏显示网络图标 template.LogoURL = ""; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = "1"; //透传内容 template.TransmissionContent = ""; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsRing = true; //接收到消息是否震动,true:震动 false:不震动 template.IsVibrate = true; //接收到消息是否可清除,true:可清除 false:不可清除 template.IsClearable = true; return template; }
public bool Add(NotificationTemplate model) { var sql = @"INSERT INTO NotificationTemplate (NotificationTemplateGuid ,Keys ,NotificationTypeGuid ,Subject ,Message ,IsActive ,Priority ,IsRecurring ,RecurringInterval ,CreatedOn ,CreatedBy ) VALUES (@NotificationTemplateGuid ,@Keys ,@NotificationTypeGuid ,@Subject ,@Message ,@IsActive ,@Priority ,@IsRecurring ,@RecurringInterval ,@CreatedOn ,@CreatedBy )"; _context.Connection.Execute(sql, model); return(true); }
internal static WnsSecondaryTile CreateWnsSecondaryTile(NotificationSecondaryTile notificationSecondaryTile) { WnsSecondaryTile secondaryTile = new WnsSecondaryTile(); // Strip the tags. secondaryTile.Tags = new List <string>(); secondaryTile.PushChannelExpired = null; secondaryTile.Templates = new Dictionary <string, InstallationTemplate>(); if (notificationSecondaryTile != null) { secondaryTile.PushChannel = notificationSecondaryTile.PushChannel; // Parse each template for the Secondary Tile and add to installation object. foreach (string templateName in notificationSecondaryTile.Templates.Keys) { NotificationTemplate template = notificationSecondaryTile.Templates[templateName]; secondaryTile.Templates[templateName] = CreateInstallationTemplate(template, NotificationPlatform.Wns); } } else { secondaryTile.PushChannel = string.Empty; } return(secondaryTile); }
/// <summary> /// This method will build the message and parse the result of each content /// </summary> /// <param name="template"></param> /// <param name="request"></param> /// <returns></returns> public NotificationMessage Build(NotificationTemplate template, NotificationRequest request) { if (template == null) { throw new ArgumentNullException(nameof(template)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } var message = new NotificationMessage(template.Type) { Subject = BuildSubject(template, request), From = BuildFrom(template, request), To = BuildTo(template, request), Body = BuildBody(template, request), BccTo = BuildBccTo(template, request), CcTo = BuildCcTo(template, request), ReplyToAddresses = BuildReplyTo(template, request) }; //TODO: can be better if we parse per type maybe ParseMessage(message, request.PayLoad); return(message); }
public async Task CreateNotification_WhenCalled_ProperNotificationExpected() { // ARRANGE var templateData = Substitute.For <INotificationTemplateData>(); templateData.GetKeys().Returns(new List <string> { "{body}" }); templateData.GetValue("{body}").Returns("The body content"); var repository = Substitute.For <IRepository <NotificationTemplate> >(); var notificationTemplate = new NotificationTemplate { Abbreviation = "ABC", Body = "{body}", Subject = "The subject" }; repository.SingleOrDefaultAsync(Arg.Any <Expression <Func <NotificationTemplate, bool> > >()).Returns(notificationTemplate); var expected = new NotificationDto { Body = "The body content", Subject = notificationTemplate.Subject }; var service = new NotificationTemplateService(repository); // ACT var actual = await service.CreateNotification(templateData); // ASSERT actual.Should().BeEquivalentTo(expected); }
/// <summary> /// Add a new record. /// </summary> /// <param name="tclass">Model class.</param> public void Add(NotificationTemplateModel tclass) { try { var watch = new Stopwatch(); watch.Start(); var userId = this.AuthenticationSession.GetUserId(); var entity = new NotificationTemplate { Description = tclass.Description, Title = tclass.Title, Body = tclass.Body, IsDeleted = tclass.IsDeleted, CreatedBy = userId, Created = DateTime.Now, ChangedBy = userId, Changed = DateTime.Now }; this.Entities.AddToNotificationTemplates(entity); watch.Stop(); Log.Debug(string.Format("A new notification template has been added. Took {0}", watch.Elapsed)); } catch (Exception ex) { Log.Exception(ex); } }
public static void Push(string clientId, NotificationTemplate template) { Push(new List <string>() { clientId }, template); }
//通知透传模板动作内容 public NotificationTemplate NotificationTemplateDemo() { NotificationTemplate template = new NotificationTemplate(); template.AppId = APPID; template.AppKey = APPKEY; //通知栏标题 template.Title = "请填写通知标题"; //通知栏内容 template.Text = "请填写通知内容"; //通知栏显示本地图片 template.Logo = ""; //通知栏显示网络图标 template.LogoURL = ""; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = "1"; //透传内容 template.TransmissionContent = "请填写透传内容"; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsRing = true; //接收到消息是否震动,true:震动 false:不震动 template.IsVibrate = true; //接收到消息是否可清除,true:可清除 false:不可清除 template.IsClearable = true; //设置通知定时展示时间,结束时间与开始时间相差需大于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> /// PushMessageToSingle接口测试代码 /// </summary> /// <param name="PaltForm">平台类型 1:苹果 2:安卓</param> /// <param name="clientId"></param> /// <param name="NoticeTitle">通知标题</param> /// <param name="NoticeContent">通知内容</param> /// <param name="custom_content">自定义内容</param> /// <returns></returns> public static string PushMessageToSingle(int PaltForm, string clientId, string NoticeTitle, string NoticeContent, string custom_content) { CLIENTID = clientId; // 推送主类 IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); /*消息模版: * 1.TransmissionTemplate:透传模板 * 2.LinkTemplate:通知链接模板 * 3.NotificationTemplate:通知透传模板 * 4.NotyPopLoadTemplate:通知弹框下载模板 */ //数据经SDK传给您的客户端,由您写代码决定如何处理展现给用户 //TransmissionTemplate template = TransmissionTemplateDemo(PaltForm, NoticeTitle, NoticeContent, custom_content); //LinkTemplate template = LinkTemplateDemo(NoticeTitle, NoticeContent); //NotyPopLoadTemplate template = NotyPopLoadTemplateDemo(NoticeTitle, NoticeContent); //在通知栏显示一条含图标、标题等的通知,用户点击后激活您的应用 NotificationTemplate template = NotificationTemplateDemo(PaltForm, NoticeTitle, NoticeContent, custom_content); SingleMessage message = new SingleMessage(); message.IsOffline = false; // 用户当前不在线时,是否离线存储,可选 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); return(pushResult); }
private NotificationTemplate NotificationTemplateDemo(string AppID, string AppKey) { NotificationTemplate template = new NotificationTemplate(); template.AppId = AppID; template.AppKey = AppKey; //通知栏标题 template.Title = Title; //通知栏内容 template.Text = Text + "-" + ExceptionDate; //通知栏显示本地图片 template.Logo = ""; //通知栏显示网络图标 template.LogoURL = ""; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = "1"; //透传内容 template.TransmissionContent = ExceptionID; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsRing = true; //接收到消息是否震动,true:震动 false:不震动 template.IsVibrate = true; //接收到消息是否可清除,true:可清除 false:不可清除 template.IsClearable = true; //设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟) var date = DateTime.Now; String begin = date.ToString("yyyy-MM-dd HH:mm:ss"); String end = date.AddMinutes(10).ToString("yyyy-MM-dd HH:mm:ss"); template.setDuration(begin, end); return(template); }
public async Task <NotificationResponse> Send(NotificationRequest request, NotificationTemplate template) { var fromAddress = template.EmailAddress; var fromName = template.SenderName; var templateId = template.TemplateId; var toName = request.CustomerId; var toAddress = template.NotificationMethod == Method.SMS ? GetFullSMS(_countryCode, request.CustomerMobile, template.SMSDomain) : request.CustomerEmail; var mailResponse = await SendGridEmail(fromAddress, fromName, toAddress, toName, templateId, request); var response = new NotificationResponse { TransactionId = request.TransactionId, OrderNo = request.OrderNo, ServiceResult = new ServiceResult() { Code = mailResponse.Success ? 0 : 1, Message = string.IsNullOrEmpty(mailResponse.Message) ? "Success" : mailResponse.Message } }; return(response); }
/// <inheritdoc /> public async Task <ApiResponse <NotificationTemplate> > GenerateNotificationTemplate( string tenantId, CreateNotificationsRequest createNotificationsRequest, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(tenantId)) { throw new ArgumentNullException(nameof(tenantId)); } if (createNotificationsRequest == null) { throw new ArgumentNullException(nameof(createNotificationsRequest)); } Uri requestUri = this.ConstructUri($"{tenantId}/marain/usernotifications/templates/generate"); HttpRequestMessage request = this.BuildRequest(HttpMethod.Put, requestUri, createNotificationsRequest); HttpResponseMessage response = await this.SendRequestAndThrowOnFailure(request, cancellationToken).ConfigureAwait(false); using Stream contentStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); NotificationTemplate result = await JsonSerializer.DeserializeAsync <NotificationTemplate>(contentStream, this.SerializerOptions).ConfigureAwait(false); return(new ApiResponse <NotificationTemplate>( response.StatusCode, result)); }
/// <summary> /// 通知透传模板动作内容 /// </summary> /// <param name="Title">通知栏标题</param> /// <param name="Text">通知栏内容</param> /// <param name="Logo">通知栏显示本地图片</param> /// <param name="LogoURL">通知栏显示网络图标</param> /// <param name="TransmissionType">应用启动类型,1:强制应用启动 2:等待应用启动</param> /// <param name="TransmissionContent">透传内容</param> /// <param name="IsRing">接收到消息是否响铃,true:响铃 false:不响铃</param> /// <param name="IsVibrate">接收到消息是否震动,true:震动 false:不震动</param> /// <param name="IsClearable">接收到消息是否可清除,true:可清除 false:不可清除</param> /// <param name="beginTime">设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)</param> /// <param name="endTime">设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)</param> /// <returns></returns> public static NotificationTemplate NotificationTemplate(string Title, string Text, string Logo, string LogoURL, string TransmissionType, string TransmissionContent, bool IsRing, bool IsVibrate, bool IsClearable, string beginTime, string endTime) { NotificationTemplate template = new NotificationTemplate(); template.AppId = APPID; template.AppKey = APPKEY; //通知栏标题 template.Title = Title; //通知栏内容 template.Text = Text; //通知栏显示本地图片 template.Logo = Logo; //通知栏显示网络图标 template.LogoURL = LogoURL; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionType = TransmissionType; //透传内容 template.TransmissionContent = TransmissionContent; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsRing = IsRing; //接收到消息是否震动,true:震动 false:不震动 template.IsVibrate = IsVibrate; //接收到消息是否可清除,true:可清除 false:不可清除 template.IsClearable = IsClearable; //设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟) String begin = beginTime; String end = endTime; if (!string.IsNullOrEmpty(begin) && !string.IsNullOrEmpty(endTime)) { template.setDuration(begin, end); } return(template); }
public bool SendNotifications(NotificationTemplate template) { var client = new SendGridClient(Constants.SendGridAPIKey); var msg = new SendGridMessage(); //msg.SetTemplateId("de68e67f-490a-4e5b-9d89-91f41d2e631d"); msg.SetFrom(new EmailAddress("*****@*****.**", Constants.Name)); msg.AddTo(new EmailAddress(template.receiver.Email, template.receiver.Name)); msg.Subject = GetSubject(template.NotificationType); string emailBody = "Dear " + template.receiver.Name + "<br><br>" + msg.Subject + "<br><br><b>Idea Title:</b>" + template.IdeaTitle; if (!String.IsNullOrEmpty(template.UserComment)) { emailBody += "<br><br>" + template.IdeaSender + " > Comments: " + template.UserComment; } emailBody += "<br><br>Please visit QIdeas now to see the latest updates<br>" + Constants.Site; emailBody += "<br><br>Regards,<br>" + Constants.Name; msg.AddContent(MimeType.Html, emailBody); var response = client.SendEmailAsync(msg); return(true); //return response.StatusCode == System.Net.HttpStatusCode.Unauthorized ? false : true; }
public virtual NotificationMessage Build(NotificationTemplate template, NotificationRequest request) { if (template == null) { throw new ArgumentNullException(nameof(template)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } var message = new NotificationMessage(template.Type, template.FromAddress, template.FromName, template.Subject) { Body = new NotificationMessageBody() { Content = template.Body, Charset = template.Charset, //IsHtml = template.Type == Innovt.Core.Notification.NotificationMessageType.Email } }; foreach (var to in request.To) { message.AddTo(to.Name, to.Address); } ParseMessage(message, request.PayLoad); return(message); }
/// <summary> /// 通知透传模板动作内容 /// </summary> /// <param name="title">通知栏标题</param> /// <param name="text">通知栏内容</param> /// <param name="logo">通知栏显示本地图片</param> /// <param name="logoUrl">通知栏显示网络图标</param> /// <param name="transContent">透传内容</param> /// <param name="beginTM">客户端展示开始时间</param> /// <param name="endTM">客户端展示结束时间</param> public NotificationTemplate NotificationTemplate(string title, string text, string logo, string logoUrl, string transContent, string beginTM, string endTM) { NotificationTemplate template = new NotificationTemplate(); template.AppId = APPID; template.AppKey = APPKEY; template.Title = title; //通知栏标题 template.Text = text; //通知栏内容 template.Logo = logo; //通知栏显示本地图片 template.LogoURL = logoUrl; //通知栏显示网络图标,如https://www.baidu.com/img/bd_logo1.png template.TransmissionType = "1"; //应用启动类型,1:强制应用启动 2:等待应用启动 template.TransmissionContent = transContent; //透传内容 //iOS推送需要的pushInfo字段 //template.setPushInfo(actionLocKey, badge, message, sound, payload, locKey, locArgs, launchImage); //设置客户端展示时间 String begin = beginTM; String end = endTM; template.setDuration(begin, end); template.IsRing = true; //接收到消息是否响铃,true:响铃 false:不响铃 template.IsVibrate = true; //接收到消息是否震动,true:震动 false:不震动 template.IsClearable = true; //接收到消息是否可清除,true:可清除 false:不可清除 return(template); }
public IHttpActionResult GetNotificationTemplate(string type, string objectId, string objectTypeId, string language) { NotificationTemplate retVal = new NotificationTemplate(); var notification = _notificationManager.GetNewNotification(type, objectId, objectTypeId, language); if (notification != null) { retVal = notification.NotificationTemplate; } return Ok(retVal.ToWebModel()); }
public IHttpActionResult GetNotificationTemplate(string type, string objectId, string objectTypeId, string language) { NotificationTemplate retVal = new NotificationTemplate(); var criteria = new GetNotificationCriteria() { Type = type, ObjectId = objectId, ObjectTypeId = objectTypeId, Language = language }; var notification = _notificationManager.GetNewNotification(criteria); if (notification != null) { retVal = notification.NotificationTemplate; } return Ok(retVal.ToWebModel()); }
/// <summary> /// Update notification template /// </summary> /// <exception cref="VirtoCommerce.Platform.Client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="notificationTemplate">Notification template</param> /// <returns></returns> public void NotificationsUpdateNotificationTemplate(NotificationTemplate notificationTemplate) { NotificationsUpdateNotificationTemplateWithHttpInfo(notificationTemplate); }
/// <summary> /// Update notification template /// </summary> /// <exception cref="VirtoCommerce.Platform.Client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="notificationTemplate">Notification template</param> /// <returns>Task of ApiResponse</returns> public async System.Threading.Tasks.Task<ApiResponse<object>> NotificationsUpdateNotificationTemplateAsyncWithHttpInfo(NotificationTemplate notificationTemplate) { // verify the required parameter 'notificationTemplate' is set if (notificationTemplate == null) throw new ApiException(400, "Missing required parameter 'notificationTemplate' when calling VirtoCommercePlatformApi->NotificationsUpdateNotificationTemplate"); var localVarPath = "/api/platform/notification/template"; var localVarPathParams = new Dictionary<string, string>(); var localVarQueryParams = new Dictionary<string, string>(); var localVarHeaderParams = new Dictionary<string, string>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary<string, string>(); var localVarFileParams = new Dictionary<string, FileParameter>(); object localVarPostBody = null; // to determine the Content-Type header string[] localVarHttpContentTypes = new string[] { "application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded" }; string localVarHttpContentType = ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header string[] localVarHttpHeaderAccepts = new string[] { }; string localVarHttpHeaderAccept = ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json localVarPathParams.Add("format", "json"); if (notificationTemplate.GetType() != typeof(byte[])) { localVarPostBody = ApiClient.Serialize(notificationTemplate); // http body (model) parameter } else { localVarPostBody = notificationTemplate; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (localVarStatusCode >= 400 && (localVarStatusCode != 404 || Configuration.ThrowExceptionWhenStatusCodeIs404)) throw new ApiException(localVarStatusCode, "Error calling NotificationsUpdateNotificationTemplate: " + localVarResponse.Content, localVarResponse.Content); else if (localVarStatusCode == 0) throw new ApiException(localVarStatusCode, "Error calling NotificationsUpdateNotificationTemplate: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); return new ApiResponse<object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), null); }
/// <summary> /// Update notification template /// </summary> /// <exception cref="VirtoCommerce.Platform.Client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="notificationTemplate">Notification template</param> /// <returns>Task of void</returns> public async System.Threading.Tasks.Task NotificationsUpdateNotificationTemplateAsync(NotificationTemplate notificationTemplate) { await NotificationsUpdateNotificationTemplateAsyncWithHttpInfo(notificationTemplate); }