示例#1
0
        /// <summary>
        /// IOS单个设备 推送信息
        /// </summary>
        /// <param name="deviceToken">针对某一设备推送,token是设备的唯一识别 ID</param>
        /// <param name="message"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        public string pushSingleDevice(String deviceToken, MessageIOS message, int environment)
        {
            if (!ValidateMessageType(message, environment))
            {
                return("");
            }
            if (!message.isValid())
            {
                return("");
            }
            Dictionary <String, Object> dic = new Dictionary <String, Object>();

            dic.Add("access_id", this.m_accessId);
            dic.Add("expire_time", message.expireTime);
            dic.Add("send_time", message.sendTime);
            dic.Add("device_token", deviceToken);
            dic.Add("message_type", message.type);
            dic.Add("message", message.ToJosnByType());
            dic.Add("timestamp", DateTime.Now.DateTimeToUTCTicks());
            dic.Add("environment", environment);

            if (message.loopInterval > 0 && message.loopTimes > 0)
            {
                dic.Add("loop_interval", message.loopInterval);
                dic.Add("loop_times", message.loopTimes);
            }

            return(CallRestful(XinGeAPIUrl.RESTAPI_PUSHSINGLEDEVICE, dic));
        }
示例#2
0
 protected bool ValidateMessageType(MessageIOS message, int environment)
 {
     if (this.m_accessId >= XinGeAPIUrl.IOS_MIN_ID && (environment == XinGeAPIUrl.IOSENV_PROD || environment == XinGeAPIUrl.IOSENV_DEV))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#3
0
        public bool pushSingleDevice(String deviceToken, string account, string title, string content, int type, int environment, Dictionary <string, object> custom, out string returnStr)
        {
            content = content.Replace("\r", "").Replace("\n", "");
            switch (type)
            {
            case (int)DeviceType.Android:
                Message android = new Message();
                //android.type = Message.TYPE_MESSAGE;
                android.title   = title;
                android.content = content;
                //if (message.custom_content == null)
                //{
                //    message.custom_content = new Dictionary<string, object>();
                //}
                android.custom_content = custom.ToJson();
                returnStr = pushSingleDevice(deviceToken, android);
                break;

            case (int)DeviceType.IOS:
                MessageIOS ios = new MessageIOS();
                //ios.type = Message.TYPE_NOTIFICATION;
                ios.alertStr = content.Length > 20 ? content.Substring(0, 20) : content;
                ios.custom   = custom;

                if (!string.IsNullOrEmpty(account))
                {
                    returnStr = pushSingleAccount(account, ios, environment);
                }
                else
                {
                    returnStr = pushSingleDevice(deviceToken, ios, environment);
                }
                break;

            default:

                returnStr = string.Format("找不到指定类型的推送方法,设备类型:{0}", type);
                break;
            }
            return(true);
        }