重构代码

重构代码
This commit is contained in:
chenchun
2022-04-02 17:44:50 +08:00
parent c6371ba72d
commit f5fb2ea17b
105 changed files with 1489 additions and 4654 deletions

View File

@@ -14,7 +14,9 @@ namespace Yi.Framework.Common.Helper
{
public static string HttpGet(string Url, string postDataStr="")
{
#pragma warning disable SYSLIB0014 // 类型或成员已过时
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
#pragma warning restore SYSLIB0014 // 类型或成员已过时
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
@@ -52,7 +54,9 @@ namespace Yi.Framework.Common.Helper
public static string HttpPost(string Url, string postDataStr="")
{
CookieContainer cookie = new CookieContainer();
#pragma warning disable SYSLIB0014 // 类型或成员已过时
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
#pragma warning restore SYSLIB0014 // 类型或成员已过时
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);

View File

@@ -13,7 +13,9 @@ namespace Yi.Framework.Common.Helper
/// <returns></returns>
public static string MD5Encrypt16(string password)
{
#pragma warning disable SYSLIB0021 // 类型或成员已过时
var md5 = new MD5CryptoServiceProvider();
#pragma warning restore SYSLIB0021 // 类型或成员已过时
string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(password)), 4, 8);
t2 = t2.Replace("-", string.Empty);
return t2;

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Common.IOCOptions
{
public class AuthorizationOptions
{
public string Refresh { get; set; }
public List<string> WhiteList { get; set; }
public List<string> AccountList { get; set; }
public List<string> UserList { get; set; }
public List<string> TenantList { get; set; }
}
}

View File

@@ -1,32 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Common.IOCOptions
{
public class JWTTokenOptions
{
public string Audience
{
get;
set;
}
public string SecurityKey
{
get;
set;
}
//public SigningCredentials Credentials
//{
// get;
// set;
//}
public string Issuer
{
get;
set;
}
public string Audience { get; set; }
public string Issuer { get; set; }
public string SecurityKey { get; set; }
public string DefaultScheme { get; set; }
public int Expiration { get; set; }
public int ReExpiration { get; set; }
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Common.Models.Enum
{
public enum ResultCode
{
/// <summary>
/// 操作成功。
/// </summary>
Success = 200,
/// <summary>
/// 操作不成功
/// </summary>
NotSuccess = 500,
/// <summary>
/// 无权限
/// </summary>
NoPermission = 401,
/// <summary>
/// Access过期
/// </summary>
AccessTokenExpire = 1001,
/// <summary>
/// Refresh过期
/// </summary>
RefreshTokenExpire = 1002,
/// <summary>
/// 没有角色登录
/// </summary>
NoRoleLogin = 1003,
}
}

View File

@@ -1,70 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Extensions.Localization;
using Yi.Framework.Common.Models.Enum;
using Yi.Framework.Language;
namespace Yi.Framework.Common.Models
{
/// <summary>
/// 结果数据
/// </summary>
public class Result
{
public static IStringLocalizer<LocalLanguage> _local;
public ResultCode code { get; set; }
public bool status { get; set; }
public int code { get; set; }
public string msg { get; set; }
public string message { get; set; }
public object data { get; set; }
public static Result Instance(bool status, string msg)
public static Result Expire(ResultCode code, string msg="")
{
return new Result() { status = status, code = 500, msg = msg };
return new Result() { code = code, status=false, message = Get(msg, "token_expiration") };
}
public static Result Error(string msg = "fail")
public static Result Error(string msg = "")
{
return new Result() { status = false, code = 500, msg = msg };
return new Result() { code = ResultCode.NotSuccess,status=false, message =Get(msg, "fail") };
}
public static Result Success(string msg = "succeed")
public static Result Success(string msg = "")
{
return new Result() { status = true, code = 200, msg = msg };
return new Result() { code = ResultCode.Success,status=true, message =Get( msg, "succeed" )};
}
public static Result UnAuthorize(string msg = "unAuthorize")
public static Result SuccessError(string msg = "")
{
return new Result() { status = false, code = 401, msg = msg };
return new Result() { code = ResultCode.Success, status = false, message = Get(msg, "fail") };
}
public static Result UnAuthorize(string msg = "")
{
return new Result() { code = ResultCode.NoPermission,status=false, message = Get(msg, "unAuthorize") };
}
public Result SetStatus(bool _status)
{
this.status = _status;
return this;
}
public Result SetData(object obj)
{
this.data = obj;
return this;
}
public Result SetCode(int Code)
public Result SetCode(ResultCode Code)
{
this.code = Code;
return this;
}
public Result StatusFalse()
{
this.status = false;
return this;
}
public Result StatusTrue()
{
this.status = true;
return this;
}
public static string Get(string msg,string msg2)
{
if (msg=="")
{
msg = _local[msg2];
}
return msg;
}
}
public class Result<T>
{
public bool status { get; set; }
public int code { get; set; }
public string msg { get; set; }
public ResultCode code { get; set; }
public string message { get; set; }
public T data { get; set; }
public static Result<T> Instance(bool status, string msg)
{
return new Result<T>() { status = status, code = 500, msg = msg };
}
public static Result<T> Error(string msg = "fail")
{
return new Result<T> { status = false, code = 500, msg = msg };
return new Result<T>() { code = ResultCode.NotSuccess, message = msg };
}
public static Result<T> Success(string msg = "succeed")
{
return new Result<T> { status = true, code = 200, msg = msg };
return new Result<T>() { code = ResultCode.Success, message = msg };
}
public static Result<T> UnAuthorize(string msg = "unAuthorize")
{
return new Result<T>{ status = false, code = 401, msg = msg };
return new Result<T>() { code = ResultCode.NoPermission, message = msg };
}
public Result<T> SetData(T TValue)
@@ -72,6 +92,11 @@ namespace Yi.Framework.Common.Models
this.data = TValue;
return this;
}
}
public Result<T> SetCode(ResultCode Code)
{
this.code = Code;
return this;
}
}
}

View File

@@ -0,0 +1,10 @@
using System;
namespace Yi.Framework.Common.Models
{
public static class ServiceLocator
{
public static IServiceProvider Instance { get; set; }
}
}

View File

@@ -6,7 +6,12 @@
<ItemGroup>
<PackageReference Include="EPPlus" Version="5.8.4" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="6.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Language\Yi.Framework.Language.csproj" />
</ItemGroup>
</Project>