コード例 #1
0
        /// <summary>
        /// returns the content and status of a samplemessage
        /// </summary>
        /// <param name="messageName">name of the message</param>
        /// <returns>[message(content of the message), messageIsValid(0: not valid, 1: valid), returnValue(0:samplemessage readed, 1:samplemessage does not exists, 2:internal error, 3:samplemessage is empty)]</returns>
        public static MessageReturn GetMessage(string messageName)
        {
            MessageReturn messageReturn = new MessageReturn();    //init return values

            messageReturn.message        = "";
            messageReturn.messageIsValid = false;
            messageReturn.returnvalue    = 0;
            try
            {
                if (!buffer.ContainsKey(messageName))    //check if message already exists
                {
                    messageReturn.returnvalue = 1;
                    return(messageReturn);
                }
                if (buffer[messageName].expireTime == null || buffer[messageName].expireTime > DateTime.Now)
                {
                    messageReturn.messageIsValid = true;                                                                                          //if no expire time or expiretime is higher than actual time --> valid message
                }
                if (buffer[messageName].message == "")
                {
                    messageReturn.returnvalue = 3;                      //check if message is empty
                }
                messageReturn.message = buffer[messageName].message;    //get message content
            }
            catch
            {
                messageReturn.returnvalue = 2;
                return(messageReturn);
            }
            return(messageReturn);
        }
コード例 #2
0
        public ObjectResult Excluir(int Codigo)
        {
            var retorno = new MessageReturn();
            var CategoriasVinculadas = _complementoCategoriaService.GetCategorias(Codigo);

            if (CategoriasVinculadas.Count > 0)
            {
                retorno = new MessageReturn {
                    Title = "0", Message = "Esta categoria esta vincula a um complemento, remova o vinculo no cadastro de complemento e tente novamente.", CssClassName = "warning"
                };
                return(new ObjectResult(retorno));
            }
            var result = _categoriaService.Excluir(Codigo);

            if (result == 1)
            {
                retorno = new MessageReturn {
                    Title = "1", Message = "Item excluido com sucesso.", CssClassName = "success"
                };
            }
            else
            {
                retorno = new MessageReturn {
                    Title = "0", Message = "Erro ao excluir item.", CssClassName = "warning"
                };
            }

            return(new ObjectResult(retorno));
        }
コード例 #3
0
        public static MessageReturn SendMessageCode(string pheone)
        {
            LogHelper.WriteLog("SendMessageCode start");
            LogHelper.WriteLog("短信认证手机号:" + pheone);
            MessageReturn        messageReturn = new MessageReturn();
            JavaScriptSerializer jsonSerialize = new JavaScriptSerializer();
            IClientProfile       profile       = DefaultProfile.GetProfile("cn-hangzhou", ConfigurationManager.AppSettings["AccessKeyID"].ToString(), ConfigurationManager.AppSettings["AccessKeySecret"].ToString());
            DefaultAcsClient     client        = new DefaultAcsClient(profile);
            CommonRequest        request       = new CommonRequest();

            request.Method  = MethodType.POST;
            request.Domain  = "dysmsapi.aliyuncs.com";
            request.Version = "2017-05-25";
            request.Action  = "SendSms";
            // request.Protocol = ProtocolType.HTTP;
            request.AddQueryParameters("PhoneNumbers", pheone);
            request.AddQueryParameters("SignName", ConfigurationManager.AppSettings["SignName"].ToString());
            request.AddQueryParameters("TemplateCode", ConfigurationManager.AppSettings["TemplateCode"].ToString());
            MessageNo messageNo = new MessageNo();
            Random    rd        = new Random();
            int       num       = rd.Next(100000, 1000000);

            messageNo.code = num.ToString();
            request.AddQueryParameters("TemplateParam", jsonSerialize.Serialize(messageNo));
            LogHelper.WriteLog("短信认证参数:" + jsonSerialize.Serialize(request.QueryParameters));
            try
            {
                CommonResponse response = client.GetCommonResponse(request);
                LogHelper.WriteLog("SendMessageCode response" + response);
                var sendSmsResponse = jsonSerialize.Deserialize <SendSmsResponse>(response.Data);
                if (sendSmsResponse.Code.Equals("OK"))
                {
                    LogHelper.WriteLog("SendMessageCode num" + num.ToString());
                    messageReturn.Status  = true;
                    messageReturn.Message = num.ToString();
                }
            }
            catch (ServerException e)
            {
                messageReturn.Status  = false;
                messageReturn.Message = e.Message;
                LogHelper.WriteLog("短信认证错误:" + jsonSerialize.Serialize(messageReturn.Message), e);
            }
            catch (ClientException e)
            {
                messageReturn.Status  = false;
                messageReturn.Message = e.Message;
                LogHelper.WriteLog("短信认证错误:" + jsonSerialize.Serialize(messageReturn.Message), e);
            }
            LogHelper.WriteLog("SendMessageCode end");
            return(messageReturn);
        }
コード例 #4
0
        public ActionResult Edit(Empresa empresa)
        {
            if (ModelState.IsValid)
            {
                MessageReturn messageReturn = _businessEmpresa.Update(empresa);

                if (!messageReturn.IsValid)
                {
                    messageReturn.MessagesError.ForEach(error => ModelState.AddModelError("", error));

                    return(View(empresa));
                }

                return(RedirectToAction("Index"));
            }
            return(View(empresa));
        }
コード例 #5
0
        public ObjectResult Excluir(int Codigo)
        {
            var retorno = new MessageReturn();
            var result  = _observacaoService.Excluir(Codigo);

            if (result == 1)
            {
                retorno = new MessageReturn {
                    Title = "1", Message = "Item excluido com sucesso.", CssClassName = "success"
                };
            }
            else
            {
                retorno = new MessageReturn {
                    Title = "0", Message = "Erro ao excluir item.", CssClassName = "warning"
                };
            }

            return(new ObjectResult(retorno));
        }
コード例 #6
0
        public ActionResult Edit(Operador operador)
        {
            ViewBag.EmpresaId = new SelectList(_businessEmpresa.GetAll(), "Id", "Nome", operador.EmpresaId);
            ViewBag.PerfilId  = new SelectList(_businessPerfil.GetAll(), "Id", "Tipo", operador.PerfilId);
            if (ModelState.IsValid)
            {
                MessageReturn messageReturn = _businessOperador.Update(operador);

                if (!messageReturn.IsValid)
                {
                    messageReturn.MessagesError.ForEach(error => ModelState.AddModelError("", error));

                    return(View(operador));
                }

                return(RedirectToAction("Index"));
            }

            return(View(operador));
        }
コード例 #7
0
 protected virtual JsonResult JsonNotFoundMessage(string msg = "Not Found", dynamic objdata = null)
 {
     return(Json(MessageReturn.CreateErrorMessage(msg, objdata)));
 }
コード例 #8
0
 protected virtual JsonResult JsonSuccessMessage(string msg = "Ok", dynamic objdata = null)
 {
     return(Json(MessageReturn.CreateSuccessMessage(msg, objdata)));
 }
コード例 #9
0
        public virtual IActionResult _Create(TaskModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageContract))
            {
                return(JsonErrorMessage());
            }
            if (ModelState.IsValid)
            {
                var  note            = "";
                var  noti            = "admin.common.Added";
                Task item            = new Task();
                int  PreParentTaskId = model.ParentId;
                if (model.Id > 0)
                {
                    item            = _workTaskService.GetTaskById(model.Id);
                    PreParentTaskId = item.ParentId.GetValueOrDefault();
                    note            = MessageReturn.CreateSuccessMessage("oldData", item.ToModel <TaskModel>()).toStringJson();
                }
                _taskModelFactory.PrepareTask(item, model);
                if (model.Id > 0)
                {
                    _workTaskService.UpdateTask(item);
                    _taskModelFactory.InsertContractLog(item);
                    var TaskLogModel = new TaskLogModel
                    {
                        TaskId = item.Id,
                        Note   = "Cập nhật công việc "
                    };
                    _taskModelFactory.InsertTaskLog(TaskLogModel);
                    noti = "admin.common.Updated";
                    //kiem tra xem co thay doi cha ko, neu co thay doi cha thi phai update lai cha
                    //if(PreParentTaskId!=model.ParentId && PreParentTaskId>0)
                    //{
                    //    _workTaskService.UpdateTaskAmount(PreParentTaskId);
                    //}
                }
                else
                {
                    //neu them cong viec vao hop dong thi mac dinh cong viec o trang thai dang working
                    if (model.ContractId > 0)
                    {
                        var contract1 = _contractService.GetContractById(model.ContractId);
                        if (contract1.StatusId != (int)ContractStatus.Draf)
                        {
                            item.StatusId = (int)TaskStatus.Working;
                        }
                    }
                    _workTaskService.InsertTask(item);
                    //lay lai thong tin da insert
                    item = _workTaskService.GetTaskById(item.Id);
                    _taskModelFactory.InsertContractLog(item);
                    var TaskLogModel = new TaskLogModel
                    {
                        TaskId = item.Id,
                        Note   = "Thêm mới công việc "
                    };
                    _taskModelFactory.InsertTaskLog(TaskLogModel);
                }
                if (model.AppendixId > 0)
                {
                    var taskContract = new TaskContract
                    {
                        TaskId      = item.Id,
                        ContractId  = model.AppendixId,
                        CreatorId   = _workContext.CurrentCustomer.Id,
                        CreatedDate = DateTime.Now,
                        Note        = note,
                    };
                    _workTaskService.InsertTaskContract(taskContract);
                }
                var contract = _contractService.GetContractById(item.ContractId);
                //neu hop dong dang chay va co ContractTypeId thì chay lai gt do dang
                if (contract != null && contract.StatusId != (int)ContractStatus.Draf && item.ContractTypeId > 0 && item.StatusId != (int)TaskStatus.Draf)
                {
                    UpdateContractUnfinish(item.Id);
                }
                return(JsonSuccessMessage(_localizationService.GetResource(noti), item.ToModel <TaskModel>()));
            }
            var list = ModelState.Values.Where(c => c.Errors.Count > 0).ToList();

            return(JsonErrorMessage("Error", list));
        }
コード例 #10
0
 public BusinessOperador(IRepositoryOperador repositoryOperador)
 {
     _repositoryOperador = repositoryOperador;
     msgRetorno          = new MessageReturn();
 }
コード例 #11
0
ファイル: Service1.cs プロジェクト: itpanda2016/TQLSMacOld
        /// <summary>
        /// 执行的事件
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            txtLog.Info(string.Format("The Elapsed event was raised at {0:HH:mm:ss.fff}", e.SignalTime));
            Auths.Access_Token qyh    = new Auths.Access_Token();
            string             CorpID = ConfigurationManager.AppSettings["qyhCorpId"];
            string             Secret = ConfigurationManager.AppSettings["qyhSecret"];

            //判断当前时间是否为设置的发送时间范围bll.SiteConfig.GetSendTime();
            txtLog.Info("如果没设置,则默认为早上9点");
            int sendHour = bll.SiteConfig.GetSendTime();

            if (sendHour <= 0)
            {
                sendHour = 9;
            }
            if (sendHour != DateTime.Now.Hour)
            {
                txtLog.Info(sendHour + "不在消息发送的时间范围内:" + DateTime.Now.Hour);
                return;
            }
            txtLog.Info("判断当天(国历)是否已发送了");
            if (bll.Log.CheckHasSend(DateTime.Now))
            {
                txtLog.Info("今天已发过了,不再发送。");
                return;
            }
            Auths.Error err = new Auths.Error();
            qyh = bllQYH.Require.GetAccessToken(CorpID, Secret, ref err);
            if (err.errcode != 0)
            {
                txtLog.Info("获取Access_token出错。");
                return;
            }
            txtLog.Info("获取Token:" + qyh.access_token);
            //获取,并判断生日
            string strUserList = bllQYH.User.GetUserList(qyh.access_token, 33);
            string lunarDate   = Utility.LunarDate(DateTime.Now).ToString("yyyy-MM-dd");

            txtLog.Info("当天对应的农历日期:" + lunarDate);
            QYHUserListMore userlist = JsonConvert.DeserializeObject <QYHUserListMore>(strUserList);

            if (userlist.errcode > 0)
            {
                txtLog.Info(DateTime.Now.ToString());
                txtLog.Info("获取用户列表出错");
                txtLog.Info(userlist.errcode.ToString());
                txtLog.Info(userlist.errmsg);
                return;
            }
            txtLog.Info("用户数量:" + userlist.userlist.Count);
            List <string> listUserBirthdayLunar = new List <string>();   //当天农历生日的用户

            foreach (var item in userlist.userlist)
            {
                //txtLog.Info("开始判断扩展字段是否为空。");
                if (item.extattr != null)
                {
                    //txtLog.Info("不为空的用户才会继续判断生日字段:");
                    foreach (var item2 in item.extattr.attrs)
                    {
                        //txtLog.Info("准备开始判断不为空的生日用户。");
                        if (item2.Name == "生日" && item2.Value != "")
                        {
                            //txtLog.Info("如果生日字段存在并且不为空。");
                            //txtLog.Info("有生日用户:" + item.Name + ",生日:" + item2.Value);
                            //DateTime userBirthday = Convert.ToDateTime(item2.Value);
                            //txtLog.Info("对应日期格式值:" + userBirthday.ToString());
                            //if (userBirthday != null && lunarDate.Month == userBirthday.Month && lunarDate.Day == userBirthday.Day) {
                            if (lunarDate.Remove(0, 5) == item2.Value.Remove(0, 5))
                            {
                                //txtLog.Info(lunarDate.Remove(0, 5) + "|" + item2.Value.Remove(0, 5));
                                //if(item2.Value.Remove(0,5))
                                txtLog.Info("当天生日用户:" + item.UserId);
                                listUserBirthdayLunar.Add(item.UserId);
                                continue;
                            }
                        }
                    }
                }
            }
            txtLog.Info("当天过生日用户数量:" + listUserBirthdayLunar.Count);
            if (listUserBirthdayLunar.Count == 0)
            {
                txtLog.Info("今天没有过生日的用户:" + Utility.LunarDate(DateTime.Now));
                bll.Log.Add("今天是农历:" + Utility.LunarDate(DateTime.Now) + ",今天没有过生日的用户,所以不会发送消息。");
                return;
            }
            string logUser = "";    //仅用来记录真实的生日用户,存入数据库

            try {
                //获取后台规则列表
                txtLog.Info("获取后台规则列表。");
                DataTable dt = bll.Rule.GetRuleList();
                //准备发送消息的字典
                txtLog.Info("准备发送消息的字典");
                Dictionary <int, MessageVideo> tmpSendList = new Dictionary <int, MessageVideo>();
                //图文消息对象
                //Dictionary<int, MPNewsSendByMediaID> tmpSendList = new Dictionary<int, MPNewsSendByMediaID>();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        txtLog.Info("第" + i + "次循环数据库记录开始。");
                        //图文消息对象
                        //MPNewsSendByMediaID msgMPNews = new MPNewsSendByMediaID();
                        //msgMPNews.safe = 1;
                        //视频消息对象
                        MessageVideo      tmpVideoMessage = new MessageVideo();
                        MessageVideoChild tmpVideoChild   = new MessageVideoChild();
                        tmpVideoChild.media_id    = dt.Rows[i]["msgvalue"].ToString();
                        tmpVideoChild.title       = dt.Rows[i]["videotitle"].ToString();
                        tmpVideoChild.description = dt.Rows[i]["videodescription"].ToString();
                        tmpVideoMessage.video     = tmpVideoChild;
                        tmpVideoMessage.safe      = 1;
                        txtLog.Info("看看消息的类型是什么:" + tmpVideoMessage.msgtype);
                        txtLog.Info("判断是否有标签过滤。");
                        //如果规则中有标签过滤
                        if (Convert.ToInt32(dt.Rows[i]["rulevalue"]) > 0)
                        {
                            txtLog.Info("有");
                            //获取该标签的用户列表
                            string      tagUserlist   = bllQYH.User.GetUserListByTag(qyh.access_token, Convert.ToInt32(dt.Rows[i]["rulevalue"]));
                            TagUserList userlistModel = JsonConvert.DeserializeObject <TagUserList>(tagUserlist);
                            if (userlistModel.errcode > 0)
                            {
                                txtLog.Info(DateTime.Now.ToString());
                                txtLog.Info("获取指定标签的用户列表出错。");
                                return;
                            }
                            txtLog.Info(userlistModel.userlist.Length + "标签用户");
                            foreach (var item in userlistModel.userlist)
                            {
                                for (int j = 0; j < listUserBirthdayLunar.Count; j++)
                                {
                                    if (listUserBirthdayLunar[j] == "del")
                                    {
                                        continue;
                                    }
                                    if (listUserBirthdayLunar[j] == item.userid)
                                    {
                                        //在视频消息中添加用户
                                        tmpVideoMessage.touser += listUserBirthdayLunar[j] + "|";
                                        //在图文消息中添加用户
                                        //msgMPNews.touser += listUserBirthdayLunar[j] + "|";
                                        //listUserBirthdayLunar.RemoveAt(j);
                                        listUserBirthdayLunar[j] = "del";
                                        continue;
                                    }
                                }
                            }
                            //图文消息子对象ID处理,视频消息在第1层就配置了
                            //MPNewsMediaID mpnewsMediaID = new MPNewsMediaID();
                            //mpnewsMediaID.media_id = dt.Rows[i]["msgvalue"].ToString();
                            //msgMPNews.mpnews = mpnewsMediaID;
                            txtLog.Info("标签用户处理结束。");
                        }
                        //如果规则中无标签过滤
                        else
                        {
                            txtLog.Info("无");
                            //foreach是只读的
                            //foreach (var item2 in listUserBirthdayLunar) {
                            //    tmpVideoMessage.touser += item2 + "|";
                            //    listUserBirthdayLunar.Remove(item2);
                            //}

                            for (int k = 0; k < listUserBirthdayLunar.Count; k++)
                            {
                                if (listUserBirthdayLunar[k] == "del")
                                {
                                    continue;
                                }
                                txtLog.Info("【无标签】共有生日用户:" + listUserBirthdayLunar.Count + ",当前获取用户:" + listUserBirthdayLunar[k]);
                                //视频消息,用户处理
                                tmpVideoMessage.touser += listUserBirthdayLunar[k] + "|";
                                //图文消息,用户处理
                                //msgMPNews.touser += listUserBirthdayLunar[k] + "|";
                                listUserBirthdayLunar[k] = "del";
                            }
                            //图文消息子对象ID处理,视频消息在第1层就配置了
                            //MPNewsMediaID mpnewsMediaID = new MPNewsMediaID();
                            //mpnewsMediaID.media_id = dt.Rows[i]["msgvalue"].ToString();
                            //msgMPNews.mpnews = mpnewsMediaID;
                            txtLog.Info("无标签规则处理结束。,用户为:" + tmpVideoMessage.touser);
                        }
                        //如此当前规则没有区配到用户列表,则跳过不添加发送
                        if (tmpVideoMessage.touser == null | tmpVideoMessage.touser == "")
                        {
                            //if (msgMPNews.touser == null | msgMPNews.touser == "")
                            continue;
                        }
                        //txtLog.Info("第" + i + "次用户列表:");
                        //txtLog.Info(tmpVideoMessage.touser);
                        //txtLog.Info(msgMPNews.touser);
                        tmpVideoMessage.touser = tmpVideoMessage.touser.Remove(tmpVideoMessage.touser.Length - 1);
                        //msgMPNews.touser = msgMPNews.touser.Remove(msgMPNews.touser.Length - 1);
                        txtLog.Info("处理后:");
                        txtLog.Info(tmpVideoMessage.touser);
                        logUser = tmpVideoMessage.touser;
                        //测试时使用:熊林/李福
                        tmpVideoMessage.touser += "|15228363212";
                        txtLog.Info("测试后的发送用户:" + tmpVideoMessage.touser);
                        //txtLog.Info(msgMPNews.touser);
                        //将每次循环后的发送规则添加到字典中
                        tmpSendList.Add(i, tmpVideoMessage);
                        //tmpSendList.Add(i, msgMPNews);
                        //txtLog.Info("第" + i + "次循环数据库结束。");
                    }
                }
                else
                {
                    txtLog.Info("请登录后台配置规则。");
                }
                txtLog.Info("准备发送消息记录。");
                //准备发送消息的循环
                foreach (var item in tmpSendList)
                {
                    txtLog.Info("准备发送的消息:" + JsonConvert.SerializeObject(item.Value));
                    //txtLog.Info("Token:" + qyh.access_token);
                    string        ret    = bllQYH.Message.SendMessage(qyh.access_token, JsonConvert.SerializeObject(item.Value));
                    MessageReturn msgRet = JsonConvert.DeserializeObject <MessageReturn>(ret);
                    if (msgRet.errcode > 0)
                    {
                        txtLog.Info("消息发送失败:");
                        txtLog.Info(ret);
                        bll.Log.Add("消失发送失败,生日用户:" + logUser + ",出错信息:" + ret);
                    }
                    else
                    {
                        txtLog.Info(ret);
                        txtLog.Info("消息已发送至:" + item.Value.touser);
                        bll.Log.Add("成功发送生日祝福,生日用户:" + logUser);
                    }
                }
                //bll.Log.Add();
            }
            catch (Exception er) {
                txtLog.Info("出错:" + DateTime.Now.ToString());
                txtLog.Info(er.Message);
                bll.Log.Add("Throw错误,发生时间:" + DateTime.Now.ToString() + ",错误描述信息:" + er.Message);
            }
        }
コード例 #12
0
 public BusinessEmpresa(IRepositoryEmpresa repositoryEmpresa)
 {
     _repositoryEmpresa = repositoryEmpresa;
     messageRetorno     = new MessageReturn();
 }