using MySql.Data.MySqlClient; using System; using System.IO; using System.Net; namespace FangYar.WebUI.WebCommon { /// /// Http请求工具类 /// public class HttpUtil { /// /// 访客登记审批路径 /// public static string VisitorReg = System.Configuration.ConfigurationManager.AppSettings["VisitorReg"] + ""; /// /// 访客登记授权 /// /// public static bool VisitorRegEmpower(string vid) { try { string sql = " SELECT VISIN_ID VID, EXTEND1 str1 from tbl_visitor_reg WHERE id =@id "; MySqlParameter[] parameters = { new MySqlParameter("@id", vid) }; var ds = FangYar.Common.MySqlHelper.Query(sql, parameters); var dt = ds.Tables[0]; if (dt != null) { if (dt.Rows.Count > 0) { //发送信息ID string sVid = dt.Rows[0]["VID"] + ""; // 发送数据内容 string str1 = dt.Rows[0]["str1"] + ""; string httpUrl = VisitorReg + "?id=" + sVid + "&channelCodes=" + str1 + "&result=true"; string str2 = GetPostUrl(httpUrl); return true; } } } catch (Exception ex) { } return false; } /// /// 根据网址获取数据 /// /// /// public static string GetPostUrl(string contentUrl) { try { HttpWebRequest reqContent = (HttpWebRequest)WebRequest.Create(contentUrl); reqContent.Method = "POST"; reqContent.AllowAutoRedirect = false;//服务端重定向。一般设置false reqContent.ContentType = "application/x-www-form-urlencoded";//数据一般设置这个值,除非是文件上传 HttpWebResponse respContent = (HttpWebResponse)reqContent.GetResponse(); string html = new StreamReader(respContent.GetResponseStream()).ReadToEnd(); return html; } catch (Exception ex) { return ex + ""; } } /// /// 根据网址获取数据 /// /// /// public static string GetUrl(string contentUrl) { try { HttpWebRequest reqContent = (HttpWebRequest)WebRequest.Create(contentUrl); reqContent.Method = "GET"; reqContent.AllowAutoRedirect = false;//服务端重定向。一般设置false reqContent.ContentType = "application/x-www-form-urlencoded";//数据一般设置这个值,除非是文件上传 HttpWebResponse respContent = (HttpWebResponse)reqContent.GetResponse(); string html = new StreamReader(respContent.GetResponseStream()).ReadToEnd(); return html; } catch (Exception ex) { return ex + ""; } } /// /// 获取保存在cookie里的用户对象 /// public static FangYar.Model.LoginUserModel GetUser(System.Web.HttpContext context) { try { var cook = context.Request.Cookies; var cookInfo = cook["kn_root_cookie"]; if (cookInfo != null) { var str = cookInfo.Value; //判断是否存在登录缓存信息 if (!string.IsNullOrWhiteSpace(str)) { string app = System.Configuration.ConfigurationManager.AppSettings["APP"]; var usersUid = str.Substring(str.IndexOf("\"usersUid\":\"") + 12); usersUid = usersUid.Substring(0, usersUid.IndexOf("\",")); FangYar.Model.LoginUserModel userFromCookie = new BLL.TBL.SysUsersBLL().UserLogin2(usersUid); //获取用户角色 string rolesid = FangYar.BLL.CommomBLL.GetTableIDS("rules_id", "users_uid", "TBL_SYS_USERSRULES", " where users_uid='" + usersUid + "' and app_id='" + app + "' and rules_type='2' "); userFromCookie.roles = rolesid; //获取用户权限 string rigths = FangYar.BLL.CommomBLL.GetTableIDS("PERM_VALUE", "app_id", "TBL_SYS_PERM", " where id in(select perm_id from TBL_SYS_ROLEPERM where ROLE_ID in('" + rolesid.Replace(",", "','") + "') and app_id='" + app + "' ) "); userFromCookie.rights = rigths; return userFromCookie; } } } catch (Exception ex) { return null; } return null; } } }