Пример #1
0
        private void JPush(IEnumerable <SaleMessage> messages)
        {
            foreach (var message in messages)
            {
                //var customizedValues = new Dictionary<string, string>
                //{
                //    {"type", message.MessageType.ToString()},
                //    {"id", message.RelateId.ToString()}
                //};

                //{"JName":"0","JValue":"/Web/user/index?getCustomerId=28861,测试极光推送"}
                //{"JName":"1001","JValue":"28861"}
                //{"JName":"2","JValue":""}
                //{"JName":"10","JValue":""}

                var jp = new JavaScriptSerializer().Deserialize <JParams>(message.JParams);
                var customizedValues = new Dictionary <string, string>
                {
                    { "jName", jp.JName },
                    { "jValue", jp.JValue }
                };
                var client   = new JPushClientV3(_appKey, _masterSecret);
                var audience = new Audience();

                //audience.AddItem(PushTypeV3.Broadcast, "all");
                audience.AddItem(PushTypeV3.ByAlias, message.EmployeeId.ToString().Replace("-", ""));
                var response = client.SendPushMessage(new PushMessageRequestV3
                {
                    Notification = new Notification
                    {
                        AndroidNotification = new AndroidNotificationParameters
                        {
                            Title            = message.Title ?? "",
                            Alert            = message.Content ?? "",
                            CustomizedValues = customizedValues,
                        }
                    },
                    AppMessage = new AppMessage {
                        Title = message.Title ?? "", Content = message.Content ?? ""
                    },
                    Audience = audience,
                    Platform = PushPlatform.Android,
                    LifeTime = 863000,
                });

                //更新信息状态
                message.IsSent = true;
                //Modify(message);
            }
        }