/// <summary> /// 默认处理信息(返回文本) /// </summary> /// <param name="request"></param> /// <returns></returns> public virtual ResponseRootMsg OnDefault(IRequestRootMsg request) { ResponseTextMsg responseText = new ResponseTextMsg() { Content = "默认回复" + DateTime.Now, CreateTime = DateTime.Now.ToTimeStamp(), FromUserName = request.ToUserName, ToUserName = request.FromUserName }; return(responseText); }
/// <summary> /// 文本响应 /// </summary> /// <param name="ruleid"></param> /// <param name="request"></param> /// <returns></returns> private ResponseTextMsg GetResponseTextMsgByRuleId(int ruleid, IRequestRootMsg request) { WxTextResponse dbtext = databaseFixture.Db.WxTextResponse.Find(m => m.RuleId == ruleid); ResponseTextMsg responseTextMsg = new ResponseTextMsg { Content = dbtext.Content, CreateTime = DateTime.Now.ToTimeStamp(), FromUserName = request.ToUserName, ToUserName = request.FromUserName }; return(responseTextMsg); }
void IWeChatSendMessage.textMsg(string touser, string content) { if (_info == null) { throw new WeChatError("请先调用init初始化"); } ResponseTextMsg testMsg = new ResponseTextMsg() { FromUserName = _info.rawid, ToUserName = touser, MsgType = "text", CreateTime = (uint)StringHelper.convertDateTimeInt(DateTime.Now), Content = content }; var str = XmlHelper.serialize(testMsg); _context.Response.WriteAsync(str); }
public string Index() { StreamReader reader = new StreamReader(Request.InputStream); string xmlData = reader.ReadToEnd(); BaseMsg baseModel = XmlHelper.ConvertToModel <BaseMsg>(xmlData); BaseResponseMsg response = new BaseResponseMsg { CreateTime = CommonHelp.TimeToLong(DateTime.Now), ToUserName = baseModel.FromUserName, FromUserName = baseModel.ToUserName };//响应对象 string result = ""; try { if (baseModel.MsgType == "event") { EventMsg model = XmlHelper.ConvertToModel <EventMsg>(xmlData); //EventMsgBll.HandlerTheEvent(model); EventMsgBll.Add(model); EventMsgBll.SaveChanges(); return(""); } var res = (MsgType)Enum.Parse(typeof(MsgType), baseModel.MsgType); switch (res) { case MsgType.text: { TextMsg model = XmlHelper.ConvertToModel <TextMsg>(xmlData); TextMsgBll.Add(model); //TODO 处理用户的文字信息 response = new ResponseTextMsg { CreateTime = CommonHelp.TimeToLong(DateTime.Now), ToUserName = baseModel.FromUserName, FromUserName = baseModel.ToUserName, Content = "欢迎关注我的微信!我是wdq!" }; } break; case MsgType.image: { ImageMsg model = XmlHelper.ConvertToModel <ImageMsg>(xmlData); ImageMsgBll.Add(model); //TODO 处理用户的图片信息 response = new ResponseImageMsg { CreateTime = CommonHelp.TimeToLong(DateTime.Now), FromUserName = baseModel.ToUserName, ToUserName = baseModel.FromUserName, MediaId = "1212" }; } break; case MsgType.voice: { VoiceMsg model = XmlHelper.ConvertToModel <VoiceMsg>(xmlData); VoiceMsgBll.Add(model); if (model.Recognition != null) { //TODO 处理用户的语音信息 } response = new ResponseVoiceMsg { FromUserName = baseModel.ToUserName, ToUserName = baseModel.FromUserName, CreateTime = CommonHelp.TimeToLong(DateTime.Now), MediaId = "123" }; } break; case MsgType.video: case MsgType.shortvideo: { VideoMsg model = XmlHelper.ConvertToModel <VideoMsg>(xmlData); VideoMsgBll.Add(model); //TODO 处理用户的小视频信息 } response = new ResponseVideoMsg { FromUserName = baseModel.ToUserName, ToUserName = baseModel.FromUserName, CreateTime = CommonHelp.TimeToLong(DateTime.Now), MediaId = "123", Description = "test", Title = "回复视频消息" }; break; case MsgType.location: { LocationMsg model = XmlHelper.ConvertToModel <LocationMsg>(xmlData); LocationMsgBll.Add(model); //TODO 处理用户的地理位置信息 } response = new ResponseMusicMsg { FromUserName = baseModel.ToUserName, ToUserName = baseModel.FromUserName, CreateTime = CommonHelp.TimeToLong(DateTime.Now), Title = "回复音乐消息", Description = "一段感人的音乐", HQMusicUrl = "http://baidu.music.com", MusicUrl = "fuuuul", ThumbMediaId = "123" }; break; case MsgType.link: { LinkMsg model = XmlHelper.ConvertToModel <LinkMsg>(xmlData); LinkBll.Add(model); //TODO 处理用户的连接信息 } response = new ResponseNewsMsg { FromUserName = baseModel.ToUserName, ToUserName = baseModel.FromUserName, CreateTime = CommonHelp.TimeToLong(DateTime.Now), ArticleCount = 1, Articles = new[] { new ResponseNewsMsg.Article { Description = "", PicUrl = "", Title = "", Url = "" } }, }; break; } EventMsgBll.SaveChanges(); } catch (DbEntityValidationException dbEx) { result = dbEx.EntityValidationErrors.SelectMany(item => item.ValidationErrors).Aggregate(result, (current, item2) => current + string.Format("{0}:{1}\r\n", item2.PropertyName, item2.ErrorMessage)); } return(response.ToUserName == null ? "" : response.GetResponseStr()); }