public ActionResult GetEditUserInfo() { int ID = int.Parse(Request["ID"]); var entity = UserInfoService.LoadEntities(u => u.ID == ID).FirstOrDefault(); string json = (JsonSerializeHelper.JsonSerialize(entity)); return(Content(json)); // return Json(entity, JsonRequestBehavior.AllowGet); }
public void HandleMessage(int Pid, string content, ILogWriter _log) { _log.Info("收到一条消息处理请求:" + content); //拆分字符串并拼json var arrContent = content.Split(new string[] { "|&|" }, StringSplitOptions.RemoveEmptyEntries); var center = ConfigurationManager.AppSettings["MessageCenter"]; //如果不是文字、图片消息,就直接返回 if (arrContent[3].IndexOf("no") > -1) { return; } Task.Run(() => { string msgContent = ""; if (arrContent[3].IndexOf("image") > -1) { string u1 = GetImageBaseDir() + arrContent[4]; u1 = u1.Substring(0, u1.LastIndexOf(".dat") + 4);//防止后面有乱码 try { _log.Info(u1 + "\r\n"); //解密图片 msgContent = DecryptImageHelper.Decrypt(u1); } catch (Exception ex) { _log.Error("解密图片时候报错:" + ex.Message + u1); } } else { msgContent = arrContent[2]; } var jsonObj = new { GroupId = arrContent[0], MemberId = arrContent[1], MsgTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff"), MsgContent = msgContent, MsgType = arrContent[3] }; _log.Fatal(msgContent); var jsonContent = JsonSerializeHelper.JsonSerialize(jsonObj); //发送到数据接口 //new WebHelper().PostMessage(center, jsonContent, _log); //调用微信群组接口 //ChatRoomMember.GetChatRoomUser(Pid, jsonObj.GroupId); ChatRoomMember.SendRoomAtMsg(Pid, arrContent[0]); }); }
private void ListenExecute(object obj) { Socket client = obj as Socket; try { string ip = (client.RemoteEndPoint as System.Net.IPEndPoint).Address.ToString(); byte[] buffer = new byte[1024]; int count = client.Receive(buffer); if (count > 0) { string content = Encoding.UTF8.GetString(buffer, 0, count); if (content.IndexOf("@chatroom") == -1) { return; } //_log.Debug("请求一次微信群组调用:" + content); _log.Debug(DateTime.Now.ToString() + "收到了一次socket请求:http://localhost:83/Home/About?a=" + content); //System.IO.File.AppendAllText("c:/socketLog.txt", "socket:" + ip + ":" + port + ":" + content); ////发起请求,获取微信群组列表 ChatRoomMember.GetChatRoomUser(pid, content); try { string data = JsonSerializeHelper.JsonSerialize(new { status = "success", errorMessage = "" }); client.Send(Encoding.UTF8.GetBytes(data)); } catch (Exception ex) { string data = JsonSerializeHelper.JsonSerialize(new { status = "error", errorMessage = ex.Message }); client.Send(Encoding.UTF8.GetBytes(data)); } finally { } } } catch { } finally { try { client.Shutdown(SocketShutdown.Both); client.Close(); client.Dispose(); } catch { } } }
public ActionResult LoginUser() { string sessionValidateCode = Session["ValidateCode"] != null ? Session["ValidateCode"].ToString() : string.Empty; if (string.IsNullOrEmpty(sessionValidateCode)) { return(Content("N:验证码错误!")); } if (!Request["vCode"].Equals(sessionValidateCode, StringComparison.CurrentCultureIgnoreCase)) { return(Content("N:验证码错误!")); } string uName = Request["LoginCode"]; string uPwd = Request["LoginPwd"]; var loginUser = UserInfoService.LoadEntities(u => u.UName == uName && u.UPwd == uPwd).FirstOrDefault(); if (loginUser == null) { Session["ValidateCode"] = null; return(Content("N:用户名密码错误!")); } // Session["LoginUser"] = loginUser; else { string sessionCookie = Guid.NewGuid().ToString(); MemcachedHelper.SetMemcachedData(sessionCookie, JsonSerializeHelper.JsonSerialize(loginUser), DateTime.Now.AddMinutes(20)); Response.Cookies["LoginCookie"].Value = sessionCookie; } if (Request["checkRemember"] != null) { HttpCookie cp1 = new HttpCookie("UName", loginUser.UName); HttpCookie cp2 = new HttpCookie("UPwd", MD5Helper.GetMD5String(MD5Helper.GetMD5String(loginUser.UPwd))); cp1.Expires = DateTime.Now.AddDays(5); cp2.Expires = DateTime.Now.AddDays(5); HttpContext.Response.Cookies.Add(cp1); HttpContext.Response.Cookies.Add(cp2); } return(Content("Y:用户登陆成功!")); }
// GET: Login public ActionResult Index() { if (Request.Cookies["UName"] != null && !string.IsNullOrEmpty(Request.Cookies["UName"].Value)) { string cookieUName = Request.Cookies["UName"].Value; string cookieUPwd = Request.Cookies["UPwd"].Value; var loginUser = UserInfoService.LoadEntities(u => u.UName == cookieUName).FirstOrDefault(); if (cookieUPwd == MD5Helper.GetMD5String(MD5Helper.GetMD5String(loginUser.UPwd))) { string sessionCookie = Guid.NewGuid().ToString(); MemcachedHelper.SetMemcachedData(sessionCookie, JsonSerializeHelper.JsonSerialize(loginUser), DateTime.Now.AddMinutes(20)); Response.Cookies["LoginCookie"].Value = sessionCookie; Response.Cookies["UName"].Expires = DateTime.Now.AddDays(5); Response.Cookies["UPwd"].Expires = DateTime.Now.AddDays(5); return(Redirect("/Home/Index")); } else { Response.Cookies["UName"].Expires = DateTime.Now.AddDays(-1); Response.Cookies["UPwd"].Expires = DateTime.Now.AddDays(-1); } } return(View()); }
protected override void WndProc(ref Message m) { if (m.Msg == 0x004A) { COPYDATASTRUCT cds = new COPYDATASTRUCT(); Type type = cds.GetType(); cds = (COPYDATASTRUCT)m.GetLParam(type); //无效信息拦截 if (cds.dwData != 0 && cds.dwData != 2) { return; } if (tb_MsgBox.Text.Length > 10000) { tb_MsgBox.Text = string.Empty; } if (cds.dwData == 0) { //不再是传值的方式了,通过文件的方式,所以这里注释 ////接受到的群消息 //var content = Marshal.PtrToStringAnsi(cds.lpData); ////处理接受到的消息 //new HandleReceiveMessage().HandleMessage(content, _log); //tb_MsgBox.Text += content; //回复消息 //var chatroomId = content.Split(new string[] { "|&|" }, StringSplitOptions.RemoveEmptyEntries)[0]; //ChatRoomMember.SendRoomAtMsg(Pid, chatroomId); #region 注释 //拆分字符串并拼json //var arrContent = content.Split(new string[] { "|&|" }, StringSplitOptions.RemoveEmptyEntries); //var center = ConfigurationManager.AppSettings["MessageCenter"]; //如果不是文字、图片消息,就直接返回 //if (arrContent[3].IndexOf("no") > -1) //{ // return; //} //Task.Run(() => //{ // string msgContent = ""; // if (arrContent[3].IndexOf("image") > -1) // { // string u1 = GetImageBaseDir() + arrContent[4]; // u1 = u1.Substring(0, u1.LastIndexOf(".dat") + 4);//防止后面有乱码 // try // { // _log.Info(u1 + "\r\n"); // 解密图片 // msgContent = DecryptImageHelper.Decrypt(u1); // } // catch (Exception ex) // { // _log.Error("解密图片时候报错:" + ex.Message + u1); // } // } // else // { // msgContent = arrContent[2]; // } // var jsonObj = new // { // GroupId = arrContent[0], // MemberId = arrContent[1], // MsgTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff"), // MsgContent = msgContent, // MsgType = arrContent[3] // }; // var jsonContent = JsonSerializeHelper.JsonSerialize(jsonObj); // 显示日志 // tb_MsgBox.Text += jsonContent; // 发送到数据接口 // new WebHelper().PostMessage(center, jsonContent, _log); // 调用微信群组接口 // ChatRoomMember.GetChatRoomUser(Pid, jsonObj.GroupId); //}); #endregion } else if (cds.dwData == 2) { //获取到的群成员列表 var content = Marshal.PtrToStringUni(cds.lpData); try { //群组信息与成员列表切分开 var chatRoomIdandMember = content.Split(new string[] { "_&&_" }, StringSplitOptions.RemoveEmptyEntries); //群组id var chatRoomId = chatRoomIdandMember[0].Split(new string[] { "|&|" }, StringSplitOptions.RemoveEmptyEntries)[0]; _log.Debug("响应一次微信群组调用:" + chatRoomId); //群组名称 var chatRoomName = chatRoomIdandMember[0].Split(new string[] { "|&|" }, StringSplitOptions.RemoveEmptyEntries)[1]; //群的成员列表。 var chatRoomMembers = chatRoomIdandMember[1].Split(new string[] { "_&_" }, StringSplitOptions.RemoveEmptyEntries); List <object> memberList = new List <object>(); chatRoomMembers.ToList().ForEach(p => { var member = p.Split(new string[] { "|&|" }, StringSplitOptions.None); if (member.Length == 3) { memberList.Add(new { MemberId = member[0], MemberNickName = member[2], MemberAreas = "", MemberNumber = member[1], MemberGroupName = member[2] }); } }); var JsonObj = new { GroupId = chatRoomId, GroupName = chatRoomName, MemberList = memberList }; var JsonString = JsonSerializeHelper.JsonSerialize(JsonObj); tb_MsgBox.Text += JsonString; var center = ConfigurationManager.AppSettings["ChatRoomMemberListCenter"]; Task.Run(() => { new WebHelper().PostMessage(center, JsonString, _log); }); } catch (Exception ex) { _log.Error("获取到的群成员列表,请求过程中程序报错:" + ex.Message + "content为:" + content); } } } else { base.WndProc(ref m); } }