/// <summary> /// 设置门禁主机时间 /// </summary> /// <param name="deviceIp">门禁主机ip</param> /// <returns>true:成功 false:失败</returns> public bool SetDeviceTime(string deviceIp) { CHDOperate op = GetOPByIP(deviceIp); bool b = false; if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) { if (!op.isLinkOn) { op.isLinkOn = op.LinkOn(false); } if (op.isLinkOn) { b = op.SetDeviceTime(); if (!b) { CHDDoorUseInfo info = GetUseInfo(deviceIp); if (null != info) { ReLogin(info); } } return(b); } } TextMsg?.Invoke(string.Format("门禁主机 {0} 同步时间 {1} 失败···", deviceIp, DateTime.Now)); return(b); }
/// 启动服务 private void BtnStratSer_Click(object sender, EventArgs e) { try { //定义一个套接字用于监听客户端发来的信息 包含3个参数(IP4寻址协议,流式连接,TCP协议) socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //服务端发送信息 需要1个IP地址和端口号 IPAddress ipaddress = IPAddress.Parse("127.0.0.1"); //获取文本框输入的IP地址 //将IP地址和端口号绑定到网络节点endpoint上 IPEndPoint endpoint = new IPEndPoint(ipaddress, int.Parse("8888")); //获取文本框上输入的端口号 //监听绑定的网络节点 socketWatch.Bind(endpoint); //将套接字的监听队列长度限制为20 socketWatch.Listen(20); //创建一个监听线程 threadWatch = new Thread(WatchConnecting); //将窗体线程设置为与后台同步 threadWatch.IsBackground = true; //启动线程 threadWatch.Start(); //启动线程后 txtMsg文本框显示相应提示 TextMsg.AppendText("开始监听客户端传来的信息!" + "\r\n"); this.BtnStratSer.Enabled = false; } catch (Exception ex) { TextMsg.AppendText("服务端启动服务失败!" + "\r\n"); this.BtnStratSer.Enabled = true; } }
/// <summary> /// 设置门禁主机参数 /// </summary> /// <param name="deviceIp">门禁主机ip</param> /// <param name="param">参数信息</param> /// <returns>true:成功 false:失败</returns> public bool SetDeviceConfig(string deviceIp, CHDDoorParam param) { CHDOperate op = GetOPByIP(deviceIp); bool b = false; string str = ""; if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) { if (!op.isLinkOn) { op.LinkOn(true); } if (op.isLinkOn) { b = op.SetDoorParam(param); if (!b) { op.LinkOn(true); b = op.SetDoorParam(param); } return(b); } str = "无权限"; } else { str = "设备无法通讯"; } param = null; TextMsg?.Invoke(string.Format("门禁主机 {0} 设置参数失败,{1},请稍后再试···{2}", deviceIp, str, DateTime.Now)); return(b); }
/// <summary> /// 添加用户 /// </summary> /// <returns>true:成功 false:失败</returns> public bool AddCardUser(CHDUserInfo userInfo) { bool b = false; if (userInfo != null) { CHDOperate op = GetOPByIP(userInfo.DeviceIp); //CHDDoorUseInfo info = GetUseInfo(userInfo.DeviceIp); if (null != op) { if (op.isLinkOn) { b = op.AddUser(userInfo); return(b); } else { TextMsg?.Invoke(string.Format("门禁主机 {0} 添加用户失败,无权限,请稍后再试···", userInfo.DeviceIp)); op.LinkOn(); } } } TextMsg?.Invoke(string.Format("门禁主机 {0} 添加用户失败,设备无法通讯,请稍后再试···", userInfo.DeviceIp)); return(b); }
private static VisitNoteModel TextMsgToVisitNoteModel(TextMsg textmsg) { return(new VisitNoteModel { Id = textmsg.Vid, Date = textmsg.Date, From = textmsg.From, Note = textmsg.Msg }); }
public ActionResult Create(TextMsg sms) { try { return(RedirectToAction("Details", sms)); } catch { return(View()); } }
private void Op_CHDLogMsg(CHDClass.CHDMsg msg) { TextMsg?.Invoke(msg.Msg); if (msg.Msg.Contains("无权限")) { (new Thread(new ParameterizedThreadStart(ReDlink)) { IsBackground = true }).Start(msg); } }
/// <summary> /// 寻卡号 /// </summary> /// <param name="op">门禁主机操作对象</param> /// <returns>返回卡号</returns> public string ReaderCardNum(CHDOperate op) { string no = ""; if (null != op) { no = op.GetCardNum(); } TextMsg?.Invoke(string.Format("门禁主机 {0} 获取卡号失败···", op.deviceIp, DateTime.Now)); return(no); }
// // Event Handlers // static void _GhostAttacked(object sender, CritterAttackedEventArgs e) { var ghost = sender as Critter; // regenerate HP ghost.Stat[Stats.CurrentHP] = ghost.Stat[Stats.MaxLife]; // scream to scary player ghost.SayMsg(Say.ShoutOnHead, TextMsg.Dlg, TextMsg.DlgStr(Dialogs.Ghost, Str.Scream)); // do nothing after attack e.PreventDefaults(); }
/// 监听客户端发来的请求 private void WatchConnecting() { while (true) //持续不断监听客户端发来的请求 { socConnection = socketWatch.Accept(); TextMsg.AppendText("客户端连接成功! " + "\r\n"); //创建一个通信线程 ParameterizedThreadStart pts = new ParameterizedThreadStart(ServerRecMsg); Thread thr = new Thread(pts); thr.IsBackground = true; //启动线程 thr.Start(socConnection); } }
public static void EditVisitNote(VisitNoteModel vnm) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { List <TextMsg> textmsgs = opiddailycontext.TextMsgs.Where(m => m.Vid == vnm.Id).ToList(); if (textmsgs.Count == 1) { TextMsg textmsg = textmsgs[0]; VisitNoteModelToTextMsg(vnm, textmsg); opiddailycontext.SaveChanges(); } } }
public static void DeleteVisitNote(int id) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { List <TextMsg> textmsgs = opiddailycontext.TextMsgs.Where(m => m.Vid == id).ToList(); TextMsg textmsg = textmsgs[0]; if (textmsgs.Count == 1) { opiddailycontext.TextMsgs.Remove(textmsg); opiddailycontext.SaveChanges(); } } }
public static void AddVisitNote(int nowServing, int vid, string sender, VisitNoteModel vnm) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { Client client = opiddailycontext.Clients.Find(nowServing); opiddailycontext.Entry(client).Collection(c => c.TextMsgs).Load(); TextMsg textmsg = VisitNoteModelToTextMsg(vnm, vid); client.TextMsgs.Add(textmsg); opiddailycontext.SaveChanges(); } }
/// <summary> /// 设置时间段 /// </summary> /// <param name="deviceIp">门禁主机ip</param> /// <param name="times">时间段</param> /// <returns>true:成功 false:失败</returns> public bool SetDayTimes(string deviceIp, List <DayTimeSplit> times) { CHDOperate op = GetOPByIP(deviceIp); bool b = false; if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) { if (op.isLinkOn) { b = op.SetListTime(times); return(b); } } TextMsg?.Invoke(string.Format("门禁主机 {0} 获取时间段失败···", deviceIp, DateTime.Now)); return(false); }
/// <summary> /// 发送消息 /// </summary> /// <returns></returns> public dynamic SendChat(string cid, string content) { Dictionary <string, string> dic = new Dictionary <string, string>(); var msg = new TextMsg(); msg.msgtype = "text"; msg.text = new Text(); msg.text.content = content; dic.Add("sender", "0540636631658"); dic.Add("cid", cid); //dic.Add("chatid", "0b261630e9743b229cb12861dd550185"); dic.Add("msg", JsonHelper.SerializeObject(msg)); var response = HttpHelper.Post($"https://oapi.dingtalk.com/message/send_to_conversation?access_token={_accessToken}", JsonHelper.SerializeObject(dic)); return(JsonHelper.DeserializeJsonToObject <dynamic>(response.ToString())); }
/// <summary> /// 读取新纪录 /// </summary> /// <param name="deviceIp">门禁主机ip地址</param> public void ReadOneRe(string deviceIp) { CHDOperate op = GetOPByIP(deviceIp); if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) { if (op.isLinkOn) { if (op.ReadOneRec()) { return; } } } TextMsg?.Invoke(string.Format("门禁主机 {0} 读取新纪录失败···", deviceIp, DateTime.Now)); }
/// <summary> /// 发送消息函数 /// </summary> /// <param name="sendMsg"></param> private void ServerSendMsg(string sendMsg) { try //正常时顺序执行语句 { //将输入的字符串转换成 机器可以识别的字节数组 byte[] arrSendMsg = Encoding.UTF8.GetBytes(sendMsg); //向客户端发送字节数组信息 socConnection.Send(arrSendMsg); //将发送的字符串信息附加到文本框txtMsg上 TextMsg.AppendText("服务器:" + GetCurrentTime() + "\r\n" + sendMsg + "\r\n"); } catch (Exception ex) //异常时执行下面语句 { TextMsg.AppendText("客户端已断开连接,无法发送信息!" + "\r\n"); } }
public string SendWechatMsg_Text(string userids, string content) { TextMsg msg = new TextMsg(); msg.agentid = AgentId; msg.msgtype = AgentId; msg.msgtype = "text"; msg.touser = userids; text textcontent = new text(); textcontent.content = content; msg.text = textcontent; msg.safe = "0"; string paraJsonStr = JsonConvert.SerializeObject(msg); return(SendWechatMessage(paraJsonStr)); }
/// <summary> /// 获取门禁主机工作状态 /// </summary> /// <param name="deviceIp">门禁主机ip</param> /// <param name="state">门禁主机状态对象</param> /// <returns>true:成功 false:失败</returns> public bool GetWorkState(string deviceIp, ref CHDDeviceState state) { CHDOperate op = GetOPByIP(deviceIp); bool b = false; if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) { if (op.isLinkOn) { b = op.GetWorkState(ref state); return(b); } } TextMsg?.Invoke(string.Format("门禁主机 {0} 工作状态获取失败···", deviceIp)); return(b); }
/// <summary> /// 获取周计划 /// </summary> /// <param name="deviceIp">门禁主机ip</param> /// <param name="wPlan">周计划</param> /// <returns>true:成功 false:失败</returns> public bool GetWeekPlan(string deviceIp, ref WeekPlan wPlan) { CHDOperate op = GetOPByIP(deviceIp); bool b = false; if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) { if (op.isLinkOn) { b = op.GetWeePlan(ref wPlan); return(b); } } TextMsg?.Invoke(string.Format("门禁主机 {0} 设置周计划失败···", deviceIp, DateTime.Now)); return(false); }
/// <summary> /// 寻卡号 /// </summary> /// <param name="com">通讯端口</param> /// <returns>返回卡号</returns> public string ReaderCardNum(string com) { CHDOperate op = new CHDOperate(); op.CHDLogMsg += Op_CHDLogMsg; if (op.ConnectionDevice(com, DeviceType.CHDCardReader, portOrBaud: 9600, isTcp: false)) { string no = ""; if (null != op && !string.IsNullOrWhiteSpace(com)) { no = op.GetCardNum(); } op.DisConnectionDevice(); return(no); } TextMsg?.Invoke(string.Format("门禁主机 {0} 获取卡号失败···", com, DateTime.Now)); return(""); }
/// <summary> /// 发送文本消息 /// </summary> /// <param name="msg">消息</param> /// <param name="access_token">访问令牌</param> /// <returns></returns> public static RequestResultBaseModel SendText(TextMsg msg, string access_token) { if (null == msg) { throw new ArgumentException("参数错误", nameof(msg)); } if (string.IsNullOrWhiteSpace(msg.touser)) { throw new ArgumentException("参数错误", nameof(msg.touser)); } if (null == msg.text || string.IsNullOrWhiteSpace(msg.text.content)) { throw new ArgumentException("content参数错误"); } string jsonString = JsonHelper.Serialize(msg); return(SendToWeCart(jsonString, access_token)); }
/* * Handles stealing from ghost. * Stealing attempt fails in any case with a chance for player to cripple right hand. */ static void _GhostStealing(object sender, CritterStealingEventArgs e) { var thief = e.Thief; if (thief.IsPlayer) { int injureHandChance = 20; int injureHandRoll = Global.Random(1, 100); if (injureHandRoll <= injureHandChance) { thief.Damage[Damages.RightArm] = 1; thief.SayMsg(Say.NetMsg, TextMsg.Dlg, TextMsg.DlgStr(Dialogs.Ghost, Str.StealInjure)); } else { thief.SayMsg(Say.NetMsg, TextMsg.Dlg, TextMsg.DlgStr(Dialogs.Ghost, Str.Steal)); } } }
public string Index(Access model, TextMsg model2) { if (string.IsNullOrEmpty(model.Echostr) || string.IsNullOrEmpty(model.Nonce) || string.IsNullOrEmpty(model.Signature) || string.IsNullOrEmpty(model.Timestamp)) { return("参数错误le !"); } string token = ConfigHelper.GetValueByKey("Token"); List <string> list = new List <string> { token, model.Timestamp, model.Nonce }; list.Sort(); if (EncryptHelper.Sha1Encrypt(string.Join("", list)).ToUpper().Equals(model.Signature.ToUpper())) { return(model.Echostr); } return("Error"); }
/// <summary> /// 删除用户信息根据卡号 /// </summary> /// <param name="cardNo">卡号</param> /// <param name="deviceIp">门禁主机ip</param> /// <returns>true:成功 false:失败</returns> public bool DeleteUserByCard(string cardNo, string deviceIp) { CHDOperate op = GetOPByIP(deviceIp); bool b = false; if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) { if (op.isLinkOn) { b = op.DeleteUserByCard(cardNo); return(b); } else { TextMsg?.Invoke(string.Format("门禁主机 {0} 删除卡 {1} 用户失败,无权限,请稍后再试···", deviceIp, cardNo)); } } TextMsg?.Invoke(string.Format("门禁主机 {0} 删除卡 {1} 用户失败,设备无法通讯,请稍后再试···", deviceIp, cardNo)); return(b); }
/// <summary> /// 删除超级权限卡 /// </summary> /// <param name="deviceIp">门禁主机ip</param> /// <returns>true:成功 false:失败</returns> public bool DeleteSuperCard(string deviceIp) { CHDOperate op = GetOPByIP(deviceIp); bool b = false; if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) { if (op.isLinkOn) { b = op.DeleteSuperCard(); return(b); } else { TextMsg?.Invoke(string.Format("门禁主机 {0} 删除超级卡失败,无权限,请稍后再试···", deviceIp)); } } TextMsg?.Invoke(string.Format("门禁主机 {0} 删除超级卡失败···", deviceIp)); return(b); }
/// <summary> /// 获取超级卡 /// </summary> /// <param name="deviceIp">门禁主机ip</param> /// <param name="superCard1">特权卡1</param> /// <param name="superCard2">特权卡2</param> /// <param name="superCard3">特权卡3</param> /// <param name="superCard4">特权卡4</param> /// <returns>true:成功 false:失败</returns> public bool GetSuperCard(string deviceIp, ref string superCard1, ref string superCard2, ref string superCard3, ref string superCard4) { CHDOperate op = GetOPByIP(deviceIp); bool b = false; if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) { if (op.isLinkOn) { b = op.GetSuperCard(ref superCard1, ref superCard2, ref superCard3, ref superCard4); return(b); } else { TextMsg?.Invoke(string.Format("门禁主机 {0} 获取超级卡失败,无权限,请稍后再试···", deviceIp)); } } TextMsg?.Invoke(string.Format("门禁主机 {0} 获取超级卡失败···", deviceIp)); return(b); }
private void button4_Click(object sender, EventArgs e) { string text = TextMsg.Text; Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("type", "general_chat"); data.Add("action", "write"); data.Add("user_id", UserData.user_id.ToString()); data.Add("session_id", UserData.session_token); data.Add("text", text); string json = JsonConvert.SerializeObject(data, Formatting.Indented); string answer = Service.SendRequestAndGetAnswer(json); if (answer != "1") { MessageBox.Show("Error!"); } TextMsg.Clear(); }
/// <summary> /// 获取用户信息根据卡号 /// </summary> /// <param name="cardNo">用户卡号</param> /// <param name="deviceIp">门禁主机ip</param> /// <returns>返回卡用户信息</returns> public CHDUserInfo GetUserInfoByCard(string cardNo, string deviceIp) { CHDOperate op = GetOPByIP(deviceIp); CHDUserInfo info = new CHDUserInfo(); if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) { if (op.isLinkOn) { info = op.GetUserInfoByCard(cardNo); return(info); } else { TextMsg?.Invoke(string.Format("门禁主机 {0} 获取卡 {1} 用户失败,无权限,请稍后再试···", deviceIp, cardNo)); } } TextMsg?.Invoke(string.Format("门禁主机 {0} 获取卡 {1} 用户失败,设备无法通讯,请稍后再试···", deviceIp, cardNo)); return(null); }
///// <summary> ///// 设置超级卡 ///// </summary> ///// <param name="deviceIp">门禁主机ip</param> ///// <returns>true:成功 false:失败</returns> //public bool DelSuperCard(string deviceIp) //{ // CHDOperate op = GetOPByIP(deviceIp); // bool b = false; // if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) // { // if (op.isLinkOn) // { // b = op.DeleteSuperCard(); // // return b; // } // } // TextMsg?.Invoke(string.Format("门禁主机 {0} 删除超级卡 {1} 用户失败···", deviceIp)); // return b; //} /// <summary> /// 设置超级密码 /// </summary> /// <param name="deviceIp">门禁主机ip</param> /// <param name="superPwd1">超级密码1</param> /// <param name="superPwd2">超级密码2</param> /// <param name="superPwd3">超级密码3</param> /// <param name="superPwd4">超级密码4</param> /// <returns>true:成功 false:失败</returns> public bool SetSuperPwd(string deviceIp, string superPwd1 = "FFFFFFFF", string superPwd2 = "FFFFFFFF", string superPwd3 = "FFFFFFFF", string superPwd4 = "FFFFFFFF") { CHDOperate op = GetOPByIP(deviceIp); bool b = false; if (null != op && !string.IsNullOrWhiteSpace(deviceIp)) { if (op.isLinkOn) { b = op.SetSuperPwd(superPwd1, superPwd2, superPwd3, superPwd4); return(b); } else { TextMsg?.Invoke(string.Format("门禁主机 {0} 设置超密码失败,无权限,请稍后再试···", deviceIp)); } } TextMsg?.Invoke(string.Format("门禁主机 {0} 设置超密码失败···", deviceIp)); return(b); }