Beispiel #1
0
        public JPush()
        {
            var appKey       = ConfigurationManager.AppSettings["JPush_Key"].Trim();
            var masterSecret = ConfigurationManager.AppSettings["JPush_MasterSecret"].Trim();

            _pushClient = new JPushClientV3(appKey, masterSecret);
        }
        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);
            }
        }
Beispiel #3
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 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JPushClient" /> class.
        /// </summary>
        /// <param name="appKey">The application key.</param>
        /// <param name="masterSecret">The master secret.</param>
        /// <param name="createPushMessageLogDelegate">The create push message log delegate.</param>
        /// <param name="updatePushMessageStatusDelegate">The update push message status delegate.</param>
        /// <param name="initializeDelegate">The initialize delegate.</param>
        /// <param name="exceptionDelegate">The exception delegate.</param>
        /// <param name="intervalInSecond">The interval in second.</param>
        public JPushHandler(string appKey, string masterSecret,
                            CreatePushMessageLogDelegate createPushMessageLogDelegate       = null,
                            UpdatePushMessageStatusDelegate updatePushMessageStatusDelegate = null,
                            InitializeMessageTrackingIdDelegate initializeDelegate          = null,
                            ReportExceptionDelegate exceptionDelegate = null,
                            int intervalInSecond = 60)
        {
            client = new JPushClientV3(appKey, masterSecret);

            if (intervalInSecond < 1)
            {
                intervalInSecond = 60;
            }

            this.IntervalInSecond        = intervalInSecond;
            this.pushMessageTrackingList = new List <PushMessageTracking>();

            this.CreateDelegate     = createPushMessageLogDelegate;
            this.UpdateDelegate     = updatePushMessageStatusDelegate;
            this.InitializeDelegate = initializeDelegate;
            this.ExceptionDelegate  = exceptionDelegate;

            InitializeBackgroundThread();
        }
Beispiel #5
0
 public JPush()
 {
     var appKey = ConfigurationManager.AppSettings["JPush_Key"].Trim();
     var masterSecret = ConfigurationManager.AppSettings["JPush_MasterSecret"].Trim();
     _pushClient = new JPushClientV3(appKey, masterSecret);
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JPushClient" /> class.
 /// </summary>
 /// <param name="appKey">The application key.</param>
 /// <param name="masterSecret">The master secret.</param>
 /// <param name="useSSL">if set to <c>true</c> [use SSL].</param>
 public JPushClient(string appKey, string masterSecret, bool useSSL = true)
 {
     clientV3 = new JPushClientV3(appKey, masterSecret);
 }