Пример #1
0
        public string PushMsg(string strJson)
        {
            string result  = string.Empty;
            string message = string.Empty;

            try
            {
                Dictionary <string, string> dic = json.Deserialize <Dictionary <string, string> >(strJson);
                BaiduPush Bpush       = new BaiduPush("POST");
                String    messages    = "";
                String    method      = "push_msg";
                TimeSpan  ts          = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
                uint      device_type = uint.Parse(dic["deviceType"]);
                uint      unixTime    = (uint)ts.TotalSeconds;
                string    messageksy  = "pushkeys";
                string    apiKey      = SysFunction.GetConfigValue("ApiKey");

                if (device_type == 4)
                {
                    IOSNotification notification = new IOSNotification();
                    notification.title       = dic["title"];
                    notification.description = dic["des"];
                    messages = notification.getJsonString();
                }
                else if (device_type == 3)
                {
                    AndroidNotification notification = new AndroidNotification();
                    notification.title       = dic["title"];
                    notification.description = dic["des"];
                    messages = notification.getJsonString();
                }

                PushOptions pOpts;
                if (dic["pushType"].Equals("1"))
                {
                    pOpts = new PushOptions(method, apiKey, dic["userID"], dic["channelID"], device_type, messages, messageksy, unixTime);
                }
                else if (dic["pushType"].Equals("2"))
                {
                    pOpts = new PushOptions(method, apiKey, dic["tag"], device_type, messages, messageksy, unixTime);
                }
                else
                {
                    pOpts = new PushOptions(method, apiKey, device_type, messages, messageksy, unixTime);
                }

                pOpts.message_type = uint.Parse(dic["msgType"]);

                message = Bpush.PushMessage(pOpts);
                result  = "0";
            }
            catch (Exception ex)
            {
                HandleException(ex, ref result, ref message);
            }
            return(GetResultStr(result, message));
        }
Пример #2
0
        /// <summary>
        /// 标签操作
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <param name="tag">标签名</param>
        /// <param name="method">方法名</param>
        /// <param name="result"></param>
        /// <param name="message"></param>
        private void TagOperation(string userId, string tag, string method, ref string result, ref string message)
        {
            BaiduPush Bpush    = new BaiduPush("POST");
            TimeSpan  ts       = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
            uint      unixTime = (uint)ts.TotalSeconds;
            string    apiKey   = SysFunction.GetConfigValue("ApiKey");

            TagOptions tOpts = new TagOptions(method, apiKey, userId, tag, unixTime);

            message = Bpush.SetTag(tOpts);
            result  = "0";
        }