Exemple #1
0
        public ActionResult Index()
        {
            var result = string.Empty;
            //try
            //{
            //    Console.OutputEncoding = Encoding.GetEncoding(936);
            //    Environment.SetEnvironmentVariable("gexin_pushList_needDetails", "true");
            //    result = PushHelper.PushMessageToApp();
            //}
            //catch (Exception ex)
            //{
            //    result = ex.Message;
            //}

            string     clientId = "557e5625f84c82517457c43024b03b0c";
            PushHelper message  = new PushHelper(new List <string>()
            {
                clientId
            });

            var beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var endTime   = DateTime.Now.AddHours(2).ToString("yyyy-MM-dd HH:mm:ss");
            //string msg1 = message.PushMessageToSingleByNotificationTemplate("XXX - 单用户", "您有新的任务,点击查看!", "", "", "", beginTime, endTime);
            //string msg2 = message.PushMessageToListByNotificationTemplate("XXX  - 多用户", "您有新的任务,点击查看!", "", "", "", beginTime, endTime);
            string msg3 = message.PushTemplate(Enum_Push.All, "XXX  - APP应用", "您有新的任务,点击查看啊!", "", "", "{id:1}", beginTime, endTime);

            //解析输出结果
            //{"taskId":"OSS-0420_ZiFBb3Sx7A7Pz7YWMwJdD9","result":"ok","status":"successed_online"} 在线状态
            //{"taskId":"OSS-0420_2qtgpolflJAuYGSiGTfQ04","result":"ok","status":"successed_offline"} 离线状态

            return(Content(msg3));

            //return Content(msg1 + "</br>" + msg2 + "</br>" + msg3 + "</br>");
        }
Exemple #2
0
        public string ALL()
        {
            ApiResult result = new ApiResult();

            try
            {
                var title = ZNRequest.GetString("Title");
                var text  = ZNRequest.GetString("Text");

                string     clientId = "557e5625f84c82517457c43024b03b0c";
                PushHelper message  = new PushHelper(new List <string>()
                {
                    clientId
                });

                var beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                var endTime   = DateTime.Now.AddHours(2).ToString("yyyy-MM-dd HH:mm:ss");
                //string msg1 = message.PushMessageToSingleByNotificationTemplate("XXX - 单用户", "您有新的任务,点击查看!", "", "", "", beginTime, endTime);
                //string msg2 = message.PushMessageToListByNotificationTemplate("XXX  - 多用户", "您有新的任务,点击查看!", "", "", "", beginTime, endTime);
                string msg3 = message.PushTemplate(Enum_Push.All, "XXX  - APP应用", "您有新的任务,点击查看啊!", "", "", "{id:1}", beginTime, endTime);
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_UserLog_Edit" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemple #3
0
        public string System()
        {
            ApiResult result = new ApiResult();

            try
            {
                string clientId = "557e5625f84c82517457c43024b03b0c";
                //string clientId = "54f3c1dc7795e813a8e0cdb039becb6f";
                PushHelper message = new PushHelper(new List <string>()
                {
                    clientId
                });


                var article = db.Find <Article>(x => x.Status == Enum_Status.Approved && x.ArticlePower == Enum_ArticlePower.Public);
                var num     = new Random().Next(0, article.Count);

                var    beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                var    endTime   = DateTime.Now.AddHours(5).ToString("yyyy-MM-dd HH:mm:ss");
                string msg1      = message.PushTemplate(Enum_Push.Single, "微篇文章推荐啦", article[num].Title, "", "", "0|" + article[num].ID, beginTime, endTime);
                //string msg2 = message.PushTemplate(Enum_Push.Multiple, "用户", "您有新的任务,点击查看!", "", "", "", beginTime, endTime);
                //string msg3 = message.PushTemplate(Enum_Push.All, "XXX  - APP应用", "您有新的任务,点击查看啊!", "", "", "{id:1}", beginTime, endTime);
                result.message = msg1;
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_UserLog_Edit" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemple #4
0
        public string Single()
        {
            ApiResult result = new ApiResult();

            try
            {
                //通知用户
                var number = ZNRequest.GetString("UserNumber");
                if (string.IsNullOrWhiteSpace(number))
                {
                    return("参数异常");
                }
                var user = db.Single <User>(x => x.Number == number);
                if (user == null)
                {
                    return("用户不存在");
                }
                if (user.ShowPush == 0)
                {
                    return("未启用消息推送");
                }
                if (string.IsNullOrWhiteSpace(user.ClientID))
                {
                    return("设备号不存在");
                }
                PushHelper message = new PushHelper(new List <string>()
                {
                    user.ClientID
                });

                var article = db.Find <Article>(x => x.Status == Enum_Status.Approved && x.ArticlePower == Enum_ArticlePower.Public);
                var num     = new Random().Next(0, article.Count);

                var beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                var endTime   = DateTime.Now.AddHours(5).ToString("yyyy-MM-dd HH:mm:ss");
                result.message = message.PushTemplate(Enum_Push.Single, "微篇文章推荐啦", article[num].Title, "", "", "0|" + article[num].ID, beginTime, endTime);
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_UserLog_Edit" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemple #5
0
        /// <summary>
        /// 推送
        /// </summary>
        /// <param name="usernumber">推送目标用户编号</param>
        /// <param name="id">对象ID(文章ID)</param>
        /// <param name="number">对象Number</param>
        /// <param name="name">用户名称/文章标题</param>
        /// <param name="pushtype">推送类型</param>
        /// <param name="ispush">是否推送</param>
        public void Push(string usernumber, int id, string number, string name, int pushtype, bool ispush = true)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(usernumber))
                {
                    return;
                }
                var user = db.Single <User>(x => x.Number == usernumber);
                if (user == null)
                {
                    return;
                }

                var result = "";
                if (ispush)
                {
                    if (user.ShowPush == 0)
                    {
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(user.ClientID))
                    {
                        return;
                    }
                    PushHelper message = new PushHelper(new List <string>()
                    {
                        user.ClientID
                    });

                    var beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    var endTime   = DateTime.Now.AddHours(12).ToString("yyyy-MM-dd HH:mm:ss");

                    var url = System.Web.Configuration.WebConfigurationManager.AppSettings["base_url"];

                    switch (pushtype)
                    {
                    case Enum_PushType.Article:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇文章推荐啦", name, "", url + "Images/push.png", Enum_PushType.Article + "|" + id, beginTime, endTime);
                        break;

                    case Enum_PushType.Comment:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有好友评论啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.Comment + "|" + id + "|" + number, beginTime, endTime);
                        break;

                    case Enum_PushType.Money:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有好友打赏啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.Money.ToString(), beginTime, endTime);
                        break;

                    case Enum_PushType.Red:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "小微篇送您一个红包,快去看看吧", "", url + "Images/push.png", Enum_PushType.Red.ToString(), beginTime, endTime);
                        break;

                    case Enum_PushType.Fan:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有新的粉丝啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.Fan.ToString(), beginTime, endTime);
                        break;

                    case Enum_PushType.FanArticle:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有好友发文啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.FanArticle + "|" + id, beginTime, endTime);
                        break;

                    case Enum_PushType.Update:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇更新啦", "更新内容", "", url + "Images/push.png", "10", beginTime, endTime);
                        break;

                    default:
                        break;
                    }
                }
                //推送记录
                PushLog log = new PushLog();
                log.Number       = usernumber;
                log.ObjectID     = id;
                log.ObjectName   = name;
                log.ObjectNumber = number;
                log.PushResult   = result;
                log.PushType     = pushtype;
                log.CreateTime   = DateTime.Now;
                logdb.Add <PushLog>(log);
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("推送失败:" + ex.Message);
            }
        }