/// <summary> /// Sends the push message. /// </summary> /// <param name="request">The request.</param> /// <returns>PushResponse.</returns> public PushResponse SendPushMessage(PushMessageRequestV3 request) { try { var response = client.SendPushMessage(request); if (this.CreateDelegate != null) { this.CreateDelegate.Invoke(request, response); } if (response != null && !string.IsNullOrWhiteSpace(response.MessageId)) { this.AddMessageTrackingId(new PushMessageTracking { MessageId = response.MessageId, CreatedUtcStamp = DateTime.UtcNow }); } return(response); } catch (Exception ex) { this.HandleException(new Exception("Failed to send push message", ex)); } return(null); }
/// <summary> /// 执行发送消息方法 /// </summary> /// <param name="pushMsg">消息实体</param> /// <returns>是否推送成功</returns> private bool DoPost(PushMessageRequestV3 pushMsg) { var response = _pushClient.SendPushMessage(pushMsg); Logger.Info(response.ResponseCode.ToString() + ":" + response.ResponseMessage); return(true); }
/// <summary> /// 创建消息实体 /// </summary> /// <param name="title">消息标题</param> /// <param name="content">内容</param> /// <returns>消息实体</returns> private PushMessageRequestV3 CreatePushMsg(string title, string content, Dictionary <string, object> objs, string registId = null, List <string> alias = null, string tagAnd = null, string tagOr = null) { var customzedValues = new Dictionary <string, string>(); if (objs != null) { foreach (var obj in objs) { customzedValues.Add(obj.Key, obj.Value.ToString()); } } Audience audience = new Audience(); if (!string.IsNullOrEmpty(registId)) { var registIdList = new List <string>(); registIdList.Add(registId); audience.Add(PushTypeV3.ByRegistrationId, registIdList); } else if (!string.IsNullOrEmpty(tagAnd)) { audience.Add(PushTypeV3.ByTagWithinAnd, new List <string>(new string[] { tagAnd })); } else if (!string.IsNullOrEmpty(tagOr)) { audience.Add(PushTypeV3.ByTagWithinOr, new List <string>(new string[] { tagOr })); } else if (alias != null) { audience.Add(PushTypeV3.ByAlias, alias); } else { audience.Add(PushTypeV3.Broadcast, null); } // In JPush V3, Notification would not be display on screen, it would be transferred to app instead. // And different platform can provide different notification data. Notification notification = new Notification { AndroidNotification = new AndroidNotificationParameters { Title = title, Alert = content, CustomizedValues = customzedValues, }, iOSNotification = new iOSNotificationParameters { Badge = "+1", Alert = content, Sound = "YourSound", CustomizedValues = customzedValues, } }; PushMessageRequestV3 newPush = new PushMessageRequestV3 { Audience = audience, IsTestEnvironment = true, AppMessage = new AppMessage { Content = content }, Notification = notification }; return(newPush); }
/// <summary> /// 创建消息实体 /// </summary> /// <param name="title">消息标题</param> /// <param name="content">内容</param> /// <returns>消息实体</returns> private PushMessageRequestV3 CreatePushMsg(string title, string content, Dictionary<string, object> objs, string registId = null,List<string> alias = null, string tagAnd = null, string tagOr = null) { var customzedValues = new Dictionary<string, string>(); if (objs != null) { foreach (var obj in objs) { customzedValues.Add(obj.Key, obj.Value.ToString()); } } Audience audience = new Audience(); if (!string.IsNullOrEmpty(registId)) { var registIdList = new List<string>(); registIdList.Add(registId); audience.Add(PushTypeV3.ByRegistrationId, registIdList); } else if (!string.IsNullOrEmpty(tagAnd)) { audience.Add(PushTypeV3.ByTagWithinAnd, new List<string>(new string[] { tagAnd })); } else if (!string.IsNullOrEmpty(tagOr)) { audience.Add(PushTypeV3.ByTagWithinOr, new List<string>(new string[] { tagOr })); } else if (alias != null) { audience.Add(PushTypeV3.ByAlias, alias); }else { audience.Add(PushTypeV3.Broadcast, null); } // In JPush V3, Notification would not be display on screen, it would be transferred to app instead. // And different platform can provide different notification data. Notification notification = new Notification { AndroidNotification = new AndroidNotificationParameters { Title = title, Alert = content, CustomizedValues = customzedValues, }, iOSNotification = new iOSNotificationParameters { Badge = "+1", Alert = content, Sound = "YourSound", CustomizedValues = customzedValues, } }; PushMessageRequestV3 newPush = new PushMessageRequestV3 { Audience = audience, IsTestEnvironment = true, AppMessage = new AppMessage { Content = content }, Notification = notification }; return newPush; }
/// <summary> /// 执行发送消息方法 /// </summary> /// <param name="pushMsg">消息实体</param> /// <returns>是否推送成功</returns> private bool DoPost(PushMessageRequestV3 pushMsg) { var response = _pushClient.SendPushMessage(pushMsg); Logger.Info(response.ResponseCode.ToString() + ":" + response.ResponseMessage); return true; }