/// <summary> /// 根据用户ID判断该用户是否在含短信通知功能用户账号体系下的 /// </summary> /// <param name="UserID"></param> /// <returns></returns> public static bool IsSMSNotice(string UserID) { //var ids = System.Configuration.ConfigurationManager.AppSettings["SMSNotice"].ToString(); //if (string.IsNullOrEmpty(ids)) //{ // return false; //} // UserID 是4927 的表示 该用户下的账号有 报警短信通知功能 string strSql = "with temp(UserID,ParentID) as" + "( select UserID, ParentID from Users where UserID = " + lib.Config.SMSNoticeUserID + "union all select Users.UserID, Users.ParentID from Users, temp where Users.ParentID = temp.UserID and users.Deleted = 0" + ")select UserID from temp where UserID= " + UserID; MG_DAL.SQLServerOperating s = new MG_DAL.SQLServerOperating(); DataTable dt = s.Selects(strSql); if (dt.Rows.Count <= 0) { return(false); } //List<Dictionary<string, string>> listDic = s.Selects(strSql).toListDictionary(); ////目前只有澳博旗下所有用户 才会 发送 报警短信通知 3437 澳博美谷 总账号的UserID 870是xietong //if (listDic.Where(l => l.ContainsValue(UserID)).Count() <= 0) // //{ // return false; //} return(true); }
private void GetDeviceTracking(int DeviceID) { MG_DAL.SQLServerOperating sqlHelper = new MG_DAL.SQLServerOperating(); string strSql = "select d.DeviceID,d.SerialNumber,DeviceName,l.OLat,l.OLng,l.LastCommunication DeviceDate,l.Speed,l.Course,l.DataContext from devices d inner join LKLocation l on l.DeviceID=d.DeviceiD where d.DeviceID =@DeviceID and d.deleted=0";// model=213 and dic = sqlHelper.Selects(strSql, new SqlParameter[] { new SqlParameter("DeviceID", DeviceID) }).toDictionary(); Geocoding geo = new Amap(); Gps gps = geo.Translate(dic["OLat"], dic["OLng"]); //Gps gps = Utils.gps84_To_Gcj02(dic["OLat"], dic["OLng"]); dic["OLat"] = gps.getWgLat().ToString(); dic["OLng"] = gps.getWgLon().ToString(); dic["Address"] = gps.Address; dic["CourseName"] = Utils.GetCoureName(dic["Course"]); var dc = dic["DataContext"]; var doorStatus = "未知"; if (dc.Split('-').Length > 3 && !string.IsNullOrEmpty(dc.Split('-')[3])) { dc = dc.Split('-')[3]; if (dc.Equals("0")) { doorStatus = "打开"; } else { doorStatus = "关闭"; } } dic["DataContext"] = doorStatus;// = dic["DataContext"].Split('-')[3]; //0--- 主电断开, 1-----主电连接 Response.Write(Utils.ToJson(dic)); Response.End(); }
public void SMSX30B(string SerialNumber, string DeviceName, string Date, string Phone) { if (string.IsNullOrEmpty(Phone)) { return; } string[] phones = Phone.Split(',', ','); if (phones.Length > 0) { Phone = string.Join(",", phones); } MG_DAL.SQLServerOperating sqlHelper = new MG_DAL.SQLServerOperating(); string strSql = @" select count(*) from[dbo].[CarCommandQueue] where deviceid = '" + SerialNumber + "' and datediff(mi, ResponseDate, getdate()) <= 1"; string res = sqlHelper.Select(strSql); string state = ""; if (Convert.ToInt32(res) > 0) { } else { strSql = @" insert into CarCommandQueue ( DeviceID, CommandText, CreateDate, IsSend, SendDate, IsResponse, ResponseDate, ResponseText, CommandName, IsOfflineSend, Infos, SendCount) values('" + SerialNumber + "', 'KM', getdate(), 0, getdate(), 1, getdate() , 'Success!', '物理开锁', 0, '', 0) "; state = "非法"; sqlHelper.ExecuteSql(strSql); } string content = string.Format("【美谷科技】尊敬的用户,你好。{0}在{1}发生了一次{2}开箱行为,如是本人操作,请忽略此短信。", DeviceName, Date, state); SendSMS(Phone, content); }
protected void Page_Load(object sender, EventArgs e) { string deviceid = Request.QueryString["deviceid"]; open_id = Request.QueryString["openid"]; // imei = Request.QueryString["imei"]; if (!string.IsNullOrEmpty(deviceid) && !string.IsNullOrEmpty(open_id)) { try { device_id = Convert.ToInt32(deviceid); MG_DAL.SQLServerOperating s = new MG_DAL.SQLServerOperating(); string strSql = @"select DeviceID,SerialNumber,DeviceName,PhoneNum,ActiveDate,HireExpireDate,u.UserID,u.UserName,di.DataText,cast((datediff(DAY,ActiveDate,GETDATE()) + 0.1)/(datediff(DAY,ActiveDate,HireExpireDate)+0.1) as numeric(10,2)) as UseSituation, datediff(MM,GETDATE(),HireExpireDate) TheRest, (select count(*) from devices where Deleted=0 and UserID=d.UserID) DeviceCount, (select count(*) from devices where Deleted=0 and UserID=d.UserID and HireExpireDate > GETDATE() and HireExpireDate <= DATEADD(MM,1,GETDATE())) ExpireCount from devices d inner join Users u on u.UserID=d.UserID inner join dictionary di on di.DataValue = d.Model where d.Deleted=0 and DeviceID=@DeviceID"; DataTable dt = s.Selects(strSql, new SqlParameter[] { new SqlParameter("DeviceID", device_id) }); //X11 8 50 开头的 都是60一年,其他都是120一年 60 100 130 120 200 250 if (dt.Rows.Count <= 0) { return; } DataRow DeviceInfo = dt.Rows[0]; var expire = Convert.ToDateTime(DeviceInfo["HireExpireDate"].ToString()); expire_date = expire.ToString("yyyy-MM-dd"); if (expire < DateTime.Now) { use_situation = 100; } else { use_situation = Convert.ToInt32(Convert.ToDouble(DeviceInfo["UseSituation"].ToString()) * 100); } user_name = DeviceInfo["UserName"].ToString(); imei = DeviceInfo["SerialNumber"].ToString(); device_count = DeviceInfo["DeviceCount"].ToString(); expire_count = DeviceInfo["ExpireCount"].ToString(); device_name = string.IsNullOrEmpty(DeviceInfo["DeviceName"].ToString()) ? DeviceInfo["SerialNumber"].ToString() : DeviceInfo["DeviceName"].ToString(); user_id = Convert.ToInt32(DeviceInfo["UserID"].ToString()); int.TryParse(DeviceInfo["TheRest"].ToString(), out the_rest); the_rest = the_rest - 1; if (the_rest < 0) { the_rest = 0; } MG_BLL.Pay.MgooOrders.Orders o = new MG_BLL.Pay.MgooOrders.Orders(); PriceList = o.GetPriceList(DeviceInfo["DataText"].ToString()); } catch (Exception) { } } }
public void SMSNotice(string UserID, string UserName, string phone, string DeviceName, string MessageDate, string MessageType) { try { if (string.IsNullOrEmpty(phone)) { //return; } string[] phones = phone.Split(',', ','); if (phones.Length > 0) { phone = string.Join(",", phones); } bool isTestAccunt = Common.lib.Permission.IsSMSNotice(UserID); if (!isTestAccunt) { return; } if (isTestAccunt) { //string strSql = "select CellPhone from users where userid=3437"; string strSql = "with temp(UserID,ParentID,CellPhone) as " + "(select UserID, ParentID,CellPhone from Users where UserID = " + UserID + "union all select Users.UserID, Users.ParentID,Users.CellPhone from Users, temp where Users.UserID = temp.ParentID and users.Deleted = 0" + ")select CellPhone from temp where ParentID = " + lib.Config.SMSNoticeUserID; MG_DAL.SQLServerOperating s = new MG_DAL.SQLServerOperating(); string bigUserPhone = s.Select(strSql); if (!string.IsNullOrEmpty(bigUserPhone)) { phone = string.IsNullOrEmpty(phone) ? bigUserPhone : phone + "," + bigUserPhone; } } string smsContent = string.Format("【美谷科技】用户{0}的设备{1},在{2}触发了{3},请留意。", UserName, DeviceName, MessageDate.toDateTime().ToString("yyyy-MM-dd HH:mm:ss"), MessageType); SendSMS(phone, smsContent); } catch (Exception ex) { Utils.log("MiaodiYun>SMSNotice Error:" + ex.Message); //return ex.Message;0 } }
private void SendUnlockCommand() { var DeviceID = int.Parse(Request.Form["DeviceID"]); var SerialNumber = Request.Form["SerialNumber"]; var Password = Request.Form["Password"]; var status = "3"; // if (DeviceID == 75539) // { // DeviceID = 74324; // } if (!string.IsNullOrEmpty(Password) && !string.IsNullOrEmpty(SerialNumber) && DeviceID > 0 && Password.Length > 0 && Password.Length < 10) { string strSql = "select DevicePassword from devices where deviceid=@DeviceID and deleted=0"; MG_DAL.SQLServerOperating sqlHelper = new MG_DAL.SQLServerOperating(); string devicePassword = sqlHelper.Select(strSql, new SqlParameter[] { new SqlParameter("DeviceID", DeviceID) }); if (devicePassword.Equals(Password)) { status = Utils.SendTcpCmd("VTR-Command-" + SerialNumber + "-KM"); // status = Utils.SendTcpCmd("VTR-Command-" + SerialNumber + "-DY"); // if (status .Equals("1")) //{ //Task.Run(() => { // System.Threading.Thread.Sleep(3000); // var cmdRes = Utils.SendTcpCmd("VTR-Command-" + SerialNumber + "-TY"); // while (cmdRes!= "1") // { // System.Threading.Thread.Sleep(3000); // cmdRes = Utils.SendTcpCmd("VTR-Command-" + SerialNumber + "-TY"); // } //}); // } } else { status = "2"; } } Response.Redirect("Unlock.aspx?DeviceID=" + DeviceID + "&status=" + status); }
public string SendCommand(string deviceid) { try { MG_DAL.SQLServerOperating s = new MG_DAL.SQLServerOperating(); string imei = s.Selects("select SerialNumber from devices where deviceid=@deviceid and Deleted=0", new SqlParameter[] { new SqlParameter("deviceid", deviceid) }).Rows[0]["SerialNumber"].toStringEmpty(); string cmd = "VTR-SCommand-" + imei + "-TY"; string res = Utils.SendTcpCmd(cmd); Utils.log(" MG_BLL.DeviceManager.SendCommand:" + cmd + "," + res); if (res == "1") { return("success"); } { return("error"); } } catch (Exception e) { Utils.log("MG_BLL.DeviceManager.SendCommand Error:" + e.Message + "-" + e.StackTrace + "-" + e.Source); return("error"); } }
public static string SendTcpCmd(string cmd, string ServerID = null) { Socket clientSocket = null; try { string sid = "1"; if (string.IsNullOrEmpty(ServerID)) { string imeiOrDeviceID = cmd.Split('-')[2]; //IMEI号 或者 DeviceID if (string.IsNullOrEmpty(imeiOrDeviceID)) { sid = "1"; Utils.log("SendTcpCmd Error: cmd:" + cmd); } else { string strSql = " select dc.cmdid from devices d inner join devicesconfig dc on dc.deviceid=d.deviceid where d.deleted=0 and ( d.SerialNumber='" + imeiOrDeviceID + "' or d.DeviceID=" + imeiOrDeviceID + ")"; MG_DAL.SQLServerOperating s = new MG_DAL.SQLServerOperating(); sid = s.Select(strSql); } } else { sid = ServerID; } string configName = "tcpIP" + sid; int port = Convert.ToInt32(ConfigurationManager.AppSettings["tcpPort"]); // 7700; string host = ConfigurationManager.AppSettings[configName].ToString(); //"120.24.78.26";//服务器端ip地址 IPAddress ip = IPAddress.Parse(host); IPEndPoint ipe = new IPEndPoint(ip, port); clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); clientSocket.SendTimeout = 3000; clientSocket.Connect(ipe); //send message byte[] sendBytes = Encoding.ASCII.GetBytes(cmd); clientSocket.BeginSend(sendBytes, 0, sendBytes.Length, SocketFlags.None, null, null); //receive message string recStr = ""; byte[] recBytes = new byte[2]; int bytes = clientSocket.Receive(recBytes, recBytes.Length, 0); recStr += Encoding.ASCII.GetString(recBytes, 0, bytes); Log.Info(new Utils(), cmd + ":" + host, recStr); return(recStr); } catch (Exception ex) { Common.Log.Error("SendTcpCmd Error", ex); // Utils.log("SendTcpCmd Error:"+ex.Message+ ","+ cmd); return("0"); } finally { if (clientSocket != null) { clientSocket.Close(); } } }