public ActionResult AddOrUpdate() { try { string id = Request.Form["txtId"].ToStringEx(); var txtKeyWord = Request.Form["txtKeyWord"].ToStringEx(); var selectReplyType = Request.Form["selectReplyType"].ToInt32(); var selectMessageType = Request.Form["selectMessageType"].ToInt32(); var txtContent = Request.Form["txtContent"].ToStringEx(); var selectState = Request.Form["selectState"].ToInt32(); var state = Request.Form["selectState"].ToInt32(); if (id.IsNotNullOrWhiteSpace()) { //修改 Model.AutoReply model = new BLL.AutoReplys().GetModelById(id); model.ID = id; model.Keyword = txtKeyWord; model.ReplyType = selectReplyType; model.MessageType = selectMessageType; model.ReplyIdList = txtContent; model.state = state; if (new BLL.AutoReplys().Update(model)) { return(Content("1")); } else { return(Content("2")); } } else { //新增 Model.AutoReply model = new Model.AutoReply(); model.ID = Guid.NewGuid().ToStringEx(); model.Keyword = txtKeyWord; model.ReplyType = selectReplyType; model.MessageType = selectMessageType; model.ReplyIdList = txtContent; model.state = state; if (new BLL.AutoReplys().Add(model)) { return(Content("3")); } else { return(Content("4")); } } } catch (Exception err) { return(Content(err.Message)); } return(Content("0")); }
/// <summary> /// 处理文字请求 /// </summary> /// <returns></returns> public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage) { LogHelper.WriteLog(LogEnum.WeChatSend, "requestMessage.Content:" + requestMessage.Content); if (requestMessage.Content.Contains("客服")) { var _responseMessage = this.CreateResponseMessage <ResponseMessageTransfer_Customer_Service>(); return(_responseMessage); } var responseMessageContent = BaseConfig.DefaultInfo; var model = new BLL.AutoReplys().GetAutoReplyList(requestMessage.Content).Tables[0].ToEntity <Model.AutoReply>(); if (model != null) { if (model.ReplyType == AutoReplyTypeEnum.Text.GetHashCode()) { responseMessageContent = model.ReplyIdList; } } try { var access_token = CommonApi.GetToken(BaseConfig.AppId, BaseConfig.AppSecret); if (access_token.errcode == Senparc.Weixin.ReturnCode.请求成功) { string urlFormat = string.Format("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}", access_token.access_token); var info = new { touser = "******", msgtype = "text", text = new { content = "公众号新消息:" + requestMessage.Content } }; Utils.HttpPostRequest(urlFormat, info.ToJson()); } } catch (Exception err) { LogHelper.WriteLog(LogEnum.Error, " 客服接口异常:" + err.Message); } var responseMessage = this.CreateResponseMessage <ResponseMessageText>(); responseMessage.Content = responseMessageContent; return(responseMessage); }
/// <summary> /// 回复列表 /// </summary> /// <param name="type">回复列表</param> /// <returns></returns> public ActionResult List(int?id) { var list = new BLL.AutoReplys().GetList(string.Empty).Tables[0].ToEntityList <Model.AutoReply>(); if (id.HasValue) { if (id == 1) { //关注 list = list.Where(exp => exp.MessageType == 0).ToList(); } else { //关键词 list = list.Where(exp => exp.MessageType == 1).ToList(); } } return(View(list)); }