Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        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();
                }
            }
        }