Browse Source

手机端统一身份认证2.0

娄底高职分支
liangkun 1 year ago
parent
commit
de54a05a57
2 changed files with 122 additions and 6 deletions
  1. +8
    -0
      Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj
  2. +114
    -6
      Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/SSOApi.cs

+ 8
- 0
Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj View File

@@ -331,6 +331,14 @@
<Project>{88d8e99d-df26-4506-83c5-51e354818bef}</Project>
<Name>Learun.Application.WorkFlow</Name>
</ProjectReference>
<ProjectReference Include="..\Learun.Framework.Module\Learun.Cache\Learun.Cache.Base\Learun.Cache.Base.csproj">
<Project>{975F2CB8-605C-4ADD-B365-B97BF844F0FE}</Project>
<Name>Learun.Cache.Base</Name>
</ProjectReference>
<ProjectReference Include="..\Learun.Framework.Module\Learun.Cache\Learun.Cache.Factory\Learun.Cache.Factory.csproj">
<Project>{68902FCF-C439-4010-B17B-2499C972EE33}</Project>
<Name>Learun.Cache.Factory</Name>
</ProjectReference>
<ProjectReference Include="..\Learun.Framework.Module\Learun.Db\Learun.DataBase.EF.Oracle\Learun.DataBase.Oracle.csproj">
<Project>{82069f3a-ab45-4f8b-b2bf-a36b14208f41}</Project>
<Name>Learun.DataBase.Oracle</Name>


+ 114
- 6
Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/SSOApi.cs View File

@@ -11,6 +11,8 @@ using Learun.Application.OA;
using System.Configuration;
using Learun.Application.TwoDevelopment.Permission;
using System;
using Learun.Cache.Base;
using Learun.Cache.Factory;

namespace Learun.Application.WebApi.Modules
{
@@ -21,14 +23,73 @@ namespace Learun.Application.WebApi.Modules
private Perm_FunctionTypeIBLL perm_FunctionTypeIBLL = new Perm_FunctionTypeBLL();
Perm_UserPermissionIBLL permUserPermissionIbll = new Perm_UserPermissionBLL();
private Perm_FunctionVisitIBLL functionVisitIbll = new Perm_FunctionVisitBLL();
private ICache cache = CacheFactory.CaChe();

public SSOApi()
: base("/quanjiang/sso")
{
Get["/list"] = GetList;
Get["/list20"] = GetList20;
Get["/goto"] = GoTo;
Get["/goto20"] = GoToApplication;
Get["first"] = First;
Post["first"] = FirstPost;
Get["authorize"] = Authorize;
}

/// <summary>
/// 统一身份认证2.0
/// </summary>
/// <param name="_"></param>
/// <returns></returns>
public Response Authorize(dynamic _)
{
string appid = Request.Query["appid"];
string secret = Request.Query["secret"];
string appkey = Request.Query["appkey"];
if (string.IsNullOrEmpty(appid))
{
return Fail("参数:appid不能为空");
}
if (string.IsNullOrEmpty(secret))
{
return Fail("参数:secret不能为空");
}
if (string.IsNullOrEmpty(appkey))
{
return Fail("参数:appkey不能为空");
}
var application = perm_FunctionIBLL.GetPerm_FunctionEntity(appid);
if (application != null)
{
if (Util.DESEncrypt.Decrypt(application.FSecret,
ConfigurationManager.AppSettings["SSOPublicSecret"]).Equals(secret))
{
try
{
var code = DESEncrypt.Decrypt(appkey, "bjqjsso");

if (!string.IsNullOrEmpty(cache.Read<string>(code)))
{
return Success(new { useraccount = cache.Read<string>(code) });
}
else
{
return Fail("appkey已过期");
}
}
catch (Exception e)
{
return Fail("appkey错误");
}
}
else
{
return Fail("secret错误");
}
}
else
return Fail("未授权的appid");
}

private Response FirstPost(dynamic _)
@@ -43,7 +104,7 @@ namespace Learun.Application.WebApi.Modules
up.FId = ssoparam.FId;
up.UserId = ssoparam.UserId;
perm_FunctionIBLL.SaveEntityByUPId(ssoparam.UPId, up);
return Success(new{ FInterfaceUrl="/SSO/GoTo?sysid=" + DESEncrypt.Encrypt(up.FId, publickey) + "&openid=" + DESEncrypt.Encrypt(up.UserId, publickey)});
return Success(new { FInterfaceUrl = "/SSO/GoTo?sysid=" + DESEncrypt.Encrypt(up.FId, publickey) + "&openid=" + DESEncrypt.Encrypt(up.UserId, publickey) });
}
else
{
@@ -77,6 +138,39 @@ namespace Learun.Application.WebApi.Modules
public string UserId { get; set; }
public string UPUserName { get; set; }
public string UPPass { get; set; }
public string appid { get; set; }
}

public Response GoToApplication(dynamic _)
{
var userinfo = userInfo;
var ssoparam = this.GetReqData<SSOParam>();
if (userinfo != null)
{
var perm_application = perm_FunctionIBLL.GetPerm_FunctionEntity(ssoparam.appid);
if (perm_application != null)
{
//写入当前请求所登录的用户
var code = Util.CommonHelper.RndNum(9);
cache.Write(code, userinfo.account, TimeSpan.FromMinutes(10));
var url = perm_application.FInterfaceUrl;
if (url.Contains("?"))
{
url += "&appkey=" + DESEncrypt.Encrypt(code, "bjqjsso");
}
else
{
url += "?appkey=" + DESEncrypt.Encrypt(code, "bjqjsso");
}
return Success(new{ FInterfaceUrl=url });
}
else
return Fail("appid解析失败,请确认。");
}
else
{
return Fail("用户信息解析失败,请确认。");
}
}

public Response GoTo(dynamic _)
@@ -116,8 +210,9 @@ namespace Learun.Application.WebApi.Modules
functionVisitEntity.PIsLoginSuccess = true;
functionVisitEntity.PContent = "成功转到统一认证网站:" + perfun.FUrl;
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Success(new {
FInterfaceUrl=perfun.FInterfaceUrl + "?u=" +
return Success(new
{
FInterfaceUrl = perfun.FInterfaceUrl + "?u=" +
DESEncrypt.Encrypt(DESEncrypt.Encrypt(perfun.UPUserName, secretkey),
publickey) + "&p=" +
DESEncrypt.Encrypt(DESEncrypt.Encrypt(perfun.UPPass, secretkey),
@@ -125,7 +220,8 @@ namespace Learun.Application.WebApi.Modules
DESEncrypt.Encrypt(
DESEncrypt.Encrypt(DateTime.Now.ToString("yyyyMMddHHmmss"), secretkey),
publickey) + "&ip=" +
DESEncrypt.Encrypt(DESEncrypt.Encrypt(GetIP(), secretkey), publickey)});
DESEncrypt.Encrypt(DESEncrypt.Encrypt(GetIP(), secretkey), publickey)
});
}
else
{
@@ -133,7 +229,7 @@ namespace Learun.Application.WebApi.Modules
functionVisitEntity.PContent = "用户未配置转到用户名密码配置页面";
functionVisitIbll.SaveEntity(null, functionVisitEntity);
//用户未配置转到用户名密码配置页面
return Success(new{ FInterfaceUrl = "/SSO/FirstLogin?sysid=" + sysid + "&openid=" + openid});
return Success(new { FInterfaceUrl = "/SSO/FirstLogin?sysid=" + sysid + "&openid=" + openid });
}
}
else
@@ -151,7 +247,7 @@ namespace Learun.Application.WebApi.Modules
functionVisitEntity.PIsLoginSuccess = true;
functionVisitEntity.PContent = "成功转到统一认证网站:" + perfun.FUrl;
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Success(new { FInterfaceUrl=perfun.FUrl});
return Success(new { FInterfaceUrl = perfun.FUrl });
}
else
{
@@ -168,6 +264,18 @@ namespace Learun.Application.WebApi.Modules
}
}

public Response GetList20(dynamic _)
{
var userinfo = userInfo;
var functionlist = perm_FunctionIBLL.GetListByUserId(userinfo.userId).Select(m=>
new
{
m.FName,
m.FId,
});
return Success(functionlist);
}


/// <summary>
/// 获取页面显示列表数据


Loading…
Cancel
Save