コード例 #1
0
        public void FullPropertyMessage()
        {
            var message = new Message()
            {
                Data         = "k1=1,k2=2",
                Notification = new Notification
                {
                    Title = "Notification",
                    Body  = "Hello world!",
                    Image = "https://example.com/image.png"
                },
                Android = new AndroidConfig
                {
                    CollapseKey   = -1,
                    Urgency       = UrgencyPriority.NORMAL,
                    Category      = "PLAY_VOICE",
                    TTL           = TimeSpan.FromSeconds(20),
                    BITag         = "Test",
                    FastAppTarget = FastAppTarget.Development,
                    Data          = "k1=1,k2=2",
                    Notification  = new AndroidNotification
                    {
                        Title        = "Notification",
                        Body         = "Hello world!",
                        Icon         = "icon.png",
                        Color        = "#000000",
                        Sound        = "sound.mp3",
                        DefaultSound = false,
                        Tag          = "News",
                        ClickAction  = ClickAction.OpenApp(),
                        //ClickAction = ClickAction.OpenUrl("https://example.com"),
                        //ClickAction = ClickAction.OpenRichResource("https://example.com/res.zip"),
                        //ClickAction = ClickAction.CustomAction("customAction"),
                        //ClickAction = ClickAction.CustomIntent("customIntent"),
                        BodyLocKey  = "title_key",
                        BodyLocArgs = new List <string>()
                        {
                            "arg1", "arg2"
                        },
                        TitleLocKey  = "body_key",
                        TitleLocArgs = new List <string>()
                        {
                            "arg1", "arg2"
                        },
                        MultiLangKey = new JObject
                        {
                            ["title_key"] = new JObject
                            {
                                ["zh"] = "ÄãºÃ",
                                ["en"] = "Hello",
                            },
                            ["body_key"] = new JObject
                            {
                                ["zh"] = "ÔÙ¼û",
                                ["en"] = "Byte",
                            }
                        },
                        ChannelId     = "channel1",
                        NotifySummary = "notify summary",
                        Image         = "https://example.com/image.png",
                        Style         = NotificationStyle.BigText,
                        BigTitle      = "Big tile",
                        BigBody       = "Big body",
                        AutoClear     = 20,
                        NotifyId      = -1,
                        Group         = "News",
                        Badge         = new BadgeNotification
                        {
                            AddNum = 13,
                            SetNum = 10,
                            Class  = "com.huawei.DemoActivity",
                        },
                        Ticker                = "Say hello.",
                        AutoCancel            = false,
                        EventTime             = DateTime.Now,
                        Importance            = NotificationImportance.NORMAL,
                        DefaultVibrateTimings = false,
                        VibrateTimings        = new double[] { 1, 1, 1, 1 },
                        Visibility            = NotificationVisibility.VISIBILITY_UNSPECIFIED,
                        DefaultLightSettings  = false,
                        LightSettings         = new LightSettings
                        {
                            Color            = LightColor.FromArbg(0.5, 1.0, 0.5),
                            LightOnDuration  = TimeSpan.FromSeconds(3),
                            LightOffDuration = TimeSpan.FromSeconds(3),
                        },
                        ForegroundShow = true
                    }
                },
                Apns = new ApnsConfig
                {
                    HmsOptions = new ApnsHmsOptions
                    {
                        TargetUserType = ApnsTargetUserType.Test
                    },
                    Headers = new Dictionary <string, string>
                    {
                        ["authorization"]    = "bearer xxxxx",
                        ["apns-id"]          = "123e4567-e89b-12d3-a456-42665544000",
                        ["apns-expiration"]  = "0",
                        ["apns-priority"]    = "10",
                        ["apns-topic"]       = "Apple",
                        ["apns-collapse-id"] = "collapse-id",
                    },
                    Aps = new Aps
                    {
                        //AlertString = "hello",
                        Alert = new ApsAlert
                        {
                            Title           = "Notification",
                            Subtitle        = "Say Hello",
                            Body            = "Hello world!",
                            LaunchImage     = "launch.png",
                            TitleLocKey     = "title-loc-key",
                            TitleLocArgs    = new string[] { "arg1", "arg2" },
                            SubtitleLocKey  = "subtitle-loc-key",
                            SubtitleLocArgs = new string[] { "arg1", "arg2" },
                            LocKey          = "loc-key",
                            LocArgs         = new string[] { "arg1", "arg2" },
                        },
                        Badge = 0,
                        //Sound = "Sound",
                        CriticalSound = new CriticalSound
                        {
                            Critical = true,
                            Name     = "hh",
                            Volume   = 0.5
                        },
                        ContentAvailable = true,
                        MutableContent   = true,
                        Category         = "News",
                        ThreadId         = "thread-id",
                        TargetContentId  = "target-content-id",
                        CustomData       = new Dictionary <string, object>
                        {
                            ["custom-key"] = "custom-value"
                        }
                    },
                },
                Webpush = new WebpushConfig
                {
                    HmsOptions = new WebpushHmsOptions
                    {
                        Link = "https://example.com"
                    },
                    Headers = new Dictionary <string, string>
                    {
                        ["ttl"]     = "20s",
                        ["topic"]   = "topic",
                        ["urgency"] = "normal"  // very-low | low | normal | high
                    },
                    Notification = new WebpushNotification
                    {
                        Title              = "Notification",
                        Body               = "Hello world!",
                        Icon               = "https://example.com/icon.png",
                        Image              = "https://example.com/image.png",
                        Language           = "zh",
                        Tag                = "News",
                        Badge              = "https://example.com/badge.png",
                        Direction          = Direction.Auto,
                        Vibrate            = new int[] { 100, 200, 300 },
                        Renotify           = false,
                        RequireInteraction = false,
                        Silent             = false,
                        Timestamp          = 1575722408765,
                        Actions            = new WebpushAction[]
                        {
                            new WebpushAction
                            {
                                Action = "ok",
                                Title  = "OK",
                                Icon   = "https://example.com/ok.png"
                            },
                            new WebpushAction
                            {
                                Action = "close",
                                Title  = "Close",
                                Icon   = "https://example.com/close.png"
                            }
                        },
                        Data = new JObject
                        {
                            ["mykey"] = "myvalue"
                        },
                        CustomData = new Dictionary <string, object>
                        {
                            ["other-property"] = "other-value"
                        }
                    }
                },
                Token = new List <string> {
                    "xxxxxxxxxxxxxxxxx"
                },
                //Topic = "game",
                //Condition = "game in topics"
            };

            AssertJsonEquals("{}", message.CopyAndValidate());
        }