public static void Eval(Leaf leaf, LinkMsg msg, TCPPacketReader packet, ulong time, LinkMode mode) { switch (msg) { case LinkMsg.MSG_LINK_LEAF_AVATAR: break; case LinkMsg.MSG_LINK_LEAF_CUSTOM_NAME: break; case LinkMsg.MSG_LINK_LEAF_EMOTE_TEXT: break; case LinkMsg.MSG_LINK_LEAF_LOGIN: LeafLogin(leaf, packet, time, mode); break; case LinkMsg.MSG_LINK_LEAF_PERSONAL_MESSAGE: break; case LinkMsg.MSG_LINK_LEAF_PRIVATE_IGNORED: break; case LinkMsg.MSG_LINK_LEAF_PRIVATE_TEXT: break; case LinkMsg.MSG_LINK_LEAF_PUBLIC_TEXT: break; case LinkMsg.MSG_LINK_LEAF_USERLIST_END: break; case LinkMsg.MSG_LINK_LEAF_USERLIST_ITEM: break; } }
public static void Eval(Leaf leaf, LinkMsg msg, TCPPacketReader packet, ulong time, LinkMode mode) { switch (msg) { case LinkMsg.MSG_LINK_LEAF_AVATAR: LeafAvatar(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_CUSTOM_NAME: LeafCustomName(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_EMOTE_TEXT: LeafEmoteText(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_LOGIN: LeafLogin(leaf, packet, time, mode); break; case LinkMsg.MSG_LINK_LEAF_PERSONAL_MESSAGE: LeafPersonalMessage(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_PRIVATE_IGNORED: LeafPrivateIgnored(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_PRIVATE_TEXT: LeafPrivateText(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_PUBLIC_TEXT: LeafPublicText(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_USERLIST_END: LeafUserlistEnd(leaf); break; case LinkMsg.MSG_LINK_LEAF_USERLIST_ITEM: LeafUserlistItem(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_JOIN: LeafJoin(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_PART: LeafPart(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_PING: LeafPing(leaf, time); break; case LinkMsg.MSG_LINK_LEAF_USER_UPDATED: LeafUserUpdated(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_NICK_CHANGED: LeafNickChanged(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_VROOM_CHANGED: LeafVroomChanged(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_IUSER: LeafIUser(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_IUSER_BIN: LeafIUserBin(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_ADMIN: LeafAdmin(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_NO_ADMIN: LeafNoAdmin(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_BROWSE: LeafBrowse(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_BROWSE_DATA: LeafBrowseData(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_CUSTOM_DATA_TO: LeafCustomDataTo(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_CUSTOM_DATA_ALL: LeafCustomDataAll(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_PRINT_ALL: LeafPrintAll(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_PRINT_VROOM: LeafPrintVroom(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_PRINT_LEVEL: LeafPrintLevel(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_PUBLIC_TO_USER: LeafPublicToUser(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_EMOTE_TO_USER: LeafEmoteToUser(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_PUBLIC_TO_LEAF: LeafPublicToLeaf(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_EMOTE_TO_LEAF: LeafEmoteToLeaf(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_NUDGE: LeafNudge(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_SCRIBBLE_USER: LeafScribbleUser(leaf, packet); break; case LinkMsg.MSG_LINK_LEAF_SCRIBBLE_LEAF: LeafScribbleLeaf(leaf, packet); break; } }
private string DealWithMsg(LinkMsg linkMsg) { return(""); }
/// <summary> /// 从请求中提取微信消息推送的请求数据 /// </summary> /// <param name="request">推送过来的请求</param> /// <returns>消息推送的请求数据</returns> public MsgRequest GetMsgRequestData(WeChatEncryptMsg requestEncryptMsg) { //微信服务器在五秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次 //消息排重,推荐使用msgid排重;事件类型消息推荐使用FromUserName + CreateTime 排重 //服务器无法保证在五秒内处理并回复,直接回复success;直接回复空串,微信不再重试 //开发者在5秒内未回复任何内容,开发者回复了异常数据,微信系统提示“该公众号暂时无法提供服务,请稍后再试” if (weChatConfig == null) { throw new NullReferenceException("请使用构造MessageLinkUp(idOrAppId),或初始化Initialize(idOrAppId)"); } string xmlText;//消息 if (weChatConfig.EnCrypt) { //消息是密文,要解密后处理 xmlText = MessageDecrypt(requestEncryptMsg); } else { var stream = requestEncryptMsg.Body; //具体消息数据在请求流里面 StreamReader reader = new StreamReader(stream); xmlText = reader.ReadToEnd(); //消息 reader.Close(); } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlText); XmlNode rootNode = xmlDoc.SelectSingleNode("xml"); MsgRequest msgRequest = null; if (rootNode["MsgType"] == null) { msgRequest = new MsgRequest(); } else { string msgType = rootNode["MsgType"].InnerText; switch (msgType) { case "text": ContentMsg contentMsg = new ContentMsg(); if (rootNode["MsgId"] != null) { contentMsg.MsgId = Convert.ToInt64(rootNode["MsgId"].InnerText); } if (rootNode["Content"] != null) { contentMsg.Content = rootNode["Content"].InnerText; } msgRequest = contentMsg; break; case "image": PictureMsg pictureMsg = new PictureMsg(); if (rootNode["MsgId"] != null) { pictureMsg.MsgId = Convert.ToInt64(rootNode["MsgId"].InnerText); } if (rootNode["PicUrl"] != null) { pictureMsg.PicUrl = rootNode["PicUrl"].InnerText; } if (rootNode["MediaId"] != null) { pictureMsg.MediaId = rootNode["MediaId"].InnerText; } msgRequest = pictureMsg; break; case "voice": VoiceMsg voiceMsg = new VoiceMsg(); if (rootNode["MsgId"] != null) { voiceMsg.MsgId = Convert.ToInt64(rootNode["MsgId"].InnerText); } if (rootNode["MediaId"] != null) { voiceMsg.MediaId = rootNode["MediaId"].InnerText; } if (rootNode["Format"] != null) { voiceMsg.Format = rootNode["Format"].InnerText; } if (rootNode["Recognition"] != null) { voiceMsg.Recognition = rootNode["Recognition"].InnerText; } msgRequest = voiceMsg; break; case "video": VideoMsg videoMsg = new VideoMsg(); if (rootNode["MsgId"] != null) { videoMsg.MsgId = Convert.ToInt64(rootNode["MsgId"].InnerText); } if (rootNode["MediaId"] != null) { videoMsg.MediaId = rootNode["MediaId"].InnerText; } if (rootNode["ThumbMediaId"] != null) { videoMsg.ThumbMediaId = rootNode["ThumbMediaId"].InnerText; } msgRequest = videoMsg; break; case "shortvideo": ShortVideoMsg shortVideoMsg = new ShortVideoMsg(); if (rootNode["MsgId"] != null) { shortVideoMsg.MsgId = Convert.ToInt64(rootNode["MsgId"].InnerText); } if (rootNode["MediaId"] != null) { shortVideoMsg.MediaId = rootNode["MediaId"].InnerText; } if (rootNode["ThumbMediaId"] != null) { shortVideoMsg.ThumbMediaId = rootNode["ThumbMediaId"].InnerText; } msgRequest = shortVideoMsg; break; case "location": LocationMsg locationMsg = new LocationMsg(); if (rootNode["MsgId"] != null) { locationMsg.MsgId = Convert.ToInt64(rootNode["MsgId"].InnerText); } if (rootNode["Location_X"] != null) { locationMsg.Location_X = Convert.ToDouble(rootNode["Location_X"].InnerText); } if (rootNode["Location_Y"] != null) { locationMsg.Location_Y = Convert.ToDouble(rootNode["Location_Y"].InnerText); } if (rootNode["Scale"] != null) { locationMsg.Scale = int.Parse(rootNode["Scale"].InnerText); } if (rootNode["Label"] != null) { locationMsg.Label = rootNode["Label"].InnerText; } msgRequest = locationMsg; break; case "link": LinkMsg linkMsg = new LinkMsg(); if (rootNode["MsgId"] != null) { linkMsg.MsgId = Convert.ToInt64(rootNode["MsgId"].InnerText); } if (rootNode["Title"] != null) { linkMsg.Title = rootNode["Title"].InnerText; } if (rootNode["Description"] != null) { linkMsg.Description = rootNode["Description"].InnerText; } if (rootNode["Url"] != null) { linkMsg.Url = rootNode["Url"].InnerText; } msgRequest = linkMsg; break; case "event": if (rootNode["Event"] != null) { string eventStr = rootNode["Event"].InnerText.ToLower(); switch (eventStr) { case "subscribe": if (rootNode["EventKey"] != null) { string eventKey = rootNode["EventKey"].InnerText; if (eventKey.StartsWith("qrscene_")) { ScanSubscribeEvent scanSubscribeEvent = new ScanSubscribeEvent(); scanSubscribeEvent.EventKey = eventKey; if (rootNode["Ticket"] != null) { scanSubscribeEvent.Ticket = rootNode["Ticket"].InnerText; } msgRequest = scanSubscribeEvent; } } if (msgRequest == null) { msgRequest = new SubscribeEvent(); } break; case "unsubscribe": msgRequest = new UnSubscribeEvent(); break; case "scan": ScanEvent scanEvent = new ScanEvent(); if (rootNode["EventKey"] != null) { scanEvent.EventKey = rootNode["EventKey"].InnerText; } if (rootNode["Ticket"] != null) { scanEvent.Ticket = rootNode["Ticket"].InnerText; } msgRequest = scanEvent; break; case "location": LocationEvent locationEvent = new LocationEvent(); if (rootNode["Latitude"] != null) { locationEvent.Latitude = double.Parse(rootNode["Latitude"].InnerText); } if (rootNode["Longitude"] != null) { locationEvent.Longitude = double.Parse(rootNode["Longitude"].InnerText); } if (rootNode["Precision"] != null) { locationEvent.Precision = double.Parse(rootNode["Precision"].InnerText); } msgRequest = locationEvent; break; case "click": ClickEvent clickEvent = new ClickEvent(); if (rootNode["EventKey"] != null) { clickEvent.EventKey = rootNode["EventKey"].InnerText; } msgRequest = clickEvent; break; case "view": ViewEvent viewEvent = new ViewEvent(); if (rootNode["EventKey"] != null) { viewEvent.EventKey = rootNode["EventKey"].InnerText; } msgRequest = viewEvent; break; case "masssendjobfinish": //批量发送群发消息处理完成的消息通知 MassSendJobFinishEvent sendJobFinishEvent = new MassSendJobFinishEvent(); if (rootNode["MsgID"] != null) { sendJobFinishEvent.MsgID = int.Parse(rootNode["MsgID"].InnerText); } if (rootNode["Status"] != null) { sendJobFinishEvent.Status = Enum.Parse <MassSendJobStatus>(rootNode["Status"].InnerText); } if (rootNode["TotalCount"] != null) { sendJobFinishEvent.TotalCount = int.Parse(rootNode["TotalCount"].InnerText); } if (rootNode["FilterCount"] != null) { sendJobFinishEvent.FilterCount = int.Parse(rootNode["FilterCount"].InnerText); } if (rootNode["SentCount"] != null) { sendJobFinishEvent.SentCount = int.Parse(rootNode["SentCount"].InnerText); } if (rootNode["ErrorCount"] != null) { sendJobFinishEvent.ErrorCount = int.Parse(rootNode["ErrorCount"].InnerText); } XmlNodeList checkResultList = rootNode["CopyrightCheckResult"]?.ChildNodes; if (checkResultList != null && checkResultList.Count > 0) { XmlNode countNode = rootNode["CopyrightCheckResult"]["Count"]; XmlNode checkStateNode = rootNode["CopyrightCheckResult"]["CheckState"]; XmlNode resultListNode = rootNode["CopyrightCheckResult"]["ResultList"]; if (countNode != null) { sendJobFinishEvent.CopyrightCheckCount = int.Parse(countNode.InnerText); } else if (checkStateNode != null) { sendJobFinishEvent.CheckState = int.Parse(checkStateNode.InnerText); } else if (resultListNode != null) { sendJobFinishEvent.ResultList = new List <ArticleCheckResult>(); foreach (XmlNode itemNode in resultListNode) { sendJobFinishEvent.ResultList.Add(new ArticleCheckResult() { ArticleIdx = int.Parse(itemNode["ArticleIdx"].InnerText), UserDeclareState = int.Parse(itemNode["UserDeclareState"].InnerText), AuditState = int.Parse(itemNode["AuditState"].InnerText), OriginalArticleUrl = itemNode["OriginalArticleUrl"].InnerText, OriginalArticleType = int.Parse(itemNode["OriginalArticleType"].InnerText), CanReprint = bool.Parse(itemNode["CanReprint"].InnerText), NeedReplaceContent = bool.Parse(itemNode["NeedReplaceContent"].InnerText), NeedShowReprintSource = bool.Parse(itemNode["NeedShowReprintSource"].InnerText), }); } } } msgRequest = sendJobFinishEvent; break; case "templatesendjobfinish": TemplateSendJobFinishEvent templateSendFinishEvent = new TemplateSendJobFinishEvent(); if (rootNode["MsgID"] != null) { templateSendFinishEvent.MsgID = int.Parse(rootNode["MsgID"].InnerText); } if (rootNode["Status"] != null) { templateSendFinishEvent.Status = rootNode["Status"].InnerText; } break; default: msgRequest = new MsgRequest(); break; } } break; default: msgRequest = new MsgRequest(); break; } msgRequest.MsgType = msgType; } msgRequest.ToUserName = rootNode["ToUserName"].InnerText; msgRequest.FromUserName = rootNode["FromUserName"].InnerText; msgRequest.CreateTime = int.Parse(rootNode["CreateTime"].InnerText); return(msgRequest); }
/// <summary> /// 消息转发多客服 /// </summary> /// <param name="msg"></param> /// <param name="sendKey"></param> private void SendCustomerService(Object obj) { string result = string.Empty; string date = string.Empty; string strUrl = string.Empty; try { ReceiveMsgBase msg = obj as ReceiveMsgBase; if (msg == null) { return; } if (msg is LinkMsg) { LinkMsg link = msg as LinkMsg; link.Title = "<![CDATA[" + link.Title + "]]>"; link.Description = "<![CDATA[" + link.Description + "]]>"; link.Url = "<![CDATA[" + link.Url + "]]>"; } else if (msg is LocationMsg) { LocationMsg link = msg as LocationMsg; link.Location_X = "<![CDATA[" + link.Location_X + "]]>"; link.Location_Y = "<![CDATA[" + link.Location_Y + "]]>"; link.Scale = "<![CDATA[" + link.Scale + "]]>"; link.Label = "<![CDATA[" + link.Label + "]]>"; } else if (msg is PicMsg) { PicMsg link = msg as PicMsg; link.PicUrl = "<![CDATA[" + link.PicUrl + "]]>"; link.MediaId = "<![CDATA[" + link.MediaId + "]]>"; } else if (msg is TextMsg) { TextMsg link = msg as TextMsg; link.Content = "<![CDATA[" + link.Content + "]]>"; } else if (msg is VideoMsg) { VideoMsg link = msg as VideoMsg; link.ThumbMediaId = "<![CDATA[" + link.ThumbMediaId + "]]>"; link.MediaId = "<![CDATA[" + link.MediaId + "]]>"; } else if (msg is VoiceMsg) { VoiceMsg link = msg as VoiceMsg; link.MediaId = "<![CDATA[" + link.MediaId + "]]>"; link.Format = "<![CDATA[" + link.Format + "]]>"; link.Recognition = "<![CDATA[" + link.Recognition + "]]>"; } //try //{ // DataTable dt = DalMemberCommon.GetMemberInfoByWeiXinOpenId(msg.FromUserName); // if (dt != null && dt.Rows.Count > 0) // { date = msg.ToXml(); strUrl = @"http://dkf.ozner.net/service/wxcustomer.aspx"; } catch (Exception ex) { string errorinfo = "错误堆栈:" + ex.StackTrace; if (obj != null) { string addition = ""; string baseName = obj.GetType().Name; if (obj is ReceiveMsgBase) { ReceiveMsgBase rmb = obj as ReceiveMsgBase; Type type = rmb.GetType(); if (rmb is LinkMsg) { LinkMsg link = rmb as LinkMsg; addition = link.Title + "|" + link.Description + "|" + link.Url; } else if (rmb is LocationMsg) { LocationMsg link = rmb as LocationMsg; addition = link.Location_X + "|" + link.Location_Y + "|" + link.Scale + "|" + link.Label; } else if (rmb is PicMsg) { PicMsg link = rmb as PicMsg; addition = link.PicUrl + "|" + link.MediaId; } else if (rmb is TextMsg) { TextMsg link = rmb as TextMsg; addition = link.Content; } else if (rmb is VideoMsg) { VideoMsg link = rmb as VideoMsg; addition = link.MediaId + "|" + link.ThumbMediaId; } else if (rmb is VoiceMsg) { VoiceMsg link = rmb as VoiceMsg; addition = link.MediaId + "|" + link.Format + "|" + link.Recognition; } } errorinfo = "类型:" + obj.GetType().Name + " 额外信息:" + addition + " 错误信息:" + errorinfo; } //LogBase.LogHzLkt.LogExErr("HzLktSite", "OznerMall", "SendCustomerService", errorinfo, ELogExLevel.Higher, errorinfo); } try { result = WebClientHelper.CallPost(strUrl, date, Encoding.UTF8); } catch (Exception ex) { //LogBase.LogHzLkt.LogExErr(ex, ELogExLevel.Middle); } }
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()); }