コード例 #1
0
        private static string processPayload(string locKey, string locArgs, string message, string actionLocKey, string launchImage, string badge, string sound, string payload, int contentAvailable)
        {
            bool flag = false;

            ApnsUtils.Payload payload2 = new ApnsUtils.Payload();
            if (locKey != null && locKey.Length > 0)
            {
                payload2.AlertLocKey = locKey;
                if (locArgs != null && locArgs.Length > 0)
                {
                    payload2.AlertLocArgs = locArgs.Split(new char[]
                    {
                        ','
                    });
                }
                flag = true;
            }
            if (message != null && message.Length > 0)
            {
                payload2.AlertBody = message;
                flag = true;
            }
            if (actionLocKey != null && actionLocKey.Length > 0)
            {
                payload2.AlertActionLocKey = actionLocKey;
            }
            if (launchImage != null && launchImage.Length > 0)
            {
                payload2.AlertLaunchImage = launchImage;
            }
            int num = -1;

            try
            {
                num = int.Parse(badge);
            }
            catch (Exception innerException)
            {
                throw new Exception("unBindAlias失败 {0}", innerException);
            }
            if (num >= 0)
            {
                payload2.Badge = num;
                flag           = true;
            }
            if (!string.IsNullOrEmpty(sound))
            {
                payload2.Sound = sound;
            }
            else
            {
                payload2.Sound = "default";
            }
            if (!string.IsNullOrEmpty(payload))
            {
                payload2.addParam("payload", payload);
            }
            if (contentAvailable == 1)
            {
                payload2.ContentAvailable = 1;
            }
            if (!flag)
            {
                throw new Exception("one of the params(locKey,message,badge) must not be null or contentAvailable must be 1");
            }
            string expr_F8 = payload2.ToString();

            if (expr_F8 == null)
            {
                throw new Exception("payload json is null");
            }
            return(expr_F8);
        }
コード例 #2
0
        private static string processPayload(
            string locKey,
            string locArgs,
            string message,
            string actionLocKey,
            string launchImage,
            string badge,
            string sound,
            string payload,
            int contentAvailable)
        {
            bool flag = false;

            ApnsUtils.Payload payload1 = new ApnsUtils.Payload();
            if (locKey != null && locKey.Length > 0)
            {
                payload1.AlertLocKey = locKey;
                if (locArgs != null && locArgs.Length > 0)
                {
                    payload1.AlertLocArgs = locArgs.Split(',');
                }
                flag = true;
            }
            if (message != null && message.Length > 0)
            {
                payload1.AlertBody = message;
                flag = true;
            }
            if (actionLocKey != null && actionLocKey.Length > 0)
            {
                payload1.AlertActionLocKey = actionLocKey;
            }
            if (launchImage != null && launchImage.Length > 0)
            {
                payload1.AlertLaunchImage = launchImage;
            }
            int num;

            try
            {
                num = int.Parse(badge);
            }
            catch (Exception ex)
            {
                throw new Exception("unBindAlias失败 {0}", ex);
            }
            if (num >= 0)
            {
                payload1.Badge = num;
                flag           = true;
            }
            payload1.Sound = string.IsNullOrEmpty(sound) ? "default" : sound;
            if (!string.IsNullOrEmpty(payload))
            {
                payload1.addParam(nameof(payload), (object)payload);
            }
            if (contentAvailable == 1)
            {
                payload1.ContentAvailable = 1;
            }
            if (!flag)
            {
                throw new Exception("one of the params(locKey,message,badge) must not be null or contentAvailable must be 1");
            }
            string str = payload1.ToString();

            if (str != null)
            {
                return(str);
            }
            throw new Exception("payload json is null");
        }