|
|
@@ -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).Where(m=>m.FIsH5==true).Select(m=> |
|
|
|
new |
|
|
|
{ |
|
|
|
m.FName, |
|
|
|
m.FId, |
|
|
|
}); |
|
|
|
return Success(functionlist); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 获取页面显示列表数据 |
|
|
@@ -181,7 +289,7 @@ namespace Learun.Application.WebApi.Modules |
|
|
|
var datatype = perm_FunctionTypeIBLL.GetListByUserId(userInfo.userId); |
|
|
|
foreach (var typeEntity in datatype) |
|
|
|
{ |
|
|
|
var datafunction = perm_FunctionIBLL.GetListByFTId(typeEntity.FTId, userInfo.userId); |
|
|
|
var datafunction = perm_FunctionIBLL.GetListByFTId(typeEntity.FTId, userInfo.userId).Where(m=>m.FIsH5==true); |
|
|
|
foreach (var item in datafunction) |
|
|
|
{ |
|
|
|
if (item.FIsManagePage == true) |
|
|
|