public LoginUserInfo Login_Imei(string LoginName, string PassWord, string Identifies) { try { string strSql = "select DeviceID,SerialNumber, DeviceName, UserID,DevicePassword from devices where serialnumber = @serialnumber and deleted =0"; SQLServerOperating s = new SQLServerOperating(); DataTable dt = s.Selects(strSql, new SqlParameter[] { new SqlParameter("serialnumber", LoginName) }); if (dt.Rows.Count > 0) { DataRow loginUserDic = dt.Rows[0]; // 加密 //string EncryptPWD = FormsAuthentication.HashPasswordForStoringInConfigFile(loginUserDic["DevicePassword"].toStringEmpty(), "MD5"); string EncryptPWD = Utils.GetMD5(loginUserDic["DevicePassword"].toStringEmpty()); if (EncryptPWD.Equals(PassWord.ToLower())) { LoginUserInfo _loginUserInfo = new LoginUserInfo(); _loginUserInfo.DeviceID = loginUserDic["DeviceID"].toStringEmpty(); _loginUserInfo.UserID = loginUserDic["UserID"].toStringEmpty(); _loginUserInfo.UserName = loginUserDic["DeviceName"].toStringEmpty(); _loginUserInfo.DeviceName = loginUserDic["DeviceName"].toStringEmpty(); _loginUserInfo.LoginTime = DateTime.Now; _loginUserInfo.Identifies = Identifies; _loginUserInfo.LoginType = LoginType.Imei; _loginUserInfo.ToKen = Guid.NewGuid().toStringEmpty().Replace("-", "").ToLower(); if (Identifies.Split('@').Length == 2) { string mt = Identifies.Split('@')[1]; if (mt.ToUpper() == "BAIDU") { _loginUserInfo.MapType = MapType.BAIDU; } else { _loginUserInfo.MapType = MapType.AMAP; } } else { _loginUserInfo.MapType = MapType.AMAP; } return(_loginUserInfo); } } } catch (Exception ex) { Utils.log("Login_Imei Error:" + ex.Message); } return(null); }
public bool FilterMsgType(string UserID, string NotificationType) { try { string strSql = string.Format(" select PushAudio,PushShock,PushPeriod from UsersConfig where UserID=@UserID and (PushMsgType like '%,{0},%')", NotificationType); SQLServerOperating s = GetSQLServerOperating(); DataTable dt = s.Selects(strSql, new SqlParameter[] { new SqlParameter("UserID", UserID) }); if (dt.Rows.Count > 0) { string period = dt.Rows[0]["PushPeriod"].ToString(); //1 是全天接收 if (period == "1") { return(true); } var now = DateTime.Now; var date1 = default(DateTime); var date2 = default(DateTime); //晚上接收 if (period == "2") { date1 = now.ToString("yyyy-MM-dd 20:00:00").toDateTime(); date2 = now.AddDays(1).ToString("yyyy-MM-dd 07:59:59").toDateTime(); if (now >= date1 && now <= date2) { return(true); } Utils.log("免打扰时间-晚上接收: UserID:" + UserID + ",NotificationType:" + NotificationType); } //白天接收 if (period == "3") { date1 = now.ToString("yyyy-MM-dd 08:00:00").toDateTime(); date2 = now.ToString("yyyy-MM-dd 19:59:59").toDateTime(); if (now >= date1 && now <= date2) { return(true); } Utils.log("免打扰时间-白天接收: UserID:" + UserID + ",NotificationType:" + NotificationType); } return(false); } } catch (Exception ex) { Utils.log("FilterMsgType Error:" + ex.Message); } return(false); }
public Dictionary <string, string> GetMessageInfoByID(string eid) { try { SQLServerOperating s = new SQLServerOperating(); string strSql = @"select CASE when d.devicename='' then d.SerialNumber else d.DeviceName end DeviceName,dateadd(HH,8, em.created) Created,em.OLat,em.OLng , case when geo.FenceName is null then em.Message else em.Message+':'+geo.FenceName end Message from ExceptionMessage em inner join Devices d on d.DeviceID=em.DeviceID left join GeoFence geo on geo.GeofenceID=em.GeoFenceID where ExceptionID=@ExceptionID"; DataTable table = s.Selects(strSql, new SqlParameter[] { new SqlParameter("ExceptionID", eid) }); Dictionary <string, string> dic = new Dictionary <string, string>(); Geocoding geo = GetCurrentMapType(); foreach (DataRow row in table.Rows) { foreach (DataColumn dc in table.Columns) { dic[dc.ColumnName] = row[dc.ColumnName].toStringEmpty(); } } Mgoo.Position.IGeocoding geocoding = null; if (geo.GetType().Name.ToLower() == "baidu") { geocoding = new Mgoo.Position.Geocod.Baidu(); } else if (geo.GetType().Name.ToLower() == "amap") { geocoding = new Mgoo.Position.Geocod.Amap(); } else { geocoding = new Mgoo.Position.Geocod.Google(); } var point = geocoding.Translate(dic["OLat"].toDouble(), dic["OLng"].toDouble()); var task = Task.Run(() => { return(geocoding.GetAddress(point)); }); dic["OLat"] = point.Lat.ToString(); dic["OLng"] = point.Lng.ToString(); dic["Address"] = task.Result; return(dic); } catch (Exception ex) { Utils.log("Message>GetMessageInfoByID ERROR:" + ex.Message); return(new Dictionary <string, string>()); } }
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)); } }
public List <Dictionary <string, string> > GetMessageByDeviceID(int DeviceID, int second) { try { string strSql = $"select top 5 ExceptionID,DeviceID,Message,Created from [ExceptionMessage] where DeviceID=@DeviceID and created > dateadd(ss,@second,dateadd(HH,-8, getdate()))"; SQLServerOperating s = new SQLServerOperating(); SqlParameter[] par = new SqlParameter[] { new SqlParameter("DeviceID", DeviceID), new SqlParameter("second", second - second * 2) }; List <Dictionary <string, string> > list = s.Selects(strSql, par).toListDictionary(); return(list); } catch (Exception ex) { Utils.log("GetMessageByDeviceID:" + ex.Message); return(new List <Dictionary <string, string> >()); } }
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); }
public List <Dictionary <string, string> > GetMessageByDeviceID(string currentIndex, string pageCount, string deviceid, string type) { try { if (string.IsNullOrEmpty(currentIndex) || currentIndex == "undefined") { return(new List <Dictionary <string, string> >()); } if (string.IsNullOrEmpty(type)) { type = "2"; } string where = ""; if (type.Equals("0")) //查看未删除的 { where = " and ex.Deleted = 0 "; } else if (type.Equals("1")) //查看已删除的 { where = " and ex.Deleted = 1 "; } else if (type.Equals("2"))//查看全部报警信息 { } else { return(new List <Dictionary <string, string> >()); } string strSql = string.Format(@"select top {0} * from( select row_number() over(order by ex.[Created] desc) rowIndex, ex.ExceptionID, CASE when d.devicename = '' then d.SerialNumber else d.DeviceName end DeviceName, d.SerialNumber, d.DeviceID,case when geo.FenceName is null then ex.Message else ex.Message+':'+geo.FenceName end Message, dateadd(HH, 8, ex.created) Created ,ex.ClearBy,ex.ClearDate from ExceptionMessage ex inner join devices d on d.deviceid = ex.deviceid left join GeoFence geo on geo.GeofenceID=ex.GeoFenceID where d.DeviceID = @DeviceID " + where + @" ) t where rowIndex > {0} * ({1} - 1) order by Created desc", pageCount, currentIndex); SQLServerOperating s = new SQLServerOperating(); return(s.Selects(strSql, new SqlParameter[] { new SqlParameter("DeviceID", deviceid) }).toListDictionary()); } catch (Exception ex) { Utils.log("Message>GetMessageByDeviceID ERROR:" + ex.Message); return(new List <Dictionary <string, string> >()); } }
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)); } }
public Dictionary <string, string> GetUsersConfig() { Dictionary <string, string> dic = new Dictionary <string, string>(); try { string strSql = @"select ISNULL(uc.PushAudio,0) Audio,ISNULL(uc.PushShock,0) Shock,ISNULL(ShockSens,0) ShockSens ,ISNULL(PushPeriod,1) Period from users u left join UsersConfig uc on uc.UserID=u.UserID where u.userid = @userid"; SQLServerOperating s = new SQLServerOperating(); List <Dictionary <string, string> > list = s.Selects(strSql, new SqlParameter[] { new SqlParameter("userid", myHeader.UserID) }).toListDictionary(); dic = list[0]; } catch (Exception ex) { Utils.log("GetUsersConfig Error:" + ex.Message); } return(dic); }
public string GetUsersInfoByID(string userid) { Dictionary <string, string> dic = new Dictionary <string, string>(); try { if (myHeader.UserID.Equals(userid)) { string strSql = "select UserName,LoginName,FirstName,CellPhone,PrimaryEmail,Address1 [Address] from users where userid=@userid"; SQLServerOperating s = new SQLServerOperating(); dic = s.Selects(strSql, new SqlParameter[] { new SqlParameter("userid", userid) }).toDictionary(); } return(Utils.ToJson(dic)); } catch (Exception) { return(Utils.ToJson(dic)); } }
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)); } }
private string GetMessageList(string currentIndex, string pageCount, int deviceid, string type) { var list = new List <Dictionary <string, string> > (); try { if (string.IsNullOrEmpty(type)) { type = "2"; } string where = ""; if (type.Equals("0")) //查看未删除的 { where = " and e.Deleted = 0 "; } else if (type.Equals("1")) //查看已删除的 { where = " and e.Deleted = 1 "; } else if (type.Equals("2"))//查看全部报警信息 { } else { return(Utils.ToJson(list)); } string strSql = string.Format(@"select top {0} * from( select row_number() over(order by e.[Created] desc) rowIndex, e.[ExceptionID], case when geo.FenceName is null then e.Message else e.Message+':'+geo.FenceName end Message , dateadd(HH,8, e.[Created])[Created], d.DeviceName, d.SerialNumber, e.ClearDate, e.ClearBy from ExceptionMessage e inner join Devices d on e.DeviceID = d.DeviceID left join GeoFence geo on geo.GeofenceID=e.GeoFenceID where d.deleted =0 and d.DeviceID=@DeviceID " + where + @" ) t where rowIndex > {0} * ({1} - 1) order by Created desc" , pageCount, currentIndex); SQLServerOperating s = new SQLServerOperating(); return(Utils.ToJson(s.Selects(strSql, new SqlParameter[] { new SqlParameter("DeviceID", deviceid) }).toListDictionary())); } catch (Exception ex) { // Utils.log("GetMessageList Error:" + ex.Message); return(Utils.ToJson(list)); } }
public ajaxResult RetrievePassword(string phone, string password) { try { string strSql = "select COUNT(UserID) from users where deleted = 0 and loginname=@loginname"; strSql = @"if exists(select UserID from Users where deleted=0 and loginname=@loginname) begin update Users set password=@password where deleted=0 and loginname=@loginname select 1 end else select -2"; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("loginname", phone), new SqlParameter("password", password) }; ajaxResult ar = new MG_BLL.ajaxResult(); SQLServerOperating s = new SQLServerOperating(); string count = s.Select(strSql, parameter); if (count.Equals("1")) { ar.StatusCode = statusCode.Code.success; ar.Message = "密码重设成功."; ar.Result = ""; //strSql = "update Users set password=@password where loginname=@loginname"; //parameter = new SqlParameter[] { new SqlParameter("loginname", phone), new SqlParameter("password", password) }; //int status = s.ExecuteSql(strSql, parameter); //if (status > 0) //{ // return true; //} } else { ar.StatusCode = statusCode.Code.failure; ar.Message = "密码重设失败."; ar.Result = ""; } return(ar); } catch (Exception ex) { throw ex; } }
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); } }
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)); } }
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)); } }
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); } }
private string GetHistory(int deviceid, string startdate, string enddate) { var list = new List <Dictionary <string, string> >(); string speedfilter = "2"; if (string.IsNullOrEmpty(deviceid.ToString()) || string.IsNullOrEmpty(startdate) || string.IsNullOrEmpty(enddate)) { return(Utils.ToJson(list)); } if (string.IsNullOrEmpty(speedfilter)) { speedfilter = Utils.SpeedFilter.toStringEmpty(); } try { DateTime startTime = Convert.ToDateTime(startdate); DateTime endTime = Convert.ToDateTime(enddate); if (startTime >= endTime) { return(Utils.ToJson(list)); } TimeSpan ts = endTime - startTime; double days = Math.Ceiling(ts.TotalDays); //一次最多只能看5天的数据 if (days > 5) { return(Utils.ToJson(list)); } string DataBaseBefore = "YWData";// ConfigurationManager.AppSettings["DataBaseName"].ToStringEmpty(); StringBuilder strSql = new StringBuilder(); string startTimeUtc = startTime.AddHours(-8).ToString("yyyy-MM-dd HH:mm:ss"); string endTimeUtc = endTime.AddHours(-8).ToString("yyyy-MM-dd HH:mm:ss"); strSql.Append(" select DeviceTime, OLat, OLng, Speed, Course from ( "); string where = " where speed > @speedfilter and deviceid=@deviceid and DeviceUTCTime>@startTimeUtc and DeviceUTCTime<@endTimeUtc"; for (int i = 0; i < days; i++) { string DateBase = DataBaseBefore + startTime.ToString("yyyyMM"); int TableName = Convert.ToInt32(startTime.ToString("dd")); strSql.Append("select dateadd(HH,8,DeviceUTCTime)DeviceTime, OLat, OLng, Speed, Course from [" + DateBase + "].[dbo].[Location" + TableName + @"]"); strSql.Append(where); if (i != days - 1) { strSql.Append(" union all "); } startTime = startTime.AddDays(1); } strSql.Append(" )t order by DeviceTime"); SQLServerOperating s = new SQLServerOperating(); string model = s.Select("select di.DataText from Devices d inner join Dictionary di on di.DataValue=d.Model where DeviceID=@DeviceID", new SqlParameter[] { new SqlParameter("DeviceID", deviceid) }); if (model.EndsWith("W") || model.EndsWith("WD") || model.EndsWith("WF")) { speedfilter = "-1"; } SqlParameter[] pars = new SqlParameter[] { new SqlParameter("speedfilter", speedfilter), new SqlParameter("deviceid", deviceid), new SqlParameter("startTimeUtc", startTimeUtc), new SqlParameter("endTimeUtc", endTimeUtc) }; DataTable dt = s.Selects(strSql.ToString(), pars); //List<Dictionary<string, string>> list = new List<Dictionary<string, string>>(); Geocoding geo = new Amap(); foreach (DataRow row in dt.Rows) { Dictionary <string, string> dic = new Dictionary <string, string>(); foreach (DataColumn dc in dt.Columns) { dic[dc.ColumnName] = row[dc.ColumnName].toStringEmpty(); } Gps gps = geo.Translate(dic["OLat"], dic["OLng"], false); var listWhere = list.Where(l => l.ContainsValue(gps.getWgLat().ToString()) && l.ContainsValue(gps.getWgLon().ToString())); if (listWhere.Count() > 0) { continue; } dic["OLat"] = gps.getWgLat().toStringEmpty(); dic["OLng"] = gps.getWgLon().toStringEmpty(); list.Add(dic); } return(Utils.ToJson(list)); } catch (Exception ex) { Utils.log("GetHistoryLocus Error2:" + ex.Message + ",堆栈信息:" + ex.StackTrace + "," + deviceid + "-" + startdate + "-" + enddate); return(Utils.ToJson(list)); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { userid = Request.QueryString["userid"]; total_fee = Request.QueryString["total_fee"]; deviceid = Request.QueryString["deviceid"]; string openid = Request.QueryString["openid"]; type = Request.QueryString["type"]; imei = Request.QueryString["imei"]; string tid = Request.QueryString["tariff_id"]; if (type == "1") { tid = "7"; userid = "7"; total_fee = "1"; } else { type = "2"; } //检测是否给当前页面传递了相关参数string.IsNullOrEmpty(openid) || if (string.IsNullOrEmpty(total_fee) || string.IsNullOrEmpty(deviceid) || string.IsNullOrEmpty(tid) || string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(userid)) { state = "页面传参出错,请返回重试"; //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>"); Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit..."); //submit.Visible = false; return; } int tariff_id = int.Parse(tid); 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) }); string strSql = @"update TariffPackages set BuyCount=BuyCount+cast( ceiling(rand()*100) as int) where ID=@tariff_id; select ID, TariffName, Price, OldPrice, BuyCount, Type, (select case when DeviceName='' then SerialNumber else DeviceName end from Devices where deviceid=@deviceid) DeviceName from TariffPackages where ID=@tariff_id "; DataTable dt = s.Selects(strSql, new SqlParameter[] { new SqlParameter("tariff_id", tariff_id), new SqlParameter("deviceid", deviceid) }); if (dt.Rows.Count <= 0) { state = "页面传参出错,请返回重试"; return; } //s.ExecuteSql("update TariffPackages set BuyCount=BuyCount+cast( ceiling(rand()*100) as int) where ID=@ID", new SqlParameter[] { new SqlParameter("ID", tariff_id) }); total_fee = dt.Rows[0]["Price"].toStringEmpty(); tariff_name = dt.Rows[0]["TariffName"].toStringEmpty(); device_name = dt.Rows[0]["DeviceName"].toStringEmpty(); // s.Select("", new SqlParameter[] { new SqlParameter("deviceid", deviceid) }); if (string.IsNullOrEmpty(device_name)) { return; } tariff_name = "GPS移动流量-" + device_name + " 充值" + tariff_name; //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(this); //JSAPI支付预处理 try { // total_fee = ( type == "1" ? int.Parse(total_fee) :int.Parse( total_fee) )+""; jsApiPay.user_id = int.Parse(userid); jsApiPay.openid = openid; jsApiPay.total_fee = jsApiPay.user_id == 6 || jsApiPay.user_id == 7 ? new Random().Next(1, 10) : Convert.ToInt32(total_fee); jsApiPay.device_id = int.Parse(deviceid); jsApiPay.tariff_id = tariff_id; jsApiPay.product_body = tariff_name; jsApiPay.device_name = device_name; WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 jsApiPay.InsertMgooOrder(); //下单成功后的内部订单号 order_no = jsApiPay.order_no; callback_url = "http://m.mgoogps.com:8070/pay/pay_success.aspx?no=" + order_no.ToString() + "&deviceid=" + deviceid + "&t=" + DateTime.Now.Ticks; Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 // Response.Write("<span style='color:#00CD00;font-size:20px' id='payRes'>订单详情:</span><br/>"); // Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>"); } catch (System.Net.WebException ex) { //state = ex.Message; state = "网络繁忙,请稍后再试!"; } catch (Exception ex) { state = "下单失败,请稍后再试!"; //state = ex.Message; Utils.log("下单失败:userid:" + userid + ",deviceid:" + deviceid + ",total_fee:" + Convert.ToInt32(total_fee) + ",openid:" + openid + ",tariff_id:" + tariff_id + ",tariff_name:" + tariff_name + ",device_name:" + device_name + ",type:" + type); //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>"); // submit.Visible = false; } } }
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; } }
public WeixinOper(SQLServerOperating s) { setWx_Info(); sqlserver_oper = s; }
public void SendMail(string OrderNo, string mailTitle = null) { System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); msg.To.Add("*****@*****.**"); // 张飞鸿 msg.To.Add("*****@*****.**"); //罗坤 msg.To.Add("*****@*****.**"); //谢春丽 // msg.To.Add("*****@*****.**"); //阿成 try { SQLServerOperating s = new SQLServerOperating(); string strSql = @"select u.UserName, d.DeviceID,d.DeviceName,d.SerialNumber,o.OrderNo,o.ProductBody,o.PayDate,o.TradeType,d.PhoneNum ,d.HireExpireDate,cast(CONVERT(int, o.TotalFee)/100.0 as numeric(6,2)) TotalFee ,tp.TariffName from orders o inner join Devices d on d.DeviceID=o.DeviceID inner join Users u on u.UserID=o.UserID inner join TariffPackages tp on tp.ID=o.TariffID where o.Status = @Status and o.OrderNo = @OrderNo"; DataTable dt = s.Selects(strSql, new SqlParameter[] { new SqlParameter("OrderNo", OrderNo), new SqlParameter("Status", OrderStatus.已付款) }); DataRow row = dt.Rows[0]; msg.From = new MailAddress("*****@*****.**", "美谷充值", System.Text.Encoding.UTF8); /* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/ if (string.IsNullOrEmpty(mailTitle)) { mailTitle = "设备充值成功"; } msg.Subject = mailTitle; // "设备充值成功";//邮件标题 msg.SubjectEncoding = System.Text.Encoding.UTF8; //邮件标题编码 StringBuilder sbBody = new StringBuilder(); sbBody.Append("用户名称:" + row["UserName"] + " <br />"); sbBody.Append("充值设备IMEI:" + row["SerialNumber"] + " <br />"); sbBody.Append("充值设备名称:" + row["DeviceName"] + " <br />"); sbBody.Append("订单号:" + row["OrderNo"] + " <br />"); sbBody.Append("充值套餐:" + row["TariffName"] + " <br />"); sbBody.Append("充值金额:" + row["TotalFee"] + " <br />"); sbBody.Append("下次到期时间:" + row["HireExpireDate"] + " <br />"); sbBody.Append("交易时间:" + row["PayDate"] + " <br />"); sbBody.Append("流量卡号:" + row["PhoneNum"] + " <br />"); sbBody.Append("请尽快给该设备充值流量!"); msg.Body = sbBody.ToString(); //邮件内容 msg.BodyEncoding = System.Text.Encoding.UTF8; //邮件内容编码 msg.Priority = MailPriority.High; //邮件优先级 msg.IsBodyHtml = true; //是否是HTML邮件 SmtpClient client = new SmtpClient(); client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "mgoo123"); //登录密码 86768770 client.Host = "smtp.163.com"; client.Port = 25; //启用ssl,也就是安全发送 client.EnableSsl = true; object userState = msg; try { //client.SendAsync(msg, userState); client.Send(msg); //简单一点儿可以client.Send(msg); Utils.log("邮件发送成功:订单号:" + OrderNo); } catch (System.Net.Mail.SmtpException ex) { Console.WriteLine(ex.Message); Utils.log("SendMailUseZj1 Error:" + ex.Message + ",body:" + sbBody.ToString() + ",副标题:" + msg.Subject); throw ex; } } catch (Exception ex) { Utils.log("SendMailUseZj2 Error:" + ex.Message + ",发送邮件失败。。。 订单号:" + OrderNo, "PaySuccessEmailFailure.log"); } }
public LoginUserInfo SystemLogin_Bll(string loginName, string passWord, string identifies, string loginType) { try { string strSql = "select UserName,UserID,LoginName,UserType,SuperAdmin,PassWord from users where Deleted=0 and LoginName=@LoginName"; SqlParameter[] parameter = new SqlParameter [] { new SqlParameter("LoginName", loginName) }; SQLServerOperating s = new SQLServerOperating(); DataTable dt = s.Selects(strSql, parameter); if (dt.Rows.Count <= 0) { return(null); } else { DataRow loginUserDic = dt.Rows[0]; // 加密 //string EncryptPWD = FormsAuthentication.HashPasswordForStoringInConfigFile(loginUserDic["PassWord"].toStringEmpty(), "MD5"); string EncryptPWD = Utils.GetMD5(loginUserDic["PassWord"].toStringEmpty()); // = BitConverter.ToString(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes())).Replace("-", "").ToUpper(); if (EncryptPWD.Equals(passWord.ToLower())) { LoginUserInfo _loginUserInfo = new LoginUserInfo(); _loginUserInfo.UserID = loginUserDic["UserID"].toStringEmpty(); _loginUserInfo.UserName = loginUserDic["UserName"].toStringEmpty(); _loginUserInfo.LoginName = loginUserDic["LoginName"].toStringEmpty(); _loginUserInfo.UserType = loginUserDic["UserType"].toStringEmpty(); _loginUserInfo.SuperAdmin = loginUserDic["SuperAdmin"].toStringEmpty(); _loginUserInfo.LoginTime = DateTime.Now; _loginUserInfo.LoginType = LoginType.User; _loginUserInfo.ToKen = Guid.NewGuid().ToString().Replace("-", "").ToLower(); _loginUserInfo.Identifies = identifies; if (identifies.Split('@').Length == 2) { string mt = identifies.Split('@')[1]; if (mt.ToUpper() == "BAIDU") { _loginUserInfo.MapType = MapType.BAIDU; } else { _loginUserInfo.MapType = MapType.AMAP; } } else { _loginUserInfo.MapType = MapType.AMAP; } //string ip = Utils.GetIP(); //HttpRuntime.Cache.Insert("ip_"+_loginUserInfo.ToKen, ip, null, DateTime.Now.AddMinutes(20), TimeSpan.Zero); //SessionOper.SetSession(_loginUserInfo, SessionOper.SessionName); return(_loginUserInfo); } return(null); } } catch (Exception ex) { Utils.log("登录出错:" + loginName + "," + passWord + " --异常信息:" + ex.Message + ",堆栈信息:" + ex.StackTrace); return(null); } }