关于极光推送C#服务端代码的一些问题

/// <summary>
        ///     发送通知(指定RegistrationId)
        /// </summary>
        /// <param name="registrationId"></param>
        /// <param name="title"></param>
        /// <param name="alert"></param>
        /// <param name="customizedValues"></param>
        public static bool SendNoticeByRegistrationId(string registrationId, string title, string alert, Dictionary<string, string> customizedValues)
        {
            try
            {
                JPushClientV3 client = new JPushClientV3(appKey, masterSecret);
                Audience audience = new Audience();
                // In JPush V3, tag can be multiple added with different values.
                // In following code, it is to send push to those who are in ((Tag1 AND Tag2) AND (Tag3 OR Tag4))
                // If you want to send to all, please use: audience.Add(PushTypeV3.Broadcast, null);
                //            audience.Add(PushTypeV3.ByTagWithinAnd, new List<string>(new string[] { "Tag1", "Tag2" }));
                //            audience.Add(PushTypeV3.ByTagWithinOr, new List<string>(new string[] { "Tag3", "Tag4" }));


                audience.Add(PushTypeV3.ByRegistrationId, new List<string> { registrationId });
                Notification notification = new Notification
                {
                    AndroidNotification = new AndroidNotificationParameters
                    {
                        BuilderId = 1,
                        Title = title,
                        Alert = alert,
                        CustomizedValues = customizedValues
                    }
                };




                var response = client.SendPushMessage(new PushMessageRequestV3
                {
                    Audience = audience,
                    Platform = PushPlatform.Android,
                    IsTestEnvironment = false,
                    Notification = notification
                });
                var message = response.ResponseMessage;
                List<string> idToCheck = new List<string>();
                idToCheck.Add(response.MessageId);

                var statusList = client.QueryPushMessageStatus(idToCheck);


                if (statusList != null)
                {
                    if (statusList[0].AndroidDeliveredCount > 0)
                    {
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return false;

        }


上述是极光推送官网给的Demo,在调试的时候,走到var statusList = client.QueryPushMessageStatus(idToCheck);的时候总会报异常,异常的内容是:Failed to QueryPushMessageStatus ,百度了半天也没有查到这个异常消息是什么意思。后来经过监控,发现有一部分是可以通过的,有一部分会报异常,再查了一下,是因为response.MessageId在大于int.MaxValue的时候,会出现异常。于是在 上边加了一句                

if (Convert.ToInt32(response.MessageId) > int.MaxValue)
                {
                    return true;
                }

问题就解决了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值