Commit 8346c628 authored by 黄奎's avatar 黄奎

新增api

parent be537d10
...@@ -9,7 +9,7 @@ using System.Linq; ...@@ -9,7 +9,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Mall.CacheManager.Base namespace Edu.CacheManager.Base
{ {
/// <summary> /// <summary>
/// ConnectionMultiplexer对象管理帮助类 /// ConnectionMultiplexer对象管理帮助类
......
...@@ -6,7 +6,7 @@ using System.Linq; ...@@ -6,7 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Mall.CacheManager.Base namespace Edu.CacheManager.Base
{ {
/// <summary> /// <summary>
/// Redis操作 /// Redis操作
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Edu.Common\Edu.Common.csproj" /> <ProjectReference Include="..\Edu.Common\Edu.Common.csproj" />
<ProjectReference Include="..\Edu.Model\Edu.Model.csproj" />
<ProjectReference Include="..\Edu.Module.User\Edu.Module.User.csproj" />
<ProjectReference Include="..\Edu.Repository\Edu.Repository.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
using Edu.CacheManager.Base;
using Edu.Model.CacheModel;
using System;
using System.Collections.Generic;
using System.Text;
namespace Edu.Cache.User
{
/// <summary>
/// redis缓存
/// </summary>
public class UserReidsCache
{
/// <summary>
/// 使用redis第几号库
/// </summary>
public static readonly int REDIS_DB3 = 3;
static readonly RedisHelper redis = new RedisHelper(REDIS_DB3);
/// <summary>
/// 设置缓存
/// </summary>
/// <param name="model"></param>
public static void UserInfoSet(string cacheKey, UserInfo model, int JwtExpirTime)
{
try
{
TimeSpan ts = GetExpirTime(JwtExpirTime);
redis.StringSet<UserInfo>(cacheKey, model, ts);
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "UserInfoSet缓存设置失败");
}
}
/// <summary>
/// 获取缓存时长
/// </summary>
/// <param name="JwtExpirTime"></param>
/// <returns></returns>
private static TimeSpan GetExpirTime(int JwtExpirTime)
{
DateTime dt = DateTime.Now;
DateTime dt2 = DateTime.Now;
TimeSpan ts = dt.AddSeconds(JwtExpirTime) - dt2;
return ts;
}
/// <summary>
/// 判断key是否存在
/// </summary>
/// <param name="cacheKey"></param>
/// <returns></returns>
public static bool Exists(string cacheKey)
{
return redis.KeyExists(cacheKey);
}
/// <summary>
/// 设置缓存
/// </summary>
/// <param name="cacheKey"></param>
/// <param name="Data"></param>
/// <param name="JwtExpirTime"></param>
public static void Set(string cacheKey, object Data, int JwtExpirTime)
{
try
{
TimeSpan ts = GetExpirTime(JwtExpirTime);
redis.StringSet(cacheKey, Data, ts);
}
catch (Exception)
{
}
}
/// <summary>
/// 获取用户登录信息
/// </summary>
/// <param name="UserId">用户Id</param>
/// <returns></returns>
public static UserInfo GetUserLoginInfo(object UserId)
{
UserInfo userInfo = null;
return userInfo;
}
}
}
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
"Edu.Cache/1.0.0": { "Edu.Cache/1.0.0": {
"dependencies": { "dependencies": {
"Edu.Common": "1.0.0", "Edu.Common": "1.0.0",
"Edu.Model": "1.0.0",
"Edu.Module.User": "1.0.0",
"Edu.Repository": "1.0.0",
"VT.FW": "1.0.1" "VT.FW": "1.0.1"
}, },
"runtime": { "runtime": {
...@@ -1915,6 +1918,14 @@ ...@@ -1915,6 +1918,14 @@
} }
} }
}, },
"Edu.Aop/1.0.0": {
"dependencies": {
"Castle.Core": "4.4.1"
},
"runtime": {
"Edu.Aop.dll": {}
}
},
"Edu.Common/1.0.0": { "Edu.Common/1.0.0": {
"dependencies": { "dependencies": {
"Microsoft.AspNetCore.Http": "2.2.2", "Microsoft.AspNetCore.Http": "2.2.2",
...@@ -1927,6 +1938,36 @@ ...@@ -1927,6 +1938,36 @@
"runtime": { "runtime": {
"Edu.Common.dll": {} "Edu.Common.dll": {}
} }
},
"Edu.Model/1.0.0": {
"dependencies": {
"Edu.Common": "1.0.0",
"VT.FW": "1.0.1"
},
"runtime": {
"Edu.Model.dll": {}
}
},
"Edu.Module.User/1.0.0": {
"dependencies": {
"Edu.Aop": "1.0.0",
"Edu.Common": "1.0.0",
"Edu.Model": "1.0.0",
"Edu.Repository": "1.0.0"
},
"runtime": {
"Edu.Module.User.dll": {}
}
},
"Edu.Repository/1.0.0": {
"dependencies": {
"Edu.Common": "1.0.0",
"Edu.Model": "1.0.0",
"VT.FW": "1.0.1"
},
"runtime": {
"Edu.Repository.dll": {}
}
} }
} }
}, },
...@@ -3112,10 +3153,30 @@ ...@@ -3112,10 +3153,30 @@
"path": "vt.fw/1.0.1", "path": "vt.fw/1.0.1",
"hashPath": "vt.fw.1.0.1.nupkg.sha512" "hashPath": "vt.fw.1.0.1.nupkg.sha512"
}, },
"Edu.Aop/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Edu.Common/1.0.0": { "Edu.Common/1.0.0": {
"type": "project", "type": "project",
"serviceable": false, "serviceable": false,
"sha512": "" "sha512": ""
},
"Edu.Model/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Edu.Module.User/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Edu.Repository/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
} }
} }
} }
\ No newline at end of file
...@@ -20,3 +20,11 @@ F:\工作\微途\外网代码\new_edu\Edu.Cache\obj\Debug\netcoreapp3.0\Edu.Cach ...@@ -20,3 +20,11 @@ F:\工作\微途\外网代码\new_edu\Edu.Cache\obj\Debug\netcoreapp3.0\Edu.Cach
F:\工作\微途\外网代码\new_edu\Edu.Cache\obj\Debug\netcoreapp3.0\Edu.Cache.csproj.CopyComplete F:\工作\微途\外网代码\new_edu\Edu.Cache\obj\Debug\netcoreapp3.0\Edu.Cache.csproj.CopyComplete
F:\工作\微途\外网代码\new_edu\Edu.Cache\obj\Debug\netcoreapp3.0\Edu.Cache.dll F:\工作\微途\外网代码\new_edu\Edu.Cache\obj\Debug\netcoreapp3.0\Edu.Cache.dll
F:\工作\微途\外网代码\new_edu\Edu.Cache\obj\Debug\netcoreapp3.0\Edu.Cache.pdb F:\工作\微途\外网代码\new_edu\Edu.Cache\obj\Debug\netcoreapp3.0\Edu.Cache.pdb
F:\工作\微途\外网代码\new_edu\Edu.Cache\bin\Debug\netcoreapp3.0\Edu.Aop.dll
F:\工作\微途\外网代码\new_edu\Edu.Cache\bin\Debug\netcoreapp3.0\Edu.Model.dll
F:\工作\微途\外网代码\new_edu\Edu.Cache\bin\Debug\netcoreapp3.0\Edu.Module.User.dll
F:\工作\微途\外网代码\new_edu\Edu.Cache\bin\Debug\netcoreapp3.0\Edu.Repository.dll
F:\工作\微途\外网代码\new_edu\Edu.Cache\bin\Debug\netcoreapp3.0\Edu.Model.pdb
F:\工作\微途\外网代码\new_edu\Edu.Cache\bin\Debug\netcoreapp3.0\Edu.Module.User.pdb
F:\工作\微途\外网代码\new_edu\Edu.Cache\bin\Debug\netcoreapp3.0\Edu.Repository.pdb
F:\工作\微途\外网代码\new_edu\Edu.Cache\bin\Debug\netcoreapp3.0\Edu.Aop.pdb
{ {
"version": 1, "version": 1,
"dgSpecHash": "x/9dTAtmlFMI+jbGVlABfC/fykEbZYjnoYIaA2z6HRIX3ZvaO2+GgqImhc6R+vSlL/pgP/8ewZGt31dLV7tA9A==", "dgSpecHash": "LRybV+AX/CjAk7oiUYxps2DCWxSLeqfY8HqQiSjf/NJMOAptYharLMj2ROnTrBnXUngwsHKEa9lsxrAC3ohZ4Q==",
"success": true "success": true
} }
\ No newline at end of file
...@@ -2597,6 +2597,19 @@ ...@@ -2597,6 +2597,19 @@
"lib/netstandard2.1/VT.FW.dll": {} "lib/netstandard2.1/VT.FW.dll": {}
} }
}, },
"Edu.Aop/1.0.0": {
"type": "project",
"framework": ".NETCoreApp,Version=v3.0",
"dependencies": {
"Castle.Core": "4.4.1"
},
"compile": {
"bin/placeholder/Edu.Aop.dll": {}
},
"runtime": {
"bin/placeholder/Edu.Aop.dll": {}
}
},
"Edu.Common/1.0.0": { "Edu.Common/1.0.0": {
"type": "project", "type": "project",
"framework": ".NETCoreApp,Version=v3.0", "framework": ".NETCoreApp,Version=v3.0",
...@@ -2614,6 +2627,51 @@ ...@@ -2614,6 +2627,51 @@
"runtime": { "runtime": {
"bin/placeholder/Edu.Common.dll": {} "bin/placeholder/Edu.Common.dll": {}
} }
},
"Edu.Model/1.0.0": {
"type": "project",
"framework": ".NETCoreApp,Version=v3.0",
"dependencies": {
"Edu.Common": "1.0.0",
"VT.FW": "1.0.1"
},
"compile": {
"bin/placeholder/Edu.Model.dll": {}
},
"runtime": {
"bin/placeholder/Edu.Model.dll": {}
}
},
"Edu.Module.User/1.0.0": {
"type": "project",
"framework": ".NETCoreApp,Version=v3.0",
"dependencies": {
"Edu.Aop": "1.0.0",
"Edu.Common": "1.0.0",
"Edu.Model": "1.0.0",
"Edu.Repository": "1.0.0"
},
"compile": {
"bin/placeholder/Edu.Module.User.dll": {}
},
"runtime": {
"bin/placeholder/Edu.Module.User.dll": {}
}
},
"Edu.Repository/1.0.0": {
"type": "project",
"framework": ".NETCoreApp,Version=v3.0",
"dependencies": {
"Edu.Common": "1.0.0",
"Edu.Model": "1.0.0",
"VT.FW": "1.0.1"
},
"compile": {
"bin/placeholder/Edu.Repository.dll": {}
},
"runtime": {
"bin/placeholder/Edu.Repository.dll": {}
}
} }
} }
}, },
...@@ -8291,15 +8349,38 @@ ...@@ -8291,15 +8349,38 @@
"vt.fw.nuspec" "vt.fw.nuspec"
] ]
}, },
"Edu.Aop/1.0.0": {
"type": "project",
"path": "../Edu.Aop/Edu.Aop.csproj",
"msbuildProject": "../Edu.Aop/Edu.Aop.csproj"
},
"Edu.Common/1.0.0": { "Edu.Common/1.0.0": {
"type": "project", "type": "project",
"path": "../Edu.Common/Edu.Common.csproj", "path": "../Edu.Common/Edu.Common.csproj",
"msbuildProject": "../Edu.Common/Edu.Common.csproj" "msbuildProject": "../Edu.Common/Edu.Common.csproj"
},
"Edu.Model/1.0.0": {
"type": "project",
"path": "../Edu.Model/Edu.Model.csproj",
"msbuildProject": "../Edu.Model/Edu.Model.csproj"
},
"Edu.Module.User/1.0.0": {
"type": "project",
"path": "../Edu.Module.User/Edu.Module.User.csproj",
"msbuildProject": "../Edu.Module.User/Edu.Module.User.csproj"
},
"Edu.Repository/1.0.0": {
"type": "project",
"path": "../Edu.Repository/Edu.Repository.csproj",
"msbuildProject": "../Edu.Repository/Edu.Repository.csproj"
} }
}, },
"projectFileDependencyGroups": { "projectFileDependencyGroups": {
".NETCoreApp,Version=v3.0": [ ".NETCoreApp,Version=v3.0": [
"Edu.Common >= 1.0.0", "Edu.Common >= 1.0.0",
"Edu.Model >= 1.0.0",
"Edu.Module.User >= 1.0.0",
"Edu.Repository >= 1.0.0",
"VT.FW >= 1.0.1" "VT.FW >= 1.0.1"
] ]
}, },
...@@ -8339,6 +8420,15 @@ ...@@ -8339,6 +8420,15 @@
"projectReferences": { "projectReferences": {
"F:\\工作\\微途\\外网代码\\new_edu\\Edu.Common\\Edu.Common.csproj": { "F:\\工作\\微途\\外网代码\\new_edu\\Edu.Common\\Edu.Common.csproj": {
"projectPath": "F:\\工作\\微途\\外网代码\\new_edu\\Edu.Common\\Edu.Common.csproj" "projectPath": "F:\\工作\\微途\\外网代码\\new_edu\\Edu.Common\\Edu.Common.csproj"
},
"F:\\工作\\微途\\外网代码\\new_edu\\Edu.Model\\Edu.Model.csproj": {
"projectPath": "F:\\工作\\微途\\外网代码\\new_edu\\Edu.Model\\Edu.Model.csproj"
},
"F:\\工作\\微途\\外网代码\\new_edu\\Edu.Module.User\\Edu.Module.User.csproj": {
"projectPath": "F:\\工作\\微途\\外网代码\\new_edu\\Edu.Module.User\\Edu.Module.User.csproj"
},
"F:\\工作\\微途\\外网代码\\new_edu\\Edu.Repository\\Edu.Repository.csproj": {
"projectPath": "F:\\工作\\微途\\外网代码\\new_edu\\Edu.Repository\\Edu.Repository.csproj"
} }
} }
} }
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Edu.Model.CacheModel
{
/// <summary>
/// 用户缓存
/// </summary>
public class UserInfo
{
}
}
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
<TargetFramework>netcoreapp3.0</TargetFramework> <TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Folder Include="CacheModel\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="VT.FW" Version="1.0.1" /> <PackageReference Include="VT.FW" Version="1.0.1" />
</ItemGroup> </ItemGroup>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Edu.Common;
using Edu.Common.API;
using Edu.Common.Plugin;
using Edu.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Web;
namespace Edu.WebApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiExceptionFilter]
[ApiFilter]
[EnableCors("AllowCors")]
public class BaseController : ControllerBase
{
/// <summary>
/// 整理前端传递的post参数
/// </summary>
/// <param name="requestMsg"></param>
/// <returns></returns>
public RequestParm RequestParm
{
get
{
#region 读取post参数
var requestMsg = Request.HttpContext.Items[GlobalKey.UserPostInfo];
var requestParm = JsonConvert.DeserializeObject<RequestParm>(requestMsg.ToString());
if (Request.HttpContext.Items[GlobalKey.TokenUserInfo] != null)
{
JObject parms = JObject.Parse(Request.HttpContext.Items[GlobalKey.TokenUserInfo].ToString());
requestParm.Uid = parms.GetStringValue("Uid");
//if (requestParm.uid != null && !string.IsNullOrWhiteSpace(requestParm.uid))
//{
// requestParm.TenantId = Convert.ToInt32(requestParm.uid);
//}
}
#endregion
//根据token 获取uid
return requestParm;
}
}
/// <summary>
/// 商户缓存信息
/// </summary>
//public UserInfo UserInfo
//{
// get
// {
// var parm = this.RequestParm;
// UserInfo userInfo = UserReidsCache.GetUserLoginInfo(parm.uid);
// return userInfo;
// }
//}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\PublishProfiles\**" />
<Content Remove="Properties\PublishProfiles\**" />
<EmbeddedResource Remove="Properties\PublishProfiles\**" />
<None Remove="Properties\PublishProfiles\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="JWT" Version="5.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Edu.Aop\Edu.Aop.csproj" />
<ProjectReference Include="..\Edu.Cache\Edu.Cache.csproj" />
<ProjectReference Include="..\Edu.Common\Edu.Common.csproj" />
<ProjectReference Include="..\Edu.Model\Edu.Model.csproj" />
<ProjectReference Include="..\Edu.Module.User\Edu.Module.User.csproj" />
<ProjectReference Include="..\Edu.Repository\Edu.Repository.csproj" />
</ItemGroup>
</Project>
using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json;
using Edu.Common;
using Edu.Common.API;
using Edu.Common.Plugin;
namespace Edu.WebApi.Filter
{
/// <summary>
/// Api异常过滤
/// </summary>
public class ApiExceptionFilterAttribute : ExceptionFilterAttribute
{
/// <summary>
/// 异常处理拦截
/// </summary>
/// <param name="context"></param>
public override void OnException(ExceptionContext context)
{
if (context.Exception.Message != "The operation was canceled." && !context.Exception.Message.Contains("已取消该操作"))
{
try
{
LogHelper.WriteInfo("ApiExceptionFilter_1:" + context.Exception);
}
catch
{
}
}
//记录错误日志
if (context.HttpContext.Items[GlobalKey.UserPostInfo] != null)
{
LogHelper.Write(context.Exception,$"ApiExceptionFilter_2:{Config.GetFilePath(context.HttpContext.Request.GetAbsoluteUri())},请求参数:{JsonConvert.SerializeObject(context.HttpContext.Items[GlobalKey.UserPostInfo].ToString())}");
}
else
{
LogHelper.Write(context.Exception,$"ApiExceptionFilter_3:{Config.GetFilePath(context.HttpContext.Request.GetAbsoluteUri())}");
}
var robj = new ApiResult()
{
Code = (int)ResultCode.AbnormalServer,
Message = "服务器繁忙,请稍后再试",
Data = null
};
context.Result = new Microsoft.AspNetCore.Mvc.JsonResult(robj);
}
}
}
\ No newline at end of file
using JWT;
using JWT.Serializers;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Net;
using System.Text;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http.Features;
using Edu.Common.Plugin;
using Edu.Common.API;
using Edu.Cache.User;
namespace Edu.WebApi.Filter
{
/// <summary>
/// Api过滤属性
/// </summary>
public class ApiFilterAttribute : ActionFilterAttribute
{
/// <summary>
/// OnActionExecuting
/// </summary>
/// <param name="actionContext"></param>
public override void OnActionExecuting(ActionExecutingContext actionContext)
{
string token = "";
//请求参数
JObject parm = DoApiMonitorLog(actionContext, ref token);
bool isCheckToken = true;
var endpoint = actionContext.HttpContext.Features.Get<IEndpointFeature>()?.Endpoint;
if (endpoint != null && endpoint.Metadata.GetMetadata<AllowAnonymousAttribute>() != null)
{
isCheckToken = false;
}
#region Token校验
if (isCheckToken)
{
JWTValidat(actionContext, token);
}
#endregion
#region 验证表单重复提交
string controllerName = actionContext.ActionDescriptor.RouteValues["controller"].ToString().ToLower();
string actionName = actionContext.ActionDescriptor.RouteValues["action"].ToString().ToLower();
if (!actionName.ToLower().Contains("get"))
{
string cachedKey = SecurityHelper.MD5(string.Format("cmd={0}&token={1}", controllerName + "/" + actionName, token));
try
{
if (UserReidsCache.Exists(cachedKey))//判断表单是否重复提交
{
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(new ApiResult
{
Code = (int)ResultCode.FormRepeatSubmit,
Message = "表单重复提交,请稍后再试",
Data = null
});
}
else
{
//默认2秒钟之内不能重复提交
UserReidsCache.Set(cachedKey, 1, 2);
}
}
catch
{
}
}
#endregion
}
/// <summary>
/// 解析post参数
/// </summary>
/// <param name="actionContext"></param>
/// <param name="token"></param>
/// <returns></returns>
private JObject DoApiMonitorLog(ActionExecutingContext actionContext, ref string token)
{
JObject parm = new JObject();
var request = actionContext.HttpContext.Request;
#region 如果参数是json实体对象,获取序列化后的数据
request.EnableBuffering();
string responseData = "";
using (var reader = new StreamReader(request.Body, encoding: Encoding.UTF8))
{
var body = reader.ReadToEndAsync();
responseData = body.Result;
request.Body.Position = 0;
}
if (!string.IsNullOrWhiteSpace(responseData.Trim()))
{
try
{
parm = JObject.Parse(responseData);
actionContext.HttpContext.Items[Common.GlobalKey.UserPostInfo] = responseData;
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, string.Format("DoApiMonitorLog:{0}", responseData));
}
token = JsonHelper.GetStringValue(parm, "token");
}
#endregion
return parm;
}
/// <summary>
/// token校验
/// </summary>
/// <param name="actionContext"></param>
/// <param name="token"></param>
private static void JWTValidat(ActionExecutingContext actionContext, string token)
{
if (!string.IsNullOrEmpty(token))
{
//解析token,校验是否失效
try
{
IJsonSerializer serializer = new JsonNetSerializer();
IDateTimeProvider provider = new UtcDateTimeProvider();
IJwtValidator validator = new JwtValidator(serializer, provider);
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder);
string secret =Common.Config.JwtSecretKey;
var json = decoder.Decode(token, secret, verify: true);//token为之前生成的字符串
JObject jwtJson = JObject.Parse(json);
actionContext.HttpContext.Items[Common.GlobalKey.TokenUserInfo] = jwtJson["mall_userInfo"];
}
catch (SignatureVerificationException sve)
{
string message = sve.Message;
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(
new ApiResult
{
Code = (int)ResultCode.TokenOverdue,
Message = "用户凭证失效,请重新登录1",
Data = null
});
}
catch (ArgumentException ae)
{
string message = ae.Message;
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(
new ApiResult
{
Code = (int)ResultCode.TokenIllegal,
Message = "用户凭证无效,请重新登录2",
Data = null
});
}
catch (Exception ex)
{
string message = ex.Message;
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(
HttpStatusCode.OK,
new ApiResult
{
Code = (int)ResultCode.TokenIllegal,
Message = "用户凭证失效,请重新登录3",
Data = null
});
}
}
else
{
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(
new ApiResult
{
Code = (int)ResultCode.TokenIllegal,
Message = "用户凭证为空,请重新登录4",
Data = null
});
}
}
}
}
\ No newline at end of file
using System.Net.Http;
using System.Text;
using Microsoft.AspNetCore.Http;
namespace Edu.WebApi.Filter
{
/// <summary>
/// Http请求扩展
/// </summary>
public static class HttpRequestMessageExtensions
{
private const string HttpContext = "MS_HttpContext";
private const string RemoteEndpointMessage = "System.ServiceModel.Channels.RemoteEndpointMessageProperty";
private const string OwinContext = "MS_OwinContext";
/// <summary>
/// 获取客户端Ip地址
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetClientIpAddress(this HttpRequestMessage request)
{
// Web-hosting. Needs reference to System.Web.dll
if (request.Properties.ContainsKey(HttpContext))
{
dynamic ctx = request.Properties[HttpContext];
if (ctx != null)
{
return ctx.Request.UserHostAddress;
}
}
// Self-hosting. Needs reference to System.ServiceModel.dll.
if (request.Properties.ContainsKey(RemoteEndpointMessage))
{
dynamic remoteEndpoint = request.Properties[RemoteEndpointMessage];
if (remoteEndpoint != null)
{
return remoteEndpoint.Address;
}
}
// Self-hosting using Owin. Needs reference to Microsoft.Owin.dll.
if (request.Properties.ContainsKey(OwinContext))
{
dynamic owinContext = request.Properties[OwinContext];
if (owinContext != null)
{
return owinContext.Request.RemoteIpAddress;
}
}
return null;
}
/// <summary>
/// 获取url
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetAbsoluteUri(this HttpRequest request)
{
return new StringBuilder()
.Append(request.Scheme)
.Append("://")
.Append(request.Host)
.Append(request.PathBase)
.Append(request.Path)
.Append(request.QueryString)
.ToString();
}
}
}
\ No newline at end of file
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace Edu.WebApi
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel((context, options) =>
{
options.AllowSynchronousIO = true;
//设置应用服务器Kestrel请求体最大为50MB
options.Limits.MaxRequestBodySize = 52428800;
//解决并发异常
options.Limits.MinRequestBodyDataRate = null;
});
webBuilder.UseStartup<Startup>().UseIIS();
});
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.Text.Encodings.Web;
using System.Text.Unicode;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Edu.WebApi
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(x => x.AllowSynchronousIO = true)
.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
services.AddControllers();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); //注入http上下文
services.AddMvc().AddJsonOptions(options =>
{
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
options.JsonSerializerOptions.PropertyNamingPolicy = null;
});
List<string> corsArray = new List<string>()
{
"http://localhost:8081",
"http://localhost:8080",
"http://localhost:8082",
"http://127.0.0.1:50512",
"http://127.0.0.1:20224",
"http://127.0.0.1:28221",
"http://www.test.com:8080",
"http://www.test.com:8081",
"http://yx.oytour.com",
"http://mall.oytour.com",
"http://testmall.oytour.com",
"http://yx.oytour.com",
};
services.AddCors(options => options.AddPolicy("AllowCors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().WithOrigins(corsArray.ToArray())));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
// 允许所有跨域,cors是在ConfigureServices方法中配置的跨域策略名称
app.UseCors("AllowCors");
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
\ No newline at end of file
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
{
"ConnectionStrings": {
"DefaultConnection": "server=192.168.1.214;user id=reborn;password=Reborn@2018;database=reborn_mall;CharSet=utf8mb4; Convert Zero Datetime=true; ",
"DefaultConnectionPName": "MySql.Data.MySqlClient",
"FinanceConnection": "server=192.168.1.214;user id=reborn;password=Reborn@2018;database=reborn_finance;CharSet=utf8mb4; Convert Zero Datetime=true; ",
"FinanceConnectionPName": "MySql.Data.MySqlClient",
"UserConnection": "server=192.168.1.214;user id=reborn;password=Reborn@2018;database=reborn_user;CharSet=utf8mb4; Convert Zero Datetime=true; ",
"UserConnectionPName": "MySql.Data.MySqlClient",
"PropertyConnection": "server=192.168.1.214;user id=reborn;password=Reborn@2018;database=test_property;CharSet=utf8mb4; Convert Zero Datetime=true; ",
"PropertyConnectionPName": "MySql.Data.MySqlClient"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"JwtSecretKey": "@VIITTOREBORN*2018",
"JwtExpirTime": 2592000,
"ApiExpirTime": 2592000,
"AllowedHosts": "*",
"OpenValidation": "False",
"UploadSiteUrl": "http://192.168.1.214:8120",
"ViewFileSiteUrl": "https://viitto-1301420277.cos.ap-chengdu.myqcloud.com",
"ImKey": "b612b31e837c79c68f141aeb719d2b20",
"ImSecret": "66000451fb72",
"Mongo": "mongodb://47.96.25.130:27017",
"MongoDBName": "Mall",
"ProjectUrl": "D:/project/GitProject/mallapp",
"DeveloperKitsPort": "15720",
"FirstPage": "pages/index/index.html",
"ByteDanceSendTemplate": "https://developer.toutiao.com/api/apps/game/template/send",
"sTenpayNotify": "http://mallapi.oytour.com/api/WeChatNotify/Notify", //微信商品回调地址
"sTenpayRechargeNotify": "http://mallapi.oytour.com/api/WeChatNotify/RechargeNotify", //微信充值回调地址
"sTenpayMemberBuyNotify": "http://mallapi.oytour.com/api/WeChatNotify/MemberBuyNotify", //微信充值回调地址
"sTenpayVipBuyNotify": "http://mallapi.oytour.com/api/WeChatNotify/VipBuyNotify", //微信购买VIP回调地址
"NetworkDirector": 1756, //网络主管的id,用于新建供应商账户的时候的创建人
"RB_Branch_Id": 49, //所属公司id
"IncomeDirector": 1756, //财务收入创建人
"IncomeBranchId": 49, //财务收入创建人公司
"IncomeDepartment": 331,
"ExpendDirector": 1756, //财务支出创建人
"ExpendBranchId": 49, //财务支出创建人公司
"ExpendDepartment": 331,
"RebornDMC": "reborn_dmc",
"PropertyDB": "test_property",
"IncomeFinanceApi": "http://192.168.2.16:8083/api/Mall/InsertFinanceBatchForMallIn",
"PaymentFinanceApi": "http://192.168.2.16:8083/api/Mall/InsertFinanceBatchForMallOut",
"ZYRefundFinanceApi": "http://192.168.2.16:8083/api/Mall/SetMallOrderSalesTheWayRefund",
"PropertyApi": "http://192.168.2.16:8087/api/ECWorkFlow/SetECSuppliesStockInFlow",
"FinanceKey": "FinanceMallInsertToERPViitto2020",
"SettlementRate": "0.60",
"RabbitMqConfig": {
"HostName": "47.96.25.130",
"VirtualHost": "/",
"Port": 5672,
"UserName": "guest",
"Password": "viitto2019"
},
"RedisSetting": {
"RedisServer": "47.96.23.199",
"RedisPort": "6379",
"RedisPwd": "Viitto2018"
},
"VirtualDirectory": "WebFile",
"FileService": "2",
"IsNormalServer": 2,
"FinanceSetting": {
"TenantId": 1,
"MallBaseId": 1,
"RemitTypeId": 10,
"RemitAccountId": 3012,
"ProcurementCTId": 224, //以下采购
"ProcurementFWId": 127,
"ProcurementDirector": 1756,
"ProcurementBranchId": 49,
"ProcurementDepartment": 331,
"ProcurementCurrencyId": 1
},
"InitializeImages": {
"GradeEntranceImage": "1234566778"
},
"ShareConfig": {
"ShareImg": "https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/zanyang.png"
}
}
\ No newline at end of file
@echo off
echo ASPNETCORE_ENVIRONMENT=Development
dotnet build
start "Mall.WebApi" dotnet bin\Debug\netcoreapp3.0\Mall.WebApi.dll
exit
\ No newline at end of file
...@@ -21,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Module", "Module", "{7AC0A4 ...@@ -21,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Module", "Module", "{7AC0A4
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Edu.Module.User", "Edu.Module.User\Edu.Module.User.csproj", "{1B9D7825-26A9-4F81-B04C-2261CB1F954A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Edu.Module.User", "Edu.Module.User\Edu.Module.User.csproj", "{1B9D7825-26A9-4F81-B04C-2261CB1F954A}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Edu.WebApi", "Edu.WebApi\Edu.WebApi.csproj", "{878A03A7-2571-4322-A55E-39A5105296A9}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -51,6 +53,10 @@ Global ...@@ -51,6 +53,10 @@ Global
{1B9D7825-26A9-4F81-B04C-2261CB1F954A}.Debug|Any CPU.Build.0 = Debug|Any CPU {1B9D7825-26A9-4F81-B04C-2261CB1F954A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B9D7825-26A9-4F81-B04C-2261CB1F954A}.Release|Any CPU.ActiveCfg = Release|Any CPU {1B9D7825-26A9-4F81-B04C-2261CB1F954A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B9D7825-26A9-4F81-B04C-2261CB1F954A}.Release|Any CPU.Build.0 = Release|Any CPU {1B9D7825-26A9-4F81-B04C-2261CB1F954A}.Release|Any CPU.Build.0 = Release|Any CPU
{878A03A7-2571-4322-A55E-39A5105296A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{878A03A7-2571-4322-A55E-39A5105296A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{878A03A7-2571-4322-A55E-39A5105296A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{878A03A7-2571-4322-A55E-39A5105296A9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment