using BWP.B3WeChat.Entities; using BWP.B3WeChat.Utils; using Forks.EnterpriseServices.DomainObjects2; using Forks.EnterpriseServices.DomainObjects2.DQuery; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; namespace BWP.Web.Pages { class WeChatReceive : IHttpHandler { static Forks.Utils.Logger logger = new Forks.Utils.Logger("InOutMessageUtil"); string echoStr { get { return HttpContext.Current.Request.QueryString["echoStr"]; } } public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext context) { #region 接入验证 if (!string.IsNullOrEmpty(echoStr)) { if (InOutMessageUtil.CheckSignature()) { HttpContext.Current.Response.Write(echoStr); HttpContext.Current.Response.End(); } return; } #endregion object result = InOutMessageUtil.GetMessage(context.Request); if (result is ReceivedMsg) { ReceivedMsg msg = result as ReceivedMsg; string str = string.Empty; if (msg != null) { ReplyMsg mes = new ReplyMsg() { CreateTime = ((int)DateTime.Now.Subtract(DateTime.Parse("1970-01-01")).TotalSeconds).ToString(), Content = msg.Content, ToUserName = msg.FromUserName, FromUserName = InOutMessageUtil.config.SelfAppID, MsgType = "text" }; str = XmlUtil.Serializer(mes.GetType(), mes); byte[] arr = Encoding.UTF8.GetBytes(str); HttpContext.Current.Response.OutputStream.Write(arr, 0, arr.Length); HttpContext.Current.Response.End(); } } else if (result is QRCodeMessage) { QRCodeMessage msg = result as QRCodeMessage; logger.Info("EventKey:" + msg.EventKey + ",FromUserName:" + msg.FromUserName); UpdateQRCode(msg.EventKey, msg.FromUserName); logger.Info("关联成功"); } } static void UpdateQRCode(string sceneId, string OppenId) { var update = new DQUpdateDom(typeof(QRCodeScene)); update.Where.Conditions.Add(DQCondition.EQ("ID", sceneId)); update.Columns.Add(new DQUpdateColumn("OppenId", OppenId)); using (var session = Dmo.NewSession()) { session.ExecuteNonQuery(update); } } } }