Beispiel #1
0
 protected FriendNewsfeedEvent(IEnumerable <Guid> friends)
 {
     Variant = "info";
     foreach (Guid friend in friends)
     {
         Audience.Add(friend);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 极光推送
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public PushResponse SendPush(PushRequest request)
        {
            var client   = new JPushClientV3(AppKey, MasterSecret);
            var audience = new Audience();

            if (request.type == 0)
            {
                audience.Add(PushTypeV3.Broadcast, null);
            }
            else
            {
                audience.Add(PushTypeV3.ByTagWithinAnd, new List <string>(new[] { request.userId, request.userId }));
            }
            var customizedValues = new Dictionary <string, object>
            {
                { "JPushValue", request.value }
            };
            var notification = new Notification
            {
                AndroidNotification = new AndroidNotificationParameters
                {
                    Title            = request.title,
                    Alert            = request.content,
                    CustomizedValues = customizedValues
                }
            };
            var response = client.SendPushMessage(new PushMessageRequestV3
            {
                Audience          = audience,
                Platform          = PushPlatform.AndroidAndiOS,
                Notification      = notification,
                IsTestEnvironment = true,
                AppMessage        = new AppMessage
                {
                    Content         = request.value,
                    CustomizedValue = customizedValues
                },
            });

            return(response);
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <summary>
        /// To the push message request v3.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Beyova.JPush.V3.PushMessageRequestV3.</returns>
        public static Beyova.JPush.V3.PushMessageRequestV3 ToPushMessageRequestV3(this PushMessageRequest request)
        {
            Beyova.JPush.V3.PushMessageRequestV3 result = null;

            if (request != null)
            {
                result = new Beyova.JPush.V3.PushMessageRequestV3()
                {
                    Platform          = request.Platform,
                    IsTestEnvironment = request.IsTestEnvironment,
                    LifeTime          = request.LifeTime,
                    OverrideMessageId = request.OverrideMessageId,
                    Notification      = new Notification(),
                    AppMessage        = new AppMessage
                    {
                        Content         = request.Message.Content,
                        Title           = request.Message.PushTitle,
                        CustomizedValue = request.Message.CustomizedValue
                    }
                };

                Audience      audience = new Audience();
                List <string> list     = new List <string>(request.ReceiverValue.Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries));

                switch (request.PushType)
                {
                case PushType.Broadcast:
                    audience.Add(PushTypeV3.Broadcast, null);
                    break;

                case PushType.ByAlias:
                    audience.Add(PushTypeV3.ByAlias, list);
                    break;

                case PushType.ByRegistrationId:
                    audience.Add(PushTypeV3.ByRegistrationId, list);
                    break;

                case PushType.ByTag:
                    audience.Add(PushTypeV3.ByTagWithinOr, list);
                    break;

                default:
                    break;
                }

                result.Audience = audience;

                Notification notification = new Notification();
                if ((request.Platform & PushPlatform.Android) == PushPlatform.Android)
                {
                    result.Notification.AndroidNotification = new AndroidNotificationParameters
                    {
                        Alert            = request.Message.Content,
                        BuilderId        = request.Message.BuilderId,
                        CustomizedValues = request.Message.CustomizedValue,
                        Title            = request.Message.PushTitle
                    };
                }
                if ((request.Platform & PushPlatform.iOS) == PushPlatform.iOS)
                {
                    result.Notification.iOSNotification = new iOSNotificationParameters
                    {
                        Alert            = request.Message.Content,
                        Sound            = request.Message.Sound,
                        CustomizedValues = request.Message.CustomizedValue,
                        Badge            = request.Message.BadgeValue
                    };
                }
            }

            return(result);
        }
Beispiel #5
0
        /// <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;
        }
 protected OwnNewsfeedEvent(Guid userId)
 {
     Audience.Add(userId);
     Variant = "success";
 }