This commit is contained in:
jackchenyang 2024-06-07 15:13:34 +08:00
parent 4dc89c8561
commit 25bfa4fa71
2 changed files with 26 additions and 24 deletions

View File

@ -30,12 +30,12 @@ namespace BLL.APIService
} }
public static void GetSyncUserInfo() public static void GetSyncUserInfo()
{ {
var token = GetUserToken(); //获取接口token //var token = GetUserToken(); //获取接口token
var dic = GetDepartList(); //把本地数据库中的部门全部取出作为字典 var dic = GetDepartList(); //把本地数据库中的部门全部取出作为字典
var dicUser = GetUserInfoByAccount(); //同上把所有用户取出来 var dicUser = GetUserInfoByAccount(); //同上把所有用户取出来
//string file = System.Web.HttpContext.Current.Server.MapPath("~/data.txt"); string file = System.Web.HttpContext.Current.Server.MapPath("~/data.txt");
//string result = System.IO.File.ReadAllText(file); string result = System.IO.File.ReadAllText(file);
string result = BLL.Common.HttpHelper.HttpPostRequest(GETHRINfOAPI, "", token); //string result = BLL.Common.HttpHelper.HttpPostRequest(GETHRINfOAPI, "", token);
var data = JsonHelper.DeserializeJsonToObject<ResultData<List<UserInfo>>>(result); var data = JsonHelper.DeserializeJsonToObject<ResultData<List<UserInfo>>>(result);
List<Model.SyncDataUserLogs> logList = new List<Model.SyncDataUserLogs>(); List<Model.SyncDataUserLogs> logList = new List<Model.SyncDataUserLogs>();
if (data.code == "200") if (data.code == "200")
@ -246,7 +246,7 @@ namespace BLL.APIService
/// <returns></returns> /// <returns></returns>
private static Dictionary<string,string> GetUserInfoByAccount() private static Dictionary<string,string> GetUserInfoByAccount()
{ {
return BLL.Funs.DB.Sys_User.Select(t => new { t.UserId, t.Account }).ToList() return BLL.Funs.DB.Sys_User.Where(t=>t.IsPost==true).Select(t => new { t.UserId, t.Account }).ToList()
.ToDictionary(t => t.Account.ToLower(), t => t.UserId); .ToDictionary(t => t.Account.ToLower(), t => t.UserId);
} }

View File

@ -16,20 +16,24 @@ namespace FineUIPro.Web
protected void Page_Load(object sender, EventArgs e) protected void Page_Load(object sender, EventArgs e)
{ {
this.code = Request.Params["code"]; this.code = Request.Params["code"];
if (string.IsNullOrEmpty(this.code)) BLL.ErrLogInfo.WriteLog($"获取code={this.code}");
if (!IsPostBack)
{ {
Response.Redirect("~/login.aspx"); if (string.IsNullOrEmpty(this.code))
return; {
} Response.Redirect("~/login.aspx");
var token= GetAccessToken(this.code); return;
var userInfo = getUserInfo(token); }
if (userInfo == null) var token = GetAccessToken(this.code);
{ var userInfo = getUserInfo(token);
Response.Redirect("~/login.aspx"); if (userInfo == null)
return; {
} Response.Redirect("~/login.aspx");
return;
}
Response.Redirect("~/index.aspx"); Response.Redirect("~/index.aspx");
}
} }
private AccessTokenModel GetAccessToken(string _code) private AccessTokenModel GetAccessToken(string _code)
@ -39,18 +43,18 @@ namespace FineUIPro.Web
string grant_type = "authorization_code"; string grant_type = "authorization_code";
string redirect_url = "http://localhost:6166/ssocallback.aspx"; string redirect_url = "http://localhost:6166/ssocallback.aspx";
string scope = "profile openid"; string scope = "profile openid";
string baseUrl = $" https://login.microsoftonline.com/ecaa386b-c8df-4ce0-ad01740cbdb5ba55/oauth2/v2.0/token"; string baseUrl = $"https://login.microsoftonline.com/ecaa386b-c8df-4ce0-ad01740cbdb5ba55/oauth2/v2.0/token";
try try
{ {
string postData = $"code={code}&client_id={clientId}&client_secret={clientSecret}&grant_type={grant_type}&redirect_uri={redirect_url}&scope={scope}"; string postData = $"code={code}&client_id={clientId}&client_secret={clientSecret}&grant_type={grant_type}&redirect_uri={redirect_url}&scope={scope}";
string result = BLL.Common.HttpHelper.HttpPostRequest(baseUrl, postData, string.Empty); string result = BLL.Common.HttpHelper.HttpPostRequest(baseUrl, postData, string.Empty);
BLL.ErrLogInfo.WriteLog($"参数url={postData}");
BLL.ErrLogInfo.WriteLog($"====================================");
BLL.ErrLogInfo.WriteLog($"结果Result={result}");
var Data = JsonConvert.DeserializeObject<AccessTokenModel>(result); var Data = JsonConvert.DeserializeObject<AccessTokenModel>(result);
return Data; return Data;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -67,13 +71,11 @@ namespace FineUIPro.Web
try try
{ {
var result = HttpHelper.HttpGetRequest(baseUrl, token.access_token); var result = HttpHelper.HttpGetRequest(baseUrl, token.access_token);
if (result.IndexOf("sub") > -1) if (result.IndexOf("sub") > -1)
{ {
var info = JsonConvert.DeserializeObject<UserTokenModel>(result); var info = JsonConvert.DeserializeObject<UserTokenModel>(result);
//写入session信息 //写入session信息
//写入cookie信息 Session["ossInfo"] = info;
return info; return info;
} }