You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
5.3 KiB
151 lines
5.3 KiB
using MySql.Data.MySqlClient;
|
|
using System;
|
|
using System.IO;
|
|
using System.Net;
|
|
|
|
namespace FangYar.WebUI.WebCommon
|
|
{
|
|
/// <summary>
|
|
/// Http请求工具类
|
|
/// </summary>
|
|
public class HttpUtil
|
|
{
|
|
/// <summary>
|
|
/// 访客登记审批路径
|
|
/// </summary>
|
|
public static string VisitorReg = System.Configuration.ConfigurationManager.AppSettings["VisitorReg"] + "";
|
|
|
|
/// <summary>
|
|
/// 访客登记授权
|
|
/// </summary>
|
|
/// <param name="vid"></param>
|
|
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;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 根据网址获取数据
|
|
/// </summary>
|
|
/// <param name="contentUrl"></param>
|
|
/// <returns></returns>
|
|
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 + "";
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 根据网址获取数据
|
|
/// </summary>
|
|
/// <param name="contentUrl"></param>
|
|
/// <returns></returns>
|
|
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 + "";
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取保存在cookie里的用户对象
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|