Esempio n. 1
0
 private static void ExpiredPushRecord(string UserID, string DeviceID, string ExpireDate, string Platform)
 {
     try
     {
         SQLServerOperating s = new SQLServerOperating(connectionString);
         var days             = (ExpireDate.toDateTime() - DateTime.Now).TotalDays;
         if (Platform == "app")
         {
             string strSql = @"IF EXISTS(select UserID from ExpiredPushRecord where DeviceID = @DeviceID)
                          update ExpiredPushRecord set AppLastPushTime = GETDATE(),Days=@Days where DeviceID = @DeviceID
                          ELSE
                          Insert into ExpiredPushRecord(UserID, DeviceID, AppLastPushTime,Days)values(@UserID, @DeviceID, GETDATE(),@Days)";
             s.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("DeviceID", DeviceID), new SqlParameter("UserID", UserID), new SqlParameter("Days", days) });
         }
         else
         {
             string strSql = @"IF EXISTS(select UserID from ExpiredPushRecord where DeviceID = @DeviceID)
                          update ExpiredPushRecord set WeChatLastPushTime = GETDATE(),Days=@Days  where DeviceID = @DeviceID
                          ELSE
                          Insert into ExpiredPushRecord(UserID,DeviceID, WeChatLastPushTime,Days)values(@UserID,@DeviceID, GETDATE(),@Days)";
             s.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("UserID", UserID), new SqlParameter("DeviceID", DeviceID), new SqlParameter("Days", days) });
         }
     }
     catch (Exception ex)
     {
         Utils.log("ExpiredPushRecord Error:" + ex.Message, log_name);
     }
 }
Esempio n. 2
0
        public bool MobileInfo(string AppID, string AppKey, string ClientID, string Token, string Model, string Vendor, string IMEI, string UUID, string IMSI, string Resolution, string DPI, string OS, string OSVersion, string UserID, string APPVersion)
        {
            try
            {
                if (string.IsNullOrEmpty(ClientID) || string.IsNullOrEmpty(Token) || string.IsNullOrEmpty(AppID) || string.IsNullOrEmpty(AppKey) || string.IsNullOrEmpty(OS))
                {
                    return(false);
                }
                if (ClientID.ToLower() == "null" || Token.ToLower() == "null" || AppID.ToLower() == "null" || AppKey.ToLower() == "null" || OS.ToLower() == "null" || ClientID.ToLower() == "(null)")
                {
                    return(false);
                }
                string             strSql = "select COUNT(*) from MobileAppInfo where ClientID=@ClientID";
                SQLServerOperating s      = new SQLServerOperating();
                SqlParameter[]     pars   = new SqlParameter[] { new SqlParameter("ClientID", ClientID) };
                string             count  = s.Select(strSql, pars);
                strSql = "select ID from apps where AppID=@AppID and AppKey=@AppKey";
                string appsid = s.Select(strSql, new SqlParameter[] { new SqlParameter("AppID", AppID), new SqlParameter("AppKey", AppKey) });
                if (Convert.ToInt32(count) > 0)
                {
                    strSql = "update MobileAppInfo set UserID=@UserID,LastDate=GETDATE(),OS=@OS,OSVersion=@OSVersion,AppsID=@AppsID,APPVersion=@APPVersion where ClientID=@ClientID";
                    pars   = new SqlParameter[] {
                        new SqlParameter("ClientID", ClientID),
                        new SqlParameter("UserID", UserID),
                        new SqlParameter("OS", OS),
                        new SqlParameter("OSVersion", OSVersion),
                        new SqlParameter("AppsID", appsid),
                        new SqlParameter("APPVersion", APPVersion)
                    };
                    s.ExecuteSql(strSql, pars);
                }
                else
                {
                    strSql = @"Insert into MobileAppInfo(UserID, ClientID, Token, Model, Vendor, IMEI, UUID, IMSI, Resolution, DPI, OS,OSVersion, Created, LastDate,AppsID,APPVersion)
                              values(@UserID, @ClientID, @Token, @Model, @Vendor, @IMEI, @UUID,@IMSI,@Resolution,@DPI, @OS,@OSVersion, GETDATE(), GETDATE(),@AppsID,@APPVersion)";

                    pars = new SqlParameter[] { new SqlParameter("ClientID", ClientID),
                                                new SqlParameter("UserID", UserID),
                                                new SqlParameter("Token", Token),
                                                new SqlParameter("Model", Model),
                                                new SqlParameter("Vendor", Vendor),
                                                new SqlParameter("IMEI", IMEI),
                                                new SqlParameter("UUID", UUID),
                                                new SqlParameter("IMSI", IMSI),
                                                new SqlParameter("Resolution", Resolution),
                                                new SqlParameter("DPI", DPI),
                                                new SqlParameter("OS", OS),
                                                new SqlParameter("OSVersion", OSVersion),
                                                new SqlParameter("AppsID", appsid),
                                                new SqlParameter("APPVersion", APPVersion) };
                    s.ExecuteSql(strSql, pars);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Utils.log("MobileInfo Error:" + ex.Message + ",StackTrace" + ex.StackTrace);
                return(false);
            }
        }
Esempio n. 3
0
 public bool AddOpenID(string OpenID, string UserID, string LoginName)
 {
     //StringBuilder sb = new StringBuilder();
     try
     {
         SQLServerOperating s      = new SQLServerOperating();
         string             strSql = "select count(-1) from WechatUsers where OpenID=@OpenID";
         string             exist  = s.Select(strSql, new SqlParameter[] { new SqlParameter("OpenID", OpenID), new SqlParameter("UserID", UserID) });
         if (Convert.ToInt32(exist) == 0)
         {
             //DataTable dt = s.Selects(" select NotificationType from ExceptionMessage group by NotificationType");
             //foreach (DataRow row in dt.Rows)
             //{
             //    sb.Append(row["NotificationType"]+",");
             //}
             //sb = sb.Length > 0 ? sb.Remove(sb.Length-1, 1) : sb;
             strSql = "insert into WechatUsers (UserID,LoginName, OpenID, CreateTime, UpdateTime,PushMsg)values(@UserID,@LoginName,@OpenID,GETDATE(),GETDATE(),@PushMsg)";
             return(s.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("UserID", UserID), new SqlParameter("OpenID", OpenID), new SqlParameter("LoginName", LoginName), new SqlParameter("PushMsg", "") }) > 0);
         }
         else
         {
             strSql = "update WechatUsers set UpdateTime=GETDATE(),UserID=@UserID,LoginName=@LoginName, Deleted=0 where OpenID=@OpenID";
             return(s.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("UserID", UserID), new SqlParameter("OpenID", OpenID), new SqlParameter("LoginName", LoginName) }) > 0);
         }
     }
     catch (Exception ex)
     {
         Utils.log("AddOpenID ERROR:" + ex.Message + ",StackTrace:" + ex.StackTrace + ",OpenID:" + OpenID + ",UserID:" + UserID + ",LoginName:" + LoginName);
         return(false);
     }
 }
Esempio n. 4
0
        public string DeleteGroups(string groupid)
        {
            try
            {
                if (groupid.Trim() == "-1" || string.IsNullOrEmpty(groupid))
                {
                    return("该分组不能删除.");
                }
                SQLServerOperating s      = new SQLServerOperating();
                string             strSql = "update Devices set GroupID=-1 where GroupID=@GroupID";
                int count = s.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("GroupID", groupid) });
                // strSql = "select count(*) from devices where groupid=@GroupID and UserID=@UserID";

                // string count = s.Select(strSql, new SqlParameter[] { new SqlParameter("GroupID", groupid), new SqlParameter("UserID", myHeader.UserID) });
                string msg = "";
                if (count > 0)
                {
                    msg = "该分组下的设备以移到默认组下.";
                }
                strSql = "delete from groups where groupid= @GroupID";
                int rows = s.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("GroupID", groupid) });
                return(rows > 0 ? Utils.GetResult("删除成功!" + msg, statusCode.Code.success) : Utils.GetResult("删除分组失败!" + msg, statusCode.Code.failure));
            }
            catch (Exception ex)
            {
                Utils.log("DeleteGroups Error:" + ex.Message);
                return(Utils.GetResult(ex.Message, statusCode.Code.failure));
            }
        }
Esempio n. 5
0
 /// <summary>
 /// 设置微信推送通知的报警类型
 /// </summary>
 /// <param name="msgType"></param>
 /// <param name="UserID"></param>
 /// <returns></returns>
 public string SetPushMsgType(string msgType)
 {
     try
     {
         string[] mt = msgType.Split(',');
         int[]    ls = new int[mt.Length];
         for (int i = 0; i < mt.Length; i++)
         {
             int t;
             if (int.TryParse(mt[i], out t))
             {
                 ls[i] = t;
             }
         }
         string             mstType = "," + string.Join(",", ls) + ",";
         string             strSql  = " update UsersConfig set PushMsgType=@PushMsgType where UserID=@UserID";
         SQLServerOperating s       = new SQLServerOperating();
         int count = s.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("PushMsgType", mstType), new SqlParameter("UserID", myHeader.UserID) });
         if (count > 0)
         {
             return(Utils.GetResult("设置成功.", statusCode.Code.success));;
         }
         else
         {
             Utils.log("SetPushMsgType 操作失败:" + strSql + ", UserID:" + myHeader.UserID + ",mstType:" + msgType);
             return(Utils.GetResult("设置失败.", statusCode.Code.failure));
         }
     }
     catch (Exception ex)
     {
         Utils.log("Message>SetPushMsgType ERROR:" + ex.Message);
         throw;
     }
 }
Esempio n. 6
0
 public string DeleteMessage(string userid, string ExceptionID)
 {
     try
     {
         if (string.IsNullOrEmpty(ExceptionID))
         {
             return(Utils.GetResult("至少选择一条报警消息.", statusCode.Code.failure));
         }
         string[]   msgid = ExceptionID.Split(',');
         List <int> ids   = new List <int>();
         for (int i = 0; i < msgid.Length; i++)
         {
             int temp;
             if (int.TryParse(msgid[i], out temp))
             {
                 ids.Add(temp);
             }
         }
         string strSql = "update ExceptionMessage set Deleted=1,ClearDate=GETDATE(),ClearBy=@UserID where ExceptionID in(" + string.Join(",", ids.ToArray()) + ")  and Deleted=0";
         if (myHeader.Identifies == "MG_XCX@AMAP")
         {
             Utils.log(strSql);
         }
         SQLServerOperating s = new SQLServerOperating();
         int count            = s.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("UserID", userid) });
         return(Utils.GetResult("清除成功" + count + "条", statusCode.Code.success));
     }
     catch (Exception ex)
     {
         Utils.log("Message>DeleteMessage ERROR:" + ex.Message);
         return(Utils.GetResult(ex.Message, statusCode.Code.error));
     }
 }
Esempio n. 7
0
 public string UpdateUsersInfoByID(string firstName, string callphone, string primaryemail, string address, string userid)
 {
     try
     {
         string             strSql = "update users set FirstName=@FirstName,Address1=@Address,CellPhone=@CellPhone,PrimaryEmail=@PrimaryEmail where deleted=0 and userid=@userid";
         SQLServerOperating s      = new SQLServerOperating();
         int status = s.ExecuteSql(strSql, new SqlParameter[] {
             new SqlParameter("FirstName", firstName), new SqlParameter("Address", address),
             new SqlParameter("CellPhone", callphone), new SqlParameter("PrimaryEmail", primaryemail),
             new SqlParameter("userid", userid)
         });
         if (status > 0)
         {
             return(Utils.GetResult("修改成功.", statusCode.Code.success));
         }
         else
         {
             return(Utils.GetResult("修改失败.", statusCode.Code.failure));
         }
     }
     catch (Exception ex)
     {
         return(Utils.GetResult(ex.Message, statusCode.Code.error));
     }
 }
Esempio n. 8
0
 public string UpdateGroups(string groupid, string groupname)
 {
     try
     {
         if (string.IsNullOrEmpty(groupid))
         {
             return(Utils.GetResult("分组ID不能为空.", statusCode.Code.failure));
         }
         if (string.IsNullOrEmpty(groupname))
         {
             return(Utils.GetResult("分组名字不能为空.", statusCode.Code.failure));
         }
         string             strSql = "update groups set GroupName=@GroupName where GroupID=@GroupID and UserID=@UserID ";
         SQLServerOperating s      = new SQLServerOperating();
         int rows = s.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("GroupName", groupname), new SqlParameter("GroupID", groupid), new SqlParameter("UserID", myHeader.UserID) });
         if (rows > 0)
         {
             return(Utils.GetResult("修改成功.", statusCode.Code.success, ""));
         }
         else
         {
             return(Utils.GetResult("修改失败", statusCode.Code.failure, ""));
         }
     }
     catch (Exception ex)
     {
         return(Utils.GetResult(ex.Message, statusCode.Code.error, ""));
     }
 }
Esempio n. 9
0
        public void UnifiedOrder(string deviceid, string tariffid, string tradetype)
        {
            int tariff_id         = int.Parse(tariffid);
            SQLServerOperating s  = new SQLServerOperating();
            DataTable          dt = s.Selects(" select ID, TariffName, Price, OldPrice, BuyCount, Type  from TariffPackages where ID=@tariff_id", new SqlParameter[] { new SqlParameter("tariff_id", tariff_id) });

            if (dt.Rows.Count <= 0)
            {
                return;
            }
            s.ExecuteSql("update TariffPackages set BuyCount=BuyCount+cast( ceiling(rand()*100) as int) where ID=@ID", new SqlParameter[] { new SqlParameter("ID", tariff_id) });
            s.Selects(" select ID, TariffName, Price, OldPrice, BuyCount, Type  from TariffPackages where ID=@tariff_id", new SqlParameter[] { new SqlParameter("tariff_id", tariff_id) });
            string total_fee   = dt.Rows[0]["Price"].toStringEmpty();
            string tariff_name = dt.Rows[0]["TariffName"].toStringEmpty();
            string device_name = s.Select("select case when DeviceName='' then SerialNumber else DeviceName end from Devices where deviceid=@deviceid", new SqlParameter[] { new SqlParameter("deviceid", deviceid) });

            if (string.IsNullOrEmpty(device_name))
            {
                return;
            }
            tariff_name = "GPS移动流量-" + device_name + " 充值" + tariff_name;
            JsApiPay jsApiPay = new JsApiPay();

            jsApiPay.user_id   = int.Parse(myHeader.UserID);
            jsApiPay.openid    = "";
            jsApiPay.total_fee = jsApiPay.user_id == 6 || jsApiPay.user_id == 7 ? new Random().Next(1, 10) : int.Parse(total_fee);
            jsApiPay.device_id = int.Parse(deviceid);
            jsApiPay.tariff_id = tariff_id;

            jsApiPay.product_body = tariff_name;
            WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();

            jsApiPay.InsertMgooOrder();
            // AddOrder(myHeader.UserID,deviceid,"",);
        }
Esempio n. 10
0
        public string UpdatePassword(string userid, string oldpwd, string newpwd)
        {
            string             strSql = "update users set Password=@newPwd where UserID=@UserID and Password=@oldPwd";
            SQLServerOperating s      = new SQLServerOperating();
            int c = s.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("UserID", userid), new SqlParameter("newPwd", newpwd), new SqlParameter("oldPwd", oldpwd) });

            if (c > 0)
            {
                return(Utils.GetResult("修改成功,下次登录请用新密码.", statusCode.Code.success));
            }
            else
            {
                return(Utils.GetResult("修改密码失败.", statusCode.Code.failure));
            }
        }
Esempio n. 11
0
        public bool MgRegister(string phone, string password, string username)
        {
            SqlParameter[] parms = new SqlParameter[] {
                new SqlParameter("@ParentID", "1391"),
                new SqlParameter("@UserName", string.IsNullOrEmpty(username) ? phone:username),
                new SqlParameter("@LoginName", phone),
                new SqlParameter("@Password", password),
                new SqlParameter("@UserType", "1"),
                new SqlParameter("@Gender", "0"),
                new SqlParameter("@TimeZone", "China Standard Time"),
                //new SqlParameter("@Address1",""),
                // new SqlParameter("@Address2",""),
                // new SqlParameter("@Country","-1"),
                // new SqlParameter("@State","-1"),
                // new SqlParameter("@HomePhone",""),
                // new SqlParameter("@WorkPhone",""),
                // new SqlParameter("@CellPhone",phone),
                //new SqlParameter("@SMSEmail",""),
                // new SqlParameter("@PrimaryEmail",""),
                // new SqlParameter("@SecondaryEmail",""),
                // new SqlParameter("@Status","-1"),
                // new SqlParameter("@UpdateTime", DateTime.Now),
                // new SqlParameter("@Created",DateTime.Now),
                // new SqlParameter("@Deleted","0"),
                //new SqlParameter("@SuperAdmin","0"),
                // new SqlParameter("@AllDeviceCount","0"),
                // new SqlParameter("@ActivationCount","0"),
                // new SqlParameter("@MoneyCount","0")
            };
            string ParentLoginName = "zzzc" + DateTime.Now.ToString("yyyyMM");
            string ParentUserName  = "******" + DateTime.Now.ToString("yyyyMM");
            string ParentPassword  = new Random().Next(100000, 999999).ToString();
            string strSql          = @"declare @UserID int 
                select @UserID = UserID from users where loginname = '" + ParentLoginName + @"' 
                if  (@UserID IS NULL)
                begin 
                   insert into Users(ParentID, UserName, LoginName, Password, UserType, Gender , TimeZone,  Country, State, Status, UpdateTime, Created, Deleted, SuperAdmin, AllDeviceCount, ActivationCount, MoneyCount) 
                   values (1391,'" + ParentUserName + "','" + ParentLoginName + "','" + ParentPassword + @"',2,0,'China Standard Time',-1,-1,-1,getdate(),getdate(),0,0,0,0,0) select @UserID = @@identity
                end
                insert into Users(ParentID, UserName, LoginName, Password, UserType, Gender , TimeZone,  Country, State, Status, UpdateTime, Created, Deleted, SuperAdmin, AllDeviceCount, ActivationCount, MoneyCount) 
	            values (@UserID,@UserName,@LoginName,@Password,@UserType,@Gender,@TimeZone,-1,-1,-1,getdate(),getdate(),0,0,0,0,0)"    ;
            //strSql = "insert into Users values(@ParentID, @UserName, @LoginName, @Password, @UserType, @Gender, @FirstName, @MiddleName, @LastName, @TimeZone, @Address1, @Address2, @Country, @State, @HomePhone, @WorkPhone, @CellPhone, @SMSEmail, @PrimaryEmail, @SecondaryEmail, @Status, @UpdateTime, @Created, @Deleted, @SuperAdmin, @AllDeviceCount, @ActivationCount, @MoneyCount)";
            SQLServerOperating s = new SQLServerOperating();
            bool success         = s.ExecuteSql(strSql, parms) > 0;

            return(success);
        }
Esempio n. 12
0
        public string SetUsersConfig(string ConfigData)
        {
            Dictionary <string, string> dic = Utils.ToDictionary(ConfigData);
            List <string> whereList         = new List <string>();
            Dictionary <string, string> par = new Dictionary <string, string>();

            if (dic.ContainsKey("audio"))
            {
                whereList.Add(" PushAudio=@PushAudio ");
                par["PushAudio"] = dic["audio"];
            }
            if (dic.ContainsKey("shock"))
            {
                whereList.Add(" PushShock=@PushShock ");
                par["PushShock"] = dic["shock"];
            }
            if (dic.ContainsKey("period"))
            {
                whereList.Add(" PushPeriod=@PushPeriod ");
                par["PushPeriod"] = dic["period"];
            }
            whereList.Add(" UpdateTime=GETDATE() ");
            string pars   = string.Join(",", whereList);
            string strSql = "update UsersConfig set " + pars + " where UserID=@UserID";

            SqlParameter[] parsList = new SqlParameter[par.Count + 1];
            parsList[0] = new SqlParameter("UserID", myHeader.UserID);
            int index = 1;

            foreach (KeyValuePair <string, string> item in par)
            {
                parsList[index] = new SqlParameter(item.Key, item.Value);
                index++;
            }
            SQLServerOperating s = new SQLServerOperating();

            if (s.ExecuteSql(strSql, parsList) > 0)
            {
                return(Utils.GetResult("设置成功.", statusCode.Code.success));
            }
            else
            {
                return(Utils.GetResult("设置失败.", statusCode.Code.failure));
            }
        }
Esempio n. 13
0
        public string AddFeedback(string question, string contact, string image1, string image2, string image3, string image4)
        {
            try
            {
                if (string.IsNullOrEmpty(image1) && string.IsNullOrEmpty(image2) && string.IsNullOrEmpty(image3) && string.IsNullOrEmpty(image4))
                {
                    return(Utils.GetResult("至少要有一张图片!", statusCode.Code.success));
                }
                image1 = Base64ToImage(image1);
                image2 = Base64ToImage(image2);
                image3 = Base64ToImage(image3);
                image4 = Base64ToImage(image4);

                string         strSql = "Insert into feedback (Content,Contact,Created,Status,Image1,Image2,Image3,Image4,Deleted) values (@Content,@Contact,@Created,@Status,@Image1,@Image2,@Image3,@Image4,@Deleted)";
                SqlParameter[] pars   = new SqlParameter[] {
                    new SqlParameter("Content", question),
                    new SqlParameter("Contact", contact),
                    new SqlParameter("Created", DateTime.Now),
                    new SqlParameter("Status", "已通知管理员"),
                    new SqlParameter("Image1", image1),
                    new SqlParameter("Image2", image2),
                    new SqlParameter("Image3", image3),
                    new SqlParameter("Image4", image4),
                    new SqlParameter("Deleted", "0")
                };
                SQLServerOperating s = new SQLServerOperating();
                int count            = s.ExecuteSql(strSql, pars);
                if (count > 0)
                {
                    return(Utils.GetResult("提交成功!", statusCode.Code.success));
                }
                else
                {
                    return(Utils.GetResult("提交失败!", statusCode.Code.failure));
                }
            }
            catch (Exception ex)
            {
                Utils.log("Feedback.cs > AddFeedback Error:" + ex.Message + ",堆栈:" + ex.StackTrace + ",源:" + ex.Source);
                return(Utils.GetResult(ex.Message, statusCode.Code.error));
            }
        }
Esempio n. 14
0
        public bool DeleteOpenID(string OpenID, string UserID)
        {
            string strSql = "update WeChatUsers set deleted = 1 where UserID = @UserID";

            // if (!string.IsNullOrEmpty(OpenID))
            //{
            strSql += " and OpenID=@OpenID  ";
            //}
            SQLServerOperating s = new SQLServerOperating();

            if (s.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("OpenID", OpenID.Split('@')[0]), new SqlParameter("UserID", UserID) }) > 0)
            {
                return(true);
            }
            else
            {
                Utils.log("DeleteOpenID 操作失败:sql:" + strSql + ";OpenID:" + OpenID + ",UserID:" + UserID);
                return(false);
            }
        }
Esempio n. 15
0
 private string SetDeviceInfo(int DeviceID, string DeviceName, string Cellphone, string Contact)
 {
     try
     {
         string             strSql    = "update devices set devicename=@devicename,cellphone=@cellphone,carusername=@carusername where Deleted=0 and DeviceID = @DeviceID";
         SQLServerOperating sqlHelper = new SQLServerOperating();
         int state = sqlHelper.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("DeviceID", DeviceID), new SqlParameter("devicename", DeviceName), new SqlParameter("cellphone", Cellphone), new SqlParameter("carusername", Contact) });
         if (state > 0)
         {
             return(Utils.GetResult("保存成功.", statusCode.Code.success));
         }
         else
         {
             return(Utils.GetResult("保存失败.", statusCode.Code.failure));
         }
     }
     catch (Exception e)
     {
         return(Utils.GetResult(e.Message, statusCode.Code.error));
     }
 }
Esempio n. 16
0
 private string DeleteFence(int DeviceID, int GeoFenceID)
 {
     try
     {
         string             strSql    = "delete from [GeoFence] where DeviceID=@DeviceID and GeofenceID=@GeofenceID;";
         SQLServerOperating sqlHelper = new SQLServerOperating();
         int state = sqlHelper.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("DeviceID", DeviceID), new SqlParameter("GeofenceID", GeoFenceID) });
         if (state > 0)
         {
             return(Utils.GetResult("围栏已关闭.", statusCode.Code.success));
         }
         else
         {
             return(Utils.GetResult("围栏关闭失败.", statusCode.Code.failure));
         }
     }
     catch (Exception ex)
     {
         return(Utils.GetResult(ex.Message, statusCode.Code.error));
     }
 }
Esempio n. 17
0
        public int MobileApps(string AppID, string AppKey, string PackageName, string OS)
        {
            try
            {
                if (string.IsNullOrEmpty(AppID) || string.IsNullOrEmpty(AppKey) || string.IsNullOrEmpty(PackageName))
                {
                    return(-1);
                }
                if (AppID == "null" || AppKey == "null")
                {
                    return(-1);
                }

                string             strSql = "select count(*) from apps where AppID=@AppID and AppKey=@AppKey";
                SQLServerOperating s      = new SQLServerOperating();
                string             count  = s.Select(strSql, new SqlParameter[] { new SqlParameter("AppID", AppID), new SqlParameter("AppKey", AppKey) });
                if (Convert.ToInt32(count) <= 0)
                {
                    strSql = @"insert into Apps(AppID,  AppKey,  PackageName, OS)
                               values(@AppID, @AppKey,@PackageName, @OS)";//AppSecret,MasterSecret,  ,@AppSecret @MasterSecret,
                    return(s.ExecuteSql(strSql, new SqlParameter[] {
                        new SqlParameter("AppID", AppID),
                        // new SqlParameter("AppSecret", AppSecret),
                        new SqlParameter("AppKey", AppKey),
                        // new SqlParameter("MasterSecret",MasterSecret),
                        new SqlParameter("PackageName", PackageName),
                        new SqlParameter("OS", OS)
                    }));
                }
                else
                {
                    return(2);
                }
            }
            catch (Exception ex)
            {
                Utils.log("MobileApps Error:" + ex.Message);
                return(-3);
            }
        }
Esempio n. 18
0
        public string Pushed(string UserID, string DeviceName, string Message, string Date, string Lat, string Lng, string Remark, string exceptionid, string DeviceID)
        {
            try
            {
                int tryIndex              = 0;
                SQLServerOperating s      = GetSQLServerOperating();
                string             strSql = "select ID, UserID,LoginName, OpenID, CreateTime, UpdateTime from WechatUsers where UserID = @UserID and Deleted=0";
                DataTable          dt     = s.Selects(strSql, new SqlParameter[] { new SqlParameter("UserID", UserID) });
                if (dt.Rows.Count > 0)
                {
                    string           _lat         = Lat;
                    string           _lng         = Lng;
                    MgoogpsWebClient mwc          = new MgoogpsWebClient();
                    string           access_token = AccessToken();
                    if (string.IsNullOrEmpty(access_token))
                    {
                        return("未获取到access_token.");
                    }
                    int    count   = 0;
                    string rulst   = "";
                    string key     = Utils.GetAmapKey();
                    string logName = "PushedMessage" + DateTime.Now.ToString("yyyyMM") + ".log";
                    if (Lat.toDouble() == -1.0 && Lng.toDouble() == -1.0)
                    {
                        Dictionary <string, string> dic = s.Selects("select OLat,OLng from lklocation where deviceid=@DeviceID", new SqlParameter[] { new SqlParameter("DeviceID", DeviceID) }).toDictionary();
                        Lat = dic["OLat"];
                        Lng = dic["OLng"];
                    }
                    Gps g = Utils.gps84_To_Gcj02(Lat, Lng, key);
                    mwc.RequestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;
                    string time = Date.toDateTime().ToString("yyyy-MM-dd HH:mm:ss");

                    //List<Task> taskList = new List<Task>();
                    // TaskFactory taskFactory = new TaskFactory();
                    // List<string> openids = new List<string>();
                    foreach (DataRow item in dt.Rows)
                    {
                        DataRow row = item;

                        //Task task = taskFactory.StartNew(() =>
                        // {
                        string openid      = row["OpenID"].toStringEmpty();
                        string pushContent = GetAlarmPushText(openid, DeviceName, Message, time, g.Address, Remark, exceptionid);
                        mwc.RequestPostData = Encoding.UTF8.GetBytes(pushContent);
                        rulst = mwc.RequestSend();
                        Dictionary <string, string> res = Utils.ToDictionary(rulst);
                        Utils.log(string.Format("{0},{1},{2},{3},{4},{5}", UserID, row["LoginName"], DeviceName, openid, time, Message), logName);
                        if (res["errcode"].Equals("0") && res["errmsg"].Equals("ok"))
                        {
                            count++;
                            continue;
                            //return Utils.GetResult("发送成功.", statusCode.Code.success);
                        }
                        else if (res["errcode"] == "40001") //获取access_token时AppSecret错误,或者access_token无效。请开发者认真比对AppSecret的正确性,或查看是否正在为恰当的公众号调用接口
                        {
                            if (tryIndex < 1)
                            {
                                Utils.SetCache("access_token", "");
                                AccessToken();
                                tryIndex++;
                                return(Pushed(UserID, DeviceName, Message, time, _lat, _lng, Remark, exceptionid, DeviceID));
                            }
                        }
                        else if (res["errcode"] == "43004") //接收者没有关注公众号
                        {
                            string sql = "delete from wechatusers where OpenID=@OpenID";
                            s.ExecuteSql(sql, new SqlParameter[] { new SqlParameter("OpenID", openid) });
                        }
                        Utils.log(string.Format("----发送失败 :{0},{1},{2},{3},{4},{5}", UserID, row["LoginName"], DeviceName, openid, time, Message), logName);
                        Utils.log("----rulst :" + rulst, logName);
                        // openids.Add(openid);
                        // return Utils.GetResult("发送失败.", statusCode.Code.failure);
                        //  });
                        //  taskList.Add(task);
                    }
                    //Task.WaitAll(taskList.ToArray());

                    if (count > 0)
                    {
                        return(Utils.GetResult("发送成功.", statusCode.Code.success));
                    }
                    else
                    {
                        return(Utils.GetResult("发送失败.", statusCode.Code.failure, rulst));
                    }
                }
                return(Utils.GetResult("该用户未绑定微信.", statusCode.Code.failure));
            }
            catch (Exception ex)
            {
                Utils.log("Pushed ERROR:" + ex.Message + ",堆栈:" + ex.StackTrace);
                throw ex;
            }
        }