瀏覽代碼

增加手机端统一身份认证sso api

北屯中职分支
liangkun 1 年之前
父節點
當前提交
cc9f0a412c
共有 6 個檔案被更改,包括 288 行新增1 行删除
  1. +6
    -0
      Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj
  2. +217
    -0
      Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/SSOApi.cs
  3. +19
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionBLL.cs
  4. +3
    -1
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionIBLL.cs
  5. +39
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionService.cs
  6. +4
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_FunctionType/Perm_FunctionTypeEntity.cs

+ 6
- 0
Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj 查看文件

@@ -190,6 +190,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Bootstraper.cs" />
<Compile Include="Modules\SSOApi.cs" />
<Compile Include="Modules\StuEnrollOfficialApi.cs" />
<Compile Include="Modules\AnnexesNoLoginApi.cs" />
<Compile Include="Modules\AssetManagementSystem\Ass_AssetsInfoItemApi.cs" />
<Compile Include="Modules\AttendanceApi.cs" />
<Compile Include="Modules\EnrollTemplateApi.cs" />
<Compile Include="Modules\AnnexesApiWx.cs" />
<Compile Include="Modules\BaseNoLoginApi.cs" />
<Compile Include="Modules\ArrangeLessonTermAttemperApi.cs" />


+ 217
- 0
Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/SSOApi.cs 查看文件

@@ -0,0 +1,217 @@
using Learun.Application.AppMagager;
using Learun.Util;
using Nancy;
using System.Collections.Generic;
using System.Linq;
using Learun.Application.Base.SystemModule;
using Learun.Application.TwoDevelopment.LR_Desktop;
using System.Text;
using System.Data;
using Learun.Application.OA;
using System.Configuration;
using Learun.Application.TwoDevelopment.Permission;
using System;

namespace Learun.Application.WebApi.Modules
{

public class SSOApi : BaseApi
{
private Perm_FunctionIBLL perm_FunctionIBLL = new Perm_FunctionBLL();
private Perm_FunctionTypeIBLL perm_FunctionTypeIBLL = new Perm_FunctionTypeBLL();
Perm_UserPermissionIBLL permUserPermissionIbll = new Perm_UserPermissionBLL();
private Perm_FunctionVisitIBLL functionVisitIbll = new Perm_FunctionVisitBLL();

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

private Response FirstPost(dynamic _)
{
string publickey = ConfigurationManager.AppSettings["SSOPublicSecret"];
var ssoparam = this.GetReqData<SSOParam>();
if (!string.IsNullOrEmpty(ssoparam.UPId))
{
Perm_FunctionEntity up = new Perm_FunctionEntity();
up.UPUserName = ssoparam.UPUserName;
up.UPPass = ssoparam.UPPass;
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)});
}
else
{
return Fail("参数错误");
}
}

private Response First(dynamic _)
{
string publickey = ConfigurationManager.AppSettings["SSOPublicSecret"];
var ssoparam = this.GetReqData<SSOParam>();
string sysid = ssoparam.sysid;
string strsysid = DESEncrypt.Decrypt(sysid, publickey);
string openid = ssoparam.openid;
string userid = DESEncrypt.Decrypt(openid, publickey);
var uplist = permUserPermissionIbll.GetPerm_UserPermissionEntityByFIdAndUid(strsysid, userid);
if (uplist == null)
{
return Fail("用户未授权。");
}
var perfun = perm_FunctionIBLL.GetPerm_FunctionEntityByUPId(uplist.UPId);
return Success(perfun);
}

public class SSOParam
{
public string sysid { get; set; }
public string openid { get; set; }
public string UPId { get; set; }
public string FId { get; set; }
public string UserId { get; set; }
public string UPUserName { get; set; }
public string UPPass { get; set; }
}

public Response GoTo(dynamic _)
{
try
{
var ssoparam = this.GetReqData<SSOParam>();
string publickey = ConfigurationManager.AppSettings["SSOPublicSecret"];
string sysid = ssoparam.sysid;
string strsysid = DESEncrypt.Decrypt(sysid, publickey);
string openid = ssoparam.openid;
string userid = DESEncrypt.Decrypt(openid, publickey);
var uplist = permUserPermissionIbll.GetPerm_UserPermissionEntityByFIdAndUid(strsysid, userid);
Perm_FunctionVisitEntity functionVisitEntity = new Perm_FunctionVisitEntity();
functionVisitEntity.Create();
functionVisitEntity.Fid = strsysid;
functionVisitEntity.PDate = DateTime.Now;
functionVisitEntity.PUId = userid;
var userinfo = userInfo;
functionVisitEntity.PUName = userinfo.realName;
if (uplist == null)
{
functionVisitEntity.PIsLoginSuccess = false;
functionVisitEntity.PContent = "用户未授权";
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Fail("用户未授权。");
}

var perfun = perm_FunctionIBLL.GetPerm_FunctionEntityByUPId(uplist.UPId);
string secretkey = DESEncrypt.Decrypt(perfun.FSecret, publickey);
if (perfun.FIsManagePage == true)
{
if (!string.IsNullOrEmpty(perfun.FInterfaceUrl))
{
if (!string.IsNullOrEmpty(perfun.UPUserName) && !string.IsNullOrEmpty(perfun.UPPass))
{
functionVisitEntity.PIsLoginSuccess = true;
functionVisitEntity.PContent = "成功转到统一认证网站:" + perfun.FUrl;
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Success(new {
FInterfaceUrl=perfun.FInterfaceUrl + "?u=" +
DESEncrypt.Encrypt(DESEncrypt.Encrypt(perfun.UPUserName, secretkey),
publickey) + "&p=" +
DESEncrypt.Encrypt(DESEncrypt.Encrypt(perfun.UPPass, secretkey),
publickey) + "&t=" +
DESEncrypt.Encrypt(
DESEncrypt.Encrypt(DateTime.Now.ToString("yyyyMMddHHmmss"), secretkey),
publickey) + "&ip=" +
DESEncrypt.Encrypt(DESEncrypt.Encrypt(GetIP(), secretkey), publickey)});
}
else
{
functionVisitEntity.PIsLoginSuccess = false;
functionVisitEntity.PContent = "用户未配置转到用户名密码配置页面";
functionVisitIbll.SaveEntity(null, functionVisitEntity);
//用户未配置转到用户名密码配置页面
return Success(new{ FInterfaceUrl = "/SSO/FirstLogin?sysid=" + sysid + "&openid=" + openid});
}
}
else
{
functionVisitEntity.PIsLoginSuccess = false;
functionVisitEntity.PContent = "未配置登录接口地址";
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Fail("未配置登录接口地址。");
}
}
else
{
if (!string.IsNullOrEmpty(perfun.FUrl))
{
functionVisitEntity.PIsLoginSuccess = true;
functionVisitEntity.PContent = "成功转到统一认证网站:" + perfun.FUrl;
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Success(new { FInterfaceUrl=perfun.FUrl});
}
else
{
functionVisitEntity.PIsLoginSuccess = false;
functionVisitEntity.PContent = "未配置地址";
functionVisitIbll.SaveEntity(null, functionVisitEntity);
return Fail("未配置地址。");
}
}
}
catch (Exception e)
{
return Fail("参数错误。");
}
}


/// <summary>
/// 获取页面显示列表数据
/// <summary>
/// <param name="_"></param>
/// <returns></returns>
public Response GetList(dynamic _)
{
string publickey = ConfigurationManager.AppSettings["SSOPublicSecret"];
var logininfo = userInfo;
var datatype = perm_FunctionTypeIBLL.GetListByUserId(userInfo.userId);
foreach (var typeEntity in datatype)
{
var datafunction = perm_FunctionIBLL.GetListByFTId(typeEntity.FTId, userInfo.userId);
foreach (var item in datafunction)
{
if (item.FIsManagePage == true)
{
item.FInterfaceUrl = "/SSO/GoTo?sysid=" + DESEncrypt.Encrypt(item.FId, publickey) + "&openid=" + DESEncrypt.Encrypt(logininfo.userId, publickey);
}
else
{
item.FInterfaceUrl = item.FUrl;
}
item.FUrl = null;
}
typeEntity.PermFunction = datafunction.ToList();
}
return Success(datatype);
}
/// <summary>
/// 获取IP
/// </summary>
/// <returns></returns>
private string GetIP()
{
string ip = string.Empty;
if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"]))
ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
if (string.IsNullOrEmpty(ip))
ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
return ip;
}
}


}

+ 19
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionBLL.cs 查看文件

@@ -184,6 +184,25 @@ namespace Learun.Application.TwoDevelopment.Permission
}
}

public IEnumerable<Perm_FunctionEntity> GetListByFTId(string typeEntityFtId, string userId)
{
try
{
return perm_FunctionService.GetListByFTId(typeEntityFtId, userId);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}

#endregion

}


+ 3
- 1
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionIBLL.cs 查看文件

@@ -1,4 +1,5 @@
using Learun.Util;
using System.Collections;
using Learun.Util;
using System.Data;
using System.Collections.Generic;

@@ -49,5 +50,6 @@ namespace Learun.Application.TwoDevelopment.Permission
#endregion

void SaveEntityByUPId(string keyValue, Perm_FunctionEntity entity);
IEnumerable<Perm_FunctionEntity> GetListByFTId(string typeEntityFtId, string userId);
}
}

+ 39
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_Function/Perm_FunctionService.cs 查看文件

@@ -228,5 +228,44 @@ namespace Learun.Application.TwoDevelopment.Permission

#endregion

public IEnumerable<Perm_FunctionEntity> GetListByFTId(string typeEntityFtId,string userId)
{
try
{
// 虚拟参数
var dp = new DynamicParameters(new { });
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(@"
t.FId,
t.FName,
t.FTId,
t.FUrl,t.FInterfaceUrl,t.FSecret,
t.FOrder,
t.FEnabled,t.FIsManagePage
");
strSql.Append(",b.UPUserName,b.UPPass,b.UPId ");
strSql.Append(" FROM Perm_Function t ");
strSql.Append(" right join Perm_UserPermission b on b.fid=t.fid ");
strSql.Append(" WHERE 1=1 ");
strSql.Append(" and b.UserId=@UserId ");
dp.Add("UserId", "" + userId + "", DbType.String);
strSql.Append(" AND t.FTId=@FTId ");
dp.Add("FTId", "" + typeEntityFtId + "", DbType.String);
return this.BaseRepository().FindList<Perm_FunctionEntity>(strSql.ToString(), dp);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
}
}

+ 4
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/Permission/Perm_FunctionType/Perm_FunctionTypeEntity.cs 查看文件

@@ -1,5 +1,6 @@
using Learun.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace Learun.Application.TwoDevelopment.Permission
@@ -64,6 +65,9 @@ namespace Learun.Application.TwoDevelopment.Permission
}
#endregion
#region 扩展字段

[NotMapped] public List<Perm_FunctionEntity> PermFunction { get; set; }

#endregion
}
}


Loading…
取消
儲存