public string Handle(string postStr, string schoolid) { //log //ServiceCommon servComm = new ServiceCommon(); //ERROR_MESSAGEINFO einfo = new ERROR_MESSAGEINFO(); //einfo.CHANNEL = "微信调用"; //einfo.DISCRIPTION = "Handle:in " + postStr; //einfo.CREATEDATE = DateTime.Now; //einfo.ISDEL = 0; //servComm.Add(einfo); //封装请求类,将数据post过来的数据封装到xml中,以便解析返回。 XmlDocument doc = new XmlDocument(); doc.LoadXml(postStr); XmlElement rootElement = doc.DocumentElement; XmlNode MsgType = rootElement.SelectSingleNode("MsgType"); RequestXML requestXML = new RequestXML(); requestXML.ToUserName = rootElement.SelectSingleNode("ToUserName").InnerText; requestXML.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText; requestXML.CreateTime = rootElement.SelectSingleNode("CreateTime").InnerText; requestXML.MsgType = MsgType.InnerText; if (requestXML.MsgType == "text") { requestXML.Content = rootElement.SelectSingleNode("Content").InnerText; } else if (requestXML.MsgType == "location") { requestXML.Location_X = rootElement.SelectSingleNode("Location_X").InnerText; requestXML.Location_Y = rootElement.SelectSingleNode("Location_Y").InnerText; requestXML.Scale = rootElement.SelectSingleNode("Scale").InnerText; requestXML.Label = rootElement.SelectSingleNode("Label").InnerText; } else if (requestXML.MsgType == "image") { requestXML.PicUrl = rootElement.SelectSingleNode("PicUrl").InnerText; } else if (requestXML.MsgType == "event") { requestXML.Event = rootElement.SelectSingleNode("Event").InnerText; requestXML.EventKey = rootElement.SelectSingleNode("EventKey").InnerText; if (requestXML.Event == "scancode_waitmsg") { requestXML.ScanResult = rootElement.SelectSingleNode("ScanCodeInfo").SelectSingleNode("ScanResult").InnerText; //einfo.CHANNEL = "微信调用"; //einfo.DISCRIPTION = "::::" + requestXML.Event + " - " + requestXML.ScanResult; //einfo.CREATEDATE = DateTime.Now; //einfo.ISDEL = 0; //servComm.Add(einfo); } } else if (requestXML.MsgType == "video") { requestXML.MediaId = rootElement.SelectSingleNode("MediaId").InnerText; } else { requestXML.Content = rootElement.SelectSingleNode("Content").InnerText; } GeeStar.Workflow.Common.Log.LogError("FromUserName:"******"weixin.cs ip:" + HttpContext.Current.Request.UserHostAddress); //回复消息 ResponseMsg(requestXML, schoolid); return(requestXML.FromUserName); }
/// <summary> /// 回复消息(微信信息返回) /// </summary> /// <param name="weixinXML"></param> private void ResponseMsg(RequestXML requestXML, string schoolid) { //ERROR_MESSAGEINFO einfo = new ERROR_MESSAGEINFO(); //einfo.CHANNEL = "微信调用"; //einfo.DISCRIPTION = "ResponseMsg:in " + requestXML.Event + requestXML.EventKey; //einfo.CREATEDATE = DateTime.Now; //einfo.ISDEL = 0; //servComm.Add(einfo); try { string resxml = ""; //mijiya mi = new mijiya(requestXML.Content, requestXML.FromUserName); if (requestXML.MsgType == "text") { #region 客户端提交文本逻辑 if (requestXML.Content.ToLower().IndexOf("tp") == 0) { //投票出错,请稍后再试。 resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + "投票失败,请稍后再试!<a href=\"http://www.51yey.com/weixin/data/popbaby.aspx?schoolid=" + "\">点击查看详情</a>。" + "]]></Content><FuncFlag>1</FuncFlag></xml>"; } else if (requestXML.Content.IndexOf("#") == 0 && requestXML.Content.Length > 1) { resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + "设置失败,请重新设置!]]></Content><FuncFlag>1</FuncFlag></xml>"; } else { resxml = getSubscribedata(requestXML.FromUserName, requestXML.ToUserName, schoolid); } #endregion 客户端提交文本逻辑 } else if (requestXML.MsgType == "event") { #region 客户端事件逻辑 if (requestXML.Event == "subscribe") { //用户关注时的动作 resxml = getSubscribedata(requestXML.FromUserName, requestXML.ToUserName, schoolid); } } if (resxml == "") { } else { System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; System.Web.HttpContext.Current.Response.Write(resxml); System.Web.HttpContext.Current.Response.End(); } //WriteToDB(requestXML, resxml, mi.pid); } catch (Exception ex) { //WriteTxt("异常:" + ex.Message + "Struck:" + ex.StackTrace.ToString()); //wx_logs.MyInsert("异常:" + ex.Message + "Struck:" + ex.StackTrace.ToString()); //codelog mylog = new codelog(); //mylog.isdel = 0; //mylog.logtxt = "异常:" + ex.Message + "Struck:" + ex.StackTrace.ToString(); //servComm.Add(mylog); } }