更新框架,增加云库搜索模块
This commit is contained in:
1 parent
8526e5e0d2
commit
f2caec6083
192 files changed
+3626
-804
No files matched your search
@@ -0,0 +1,108 @@
|
||||
using Asp.Versioning;
|
||||
using MAX.Framework.Dtos;
|
||||
using MAX.Framework.Security;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Store.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
||||
public class AuthController : ControllerBase
|
||||
{
|
||||
//private readonly IUserService _userService;
|
||||
private readonly ITokenService _tokenService;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IOnlineUserStore _onlineUserStore;
|
||||
|
||||
public AuthController( ITokenService tokenService, ICurrentUser currentUser, IOnlineUserStore onlineUserStore)
|
||||
{
|
||||
//_userService = userService;
|
||||
_tokenService = tokenService;
|
||||
_currentUser = currentUser;
|
||||
_onlineUserStore = onlineUserStore;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录:校验用户名/密码,签发 JWT(单点登录:同用户的新登录会使旧令牌失效)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<ApiResult<object?>> Login([FromBody] LoginRequest request)
|
||||
{
|
||||
if (request is null || string.IsNullOrWhiteSpace(request.UserName) || string.IsNullOrWhiteSpace(request.Password))
|
||||
{
|
||||
return ApiResult.Fail("用户名或密码不能为空", 400);
|
||||
}
|
||||
|
||||
//UserDto? user = await _userService.LoginAsync(request.UserName, request.Password);
|
||||
//if (user is null)
|
||||
//{
|
||||
// return ApiResult.Error("用户名或密码错误", 401);
|
||||
//}
|
||||
|
||||
//var claims = new List<Claim>
|
||||
//{
|
||||
// new(JwtClaimTypes.UserName, user.UserName),
|
||||
// new(JwtClaimTypes.NickName, user.NickName),
|
||||
//};
|
||||
|
||||
//TokenResult token = _tokenService.CreateToken(claims);
|
||||
return ApiResult<object?>.Success(111);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退出登录:销毁当前用户的服务端在线会话,令牌立即失效
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public ApiResult<object?> Logout()
|
||||
{
|
||||
if (_currentUser.UserName is string username)
|
||||
{
|
||||
_onlineUserStore.SignOut(username);
|
||||
}
|
||||
|
||||
return ApiResult<object?>.Success(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前登录用户信息(需携带 Bearer Token)
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public ApiResult<object?> Me()
|
||||
{
|
||||
return ApiResult<object?>.Success(new
|
||||
{
|
||||
UserName = _currentUser.UserName,
|
||||
NickName = _currentUser.NickName,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在线人员列表(需携带 Bearer Token)
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public ApiResult<object?> OnlineUsers()
|
||||
{
|
||||
IReadOnlyList<OnlineUserInfo> users = _onlineUserStore.GetOnlineUsers();
|
||||
return ApiResult<object?>.Success(new
|
||||
{
|
||||
Count = users.Count,
|
||||
Users = users,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class LoginRequest
|
||||
{
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Store.Framework.Repositorys;
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Store.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersionNeutral]
|
||||
[Route("wxxd_user/[action]")]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public UserController(IUserRepository userRepository)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
[HttpGet]
|
||||
public string GetUser()
|
||||
{
|
||||
return JsonSerializer.Serialize(_userRepository.Select.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Asp.Versioning;
|
||||
using MAX.Framework.Dtos;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Store.Api;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Store.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Description("测试温度")]
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries =
|
||||
[
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
];
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
IEnumerable<WeatherForecast> data = Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Asp.Versioning;
|
||||
using MAX.Framework.Dtos;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Store.Api;
|
||||
|
||||
namespace Store.Api.Controllers.v2
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("2.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries =
|
||||
[
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
];
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecastV2")]
|
||||
public ApiResult<IEnumerable<WeatherForecastV2>> Get()
|
||||
{
|
||||
IEnumerable<WeatherForecastV2> data = Enumerable.Range(1, 10).Select(index => new WeatherForecastV2
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
FeelsLikeC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
return ApiResult<IEnumerable<WeatherForecastV2>>.Success(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using Asp.Versioning;
|
||||
using MAX.Framework.DependencyInjection;
|
||||
using Scalar.AspNetCore;
|
||||
|
||||
public partial class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// IOC 注册:自动注册 ISingletonDependency / IScopedDependency / ITransientDependency,并执行所有 IStartup(实现见 StoreHub.Framework)
|
||||
builder.Services.AddStoreHub();
|
||||
builder.Services.AddFreeSqlDB();
|
||||
// JWT 验证:注册 JwtBearer 认证 + 令牌服务 + OpenAPI Bearer 安全方案(配置节 Jwt)
|
||||
builder.Services.AddStoreHubJwt(builder.Configuration);
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(options =>
|
||||
{
|
||||
// 兼容迁移的同步控制器:允许同步读写请求/响应 IO(旧 asmx 行为)
|
||||
options.AllowSynchronousIO = true;
|
||||
});
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddApiVersioning(options =>
|
||||
{
|
||||
options.DefaultApiVersion = new ApiVersion(1, 0);
|
||||
options.ReportApiVersions = true;
|
||||
options.ApiVersionReader = new UrlSegmentApiVersionReader();
|
||||
}).AddMvc().AddApiExplorer(options =>
|
||||
{
|
||||
options.GroupNameFormat = "'v'V";
|
||||
options.SubstituteApiVersionInUrl = true;
|
||||
}).AddOpenApi();
|
||||
|
||||
#region DB
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// 初始化 KJD 迁移的静态提供者(MysqlUtils 连接提供 / 业务配置读取)
|
||||
//StoreHub.KJDWebService.Commons.AdoProvider.SetServiceProvider(app.Services);
|
||||
//StoreHub.KJDWebService.Commons.KJDConfig.SetConfiguration(app.Configuration);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi().WithDocumentPerVersion();
|
||||
app.MapScalarApiReference(options =>
|
||||
{
|
||||
|
||||
options.Title = "商铺管理API V1";
|
||||
options.AddDocuments(new[] { "v1", "v2" });
|
||||
});
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "scalar/v1",
|
||||
"applicationUrl": "http://localhost:9000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "scalar/v1",
|
||||
"applicationUrl": "https://localhost:7241;http://localhost:9000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Log\**" />
|
||||
<Content Remove="Log\**" />
|
||||
<EmbeddedResource Remove="Log\**" />
|
||||
<None Remove="Log\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.10" />
|
||||
<PackageReference Include="Scalar.AspNetCore" Version="2.16.18" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Models\CloudProduct\Store.Modules.CloudProduct.csproj" />
|
||||
<ProjectReference Include="..\Store.Framework\Store.Framework.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,47 @@
|
||||
@StoreHub_HostAddress = http://localhost:5295
|
||||
|
||||
# ============ 认证(JWT) ============
|
||||
|
||||
### 登录:返回 accessToken(单点登录,同用户新登录会使旧 token 失效)
|
||||
# @name login
|
||||
POST {{StoreHub_HostAddress}}/api/v1/Auth/Login
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"userName": "18990011234",
|
||||
"password": "18990011234"
|
||||
}
|
||||
|
||||
### 获取当前登录用户信息(需携带 Bearer Token,先执行上面的 login)
|
||||
GET {{StoreHub_HostAddress}}/api/v1/Auth/Me
|
||||
Authorization: Bearer {{login.response.body.$.data.token}}
|
||||
|
||||
### 退出登录:销毁服务端会话,token 立即失效
|
||||
POST {{StoreHub_HostAddress}}/api/v1/Auth/Logout
|
||||
Authorization: Bearer {{login.response.body.$.data.token}}
|
||||
|
||||
### 在线人员列表(需携带 Bearer Token)
|
||||
GET {{StoreHub_HostAddress}}/api/v1/Auth/OnlineUsers
|
||||
Authorization: Bearer {{login.response.body.$.data.token}}
|
||||
|
||||
# ============ 示例接口 ============
|
||||
|
||||
### 模板自带的 WeatherForecast
|
||||
GET {{StoreHub_HostAddress}}/api/v1/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
POST {{StoreHub_HostAddress}}/api/v1/Auth/Login
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
//LoginRequest
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
POST {{StoreHub_HostAddress}}/api/v1/Auth/Login
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
//LoginRequest
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Store.Api
|
||||
{
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Store.Api
|
||||
{
|
||||
public class WeatherForecastV2
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public int FeelsLikeC { get; set; }
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=192.168.0.200;Port=3306;Database=mysql;Uid=root;Pwd=123456;",
|
||||
"KJDConnection": "Server=192.168.0.200;Port=3306;Database=mysql;Uid=root;Pwd=123456;",
|
||||
"ConnKJD": "Server=192.168.0.200;Port=3306;Database=mysql;Uid=root;Pwd=123456;"
|
||||
//"KJDConnection": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-hl51pkfr.sql.tencentcdb.com';Port=27660;User Id='kjd';Password='Temukjd0625';Charset=utf8mb4;",
|
||||
//"KJDBAKConnection": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-9s7x16mt.sql.tencentcdb.com';Port=24049;User Id='kjdbak';Password='Temukjd0126';Charset=utf8mb4;",
|
||||
//"ConnKJD": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-hl51pkfr.sql.tencentcdb.com';Port=27660;User Id='kjd';Password='Temukjd0625';Charset=utf8mb4;",
|
||||
//"ConnKJDBAK": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-9s7x16mt.sql.tencentcdb.com';Port=24049;User Id='kjdbak';Password='Temukjd0126';Charset=utf8mb4;"
|
||||
},
|
||||
"KJDConfig": {
|
||||
"UpdateVersion": "525",
|
||||
"UpdateFileDir": "C:\\inetpub\\wwwroot\\kjd_update",
|
||||
"UpdateNewUrl": "http://weidian.e57.cn/kjd_update/",
|
||||
"UpdateExe": "http://1.13.195.131:9000/Download/Update.exe",
|
||||
"UpdateExeChk": "CE4A009B7AA330314F03EEA0C3AB23F9",
|
||||
"LowVersion": "523",
|
||||
"LimitVersion": "823",
|
||||
"GetReturnPackage": "true",
|
||||
"GetWXRecommendHotProd": "true",
|
||||
"GetWXRecommendHotProdOncePerDay": "false",
|
||||
"GetWXRecommendHotProdMinViewUv": "200",
|
||||
"GetWXRecommendHotProdInterval": "3",
|
||||
"IsKeepBase64UploadImgFile": "0",
|
||||
"UpdateWxFindOrderFileDir": "C:\\inetpub\\wwwroot\\find_order_update",
|
||||
"UpdateWxFindOrderUrl": "http://weidian.e57.cn/find_order_update/",
|
||||
"WxFindOrderLimitVersion": "172",
|
||||
"WxFindOrderLowVersion": "99"
|
||||
},
|
||||
"Jwt": {
|
||||
"Issuer": "StoreHub",
|
||||
"Audience": "StoreHub.Client",
|
||||
"SigningKey": "StoreHub--Smxf8DtV8a5dFdaCVCXtFfWbmMRfw53ectEjr8JvhUjGpPP7fuBdRn",
|
||||
"ExpiresMinutes": 2880,
|
||||
"ClockSkewMinutes": 5,
|
||||
"ValidateIssuer": true,
|
||||
"ValidateAudience": true,
|
||||
"ValidateLifetime": true
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in new issue
Block a user