/// <summary>
        /// 推送单个设备,限iOS系统使用。
        /// </summary>
        /// <param name="deviceToken"></param>
        /// <param name="msg"></param>
        /// <param name="env"></param>
        /// <returns></returns>
        public string PushSingleDevice(string deviceToken, MessageIOS msg, iOSEnvironment env)
        {
            if (!isValidMessageType(msg, env))
            {
                return("{'ret_code':-1,'err_msg':'message type or environment error!'}");
            }

            if (!msg.isValid())
            {
                return("{'ret_code':-1,'err_msg':'message invalid!'}");
            }

            var param = new Dictionary <string, object>
            {
                { Constants.access_id, m_access_id },
                { Constants.expire_time, msg.getExpireTime() },
                { Constants.send_time, msg.getSendTime() },
                { Constants.device_token, deviceToken },
                { Constants.message_type, msg.getType() },
                { Constants.message, msg.toJson() },
                { Constants.timestamp, GetTimestamp() },
                { Constants.environment, env }
            };

            if (msg.getLoopInterval() > 0 && msg.getLoopTimes() > 0)
            {
                param.Add(Constants.loop_interval, msg.getLoopInterval());
                param.Add(Constants.loop_times, msg.getLoopTimes());
            }
            var ret = callRestful(RESTAPI_PUSHSINGLEDEVICE, param);

            return(ret);
        }
        /// <summary>
        /// 创建批量推送消息,后续利用生成的 pushid 配合 PushAccountListMultiple
        /// 或 PushDeviceListMultiple 接口使用,限iOS系统使用。
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="env"></param>
        /// <returns></returns>
        public string CreateMultipush(MessageIOS msg, iOSEnvironment env)
        {
            if (!isValidMessageType(msg, env))
            {
                return("{'ret_code':-1,'err_msg':'message type or environment error!'}");
            }

            if (!msg.isValid())
            {
                return("{'ret_code':-1,'err_msg':'message invalid!'}");
            }

            var param = new Dictionary <string, object>
            {
                { Constants.access_id, m_access_id },
                { Constants.expire_time, msg.getExpireTime() },
                { Constants.message_type, msg.getType() },
                { Constants.message, msg.toJson() },
                { Constants.timestamp, GetTimestamp() },
                { Constants.environment, env }
            };
            var ret = callRestful(RESTAPI_CREATEMULTIPUSH, param);

            return(ret);
        }
        /// <summary>
        /// 推送标签,限iOS系统使用。
        /// </summary>
        /// <param name="tagList"></param>
        /// <param name="tagOp"></param>
        /// <param name="msg"></param>
        /// <param name="env"></param>
        /// <returns></returns>
        public string PushTags(IEnumerable <string> tagList, Operator tagOp, MessageIOS msg,
                               iOSEnvironment env)
        {
            if (!isValidMessageType(msg, env))
            {
                return("{'ret_code':-1,'err_msg':'message type or environment error!'}");
            }
            if (!msg.isValid())
            {
                return("{'ret_code':-1,'err_msg':'message invalid!'}");
            }
            var param = new Dictionary <string, object>
            {
                { Constants.access_id, m_access_id },
                { Constants.expire_time, msg.getExpireTime() },
                { Constants.send_time, msg.getSendTime() },
                { Constants.message_type, msg.getType() },
                { Constants.tags_list, toJArray(tagList) },
                { Constants.tags_op, tagOp },
                { Constants.message, msg.toJson() },
                { Constants.timestamp, (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000 },
                { Constants.environment, env }
            };

            if (msg.getLoopInterval() > 0 && msg.getLoopTimes() > 0)
            {
                param.Add(Constants.loop_interval, msg.getLoopInterval());
                param.Add(Constants.loop_times, msg.getLoopTimes());
            }
            var ret = callRestful(RESTAPI_PUSHTAGS, param);

            return(ret);
        }
        /// <summary>
        /// 推送账号列表,限iOS系统使用。
        /// </summary>
        /// <param name="accountList"></param>
        /// <param name="msg"></param>
        /// <param name="env"></param>
        /// <returns></returns>
        public string PushAccountList(IEnumerable <string> accountList, MessageIOS msg, iOSEnvironment env)
        {
            if (!isValidMessageType(msg, env))
            {
                return("{'ret_code':-1,'err_msg':'message type or environment error!'}");
            }
            if (!msg.isValid())
            {
                return("{'ret_code':-1,'err_msg':'message invalid!'}");
            }
            var param = new Dictionary <string, object>
            {
                { Constants.access_id, m_access_id },
                { Constants.expire_time, msg.getExpireTime() },
                { Constants.send_time, msg.getSendTime() },
                { Constants.account_list, toJArray(accountList) },
                { Constants.message_type, msg.getType() },
                { Constants.message, msg.toJson() },
                { Constants.timestamp, GetTimestamp() },
                { Constants.environment, env }
            };
            var ret = callRestful(RESTAPI_PUSHACCOUNTLIST, param);

            return(ret);
        }
        /// <summary>
        /// 推送给指定的账号,限iOS系统使用。
        /// </summary>
        /// <param name="accessId"></param>
        /// <param name="secretKey"></param>
        /// <param name="content"></param>
        /// <param name="account"></param>
        /// <param name="env"></param>
        /// <returns></returns>
        public static string pushAccountIos(long accessId, string secretKey,
                                            string content, string account, iOSEnvironment env)
        {
            var message = new MessageIOS();

            message.setAlert(content);
            message.setBadge(1);
            message.setSound(Constants.beep_wav);

            var xinge = new XingeApp(accessId, secretKey);
            var ret   = xinge.PushSingleAccount(account, message, env);

            return(ret);
        }
        /// <summary>
        /// 推送给绑定标签的设备,限iOS系统使用。
        /// </summary>
        /// <param name="accessId"></param>
        /// <param name="secretKey"></param>
        /// <param name="content"></param>
        /// <param name="tag"></param>
        /// <param name="env"></param>
        /// <returns></returns>
        public static string pushTagIos(long accessId, string secretKey,
                                        string content, string tag, iOSEnvironment env)
        {
            var message = new MessageIOS();

            message.setAlert(content);
            message.setBadge(1);
            message.setSound(Constants.beep_wav);

            var xinge   = new XingeApp(accessId, secretKey);
            var tagList = new List <string> {
                tag
            };
            string ret = xinge.PushTags(tagList, OR, message, env);

            return(ret);
        }
Example #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="env"></param>
 /// <returns></returns>
 protected bool isValidMessageType([NotNull] MessageIOS msg, int env)
 => m_access_id >= IOS_MIN_ID && (env == IOSENV_PROD || env == IOSENV_DEV);