mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-03 00:00:58 +08:00
Compare commits
84 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e18af626b | ||
|
|
89dd5b79d6 | ||
|
|
356f71f13e | ||
|
|
2f5d71a299 | ||
|
|
b581c12edb | ||
|
|
d4d6aeb0b4 | ||
|
|
77114e6cfc | ||
|
|
e14a078440 | ||
|
|
3b38a0d628 | ||
|
|
927d8cb6c9 | ||
|
|
eb8ea2f549 | ||
|
|
208c93bc8f | ||
|
|
93180faa23 | ||
|
|
816858f231 | ||
|
|
fa1d68848f | ||
|
|
bce955a1e1 | ||
|
|
82f70e0ac9 | ||
|
|
fc9b78cfef | ||
|
|
72400a48da | ||
|
|
537b39b3c4 | ||
|
|
47e6e48729 | ||
|
|
d252229777 | ||
|
|
7f4c7f607d | ||
|
|
994ba5dd1a | ||
|
|
e3a06b28dd | ||
|
|
10d512470e | ||
|
|
c1d8040fd5 | ||
|
|
e4b81da386 | ||
|
|
fd7360e6f4 | ||
|
|
62f15e218e | ||
|
|
5c1b91f348 | ||
|
|
378cbd580f | ||
|
|
3994f14010 | ||
|
|
e7f4e743e3 | ||
|
|
b934ce2893 | ||
|
|
5eec076ea2 | ||
|
|
ada36ebff5 | ||
|
|
d9543ca23c | ||
|
|
3871eb3c84 | ||
|
|
4ba696d289 | ||
|
|
2f69e0b96c | ||
|
|
d6b0c56c35 | ||
|
|
d8fe983b9d | ||
|
|
76079faca0 | ||
|
|
5d5c62123c | ||
|
|
6c7b2224b1 | ||
|
|
4d80ae2372 | ||
|
|
c651b60c59 | ||
|
|
90b39d075d | ||
|
|
5099c7e462 | ||
|
|
2f8b5dd229 | ||
|
|
7e427605ab | ||
|
|
512e640c13 | ||
|
|
acb1c6cc99 | ||
|
|
d01c3ff9ca | ||
|
|
3720644153 | ||
|
|
630cfb6769 | ||
|
|
f3061ed643 | ||
|
|
2556c037ba | ||
|
|
0b4626a5a2 | ||
|
|
1c9e993194 | ||
|
|
dc3a465f09 | ||
|
|
6d008efd54 | ||
|
|
6aa970c375 | ||
|
|
1ecd01204b | ||
|
|
33bd8d1cd1 | ||
|
|
31d2c3c98e | ||
|
|
b082ec19aa | ||
|
|
9ccb496069 | ||
|
|
3871a7de84 | ||
|
|
c6931e3492 | ||
|
|
c8b2a38c99 | ||
|
|
a7bdcd8dd8 | ||
|
|
8196cd597a | ||
|
|
52deb6bb79 | ||
|
|
1a22aa0bfb | ||
|
|
d18e5eec99 | ||
|
|
0fcf172192 | ||
|
|
88b968e826 | ||
|
|
f15d99e168 | ||
|
|
bbeea2cf62 | ||
|
|
65ac020d72 | ||
|
|
3ed42384af | ||
|
|
d780529313 |
24
README.md
24
README.md
@@ -12,6 +12,8 @@
|
||||
### 简介:
|
||||
**中文:意框架**(和他的名字一样“简易”)
|
||||
|
||||
正在持续更进业务模块
|
||||
|
||||
**英文:YiFramework**
|
||||
|
||||
Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。
|
||||
@@ -20,7 +22,12 @@ Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。
|
||||
适合.Net6学习、Sqlsugar学习 、项目二次开发。
|
||||
集大成者,终究轮子
|
||||
|
||||
Yi框架最新版本标签:`v1.1.8`,具体版本可以查看标签迭代
|
||||
|
||||
(项目与Sqlsugar同步更新,但这作者老杰哥代码天天爆肝到凌晨两点,我们也尽量会跟上他的脚步。更新频繁,所以可watching持续关注。)
|
||||
|
||||
————这不仅仅是一个程序,更是一个艺术品,面向艺术的开发!
|
||||
|
||||
**分支**:
|
||||
|
||||
(本项目由EFCore版本历经3年不断迭代至Sqlsugar版本,现EFcore版本已弃用,目前sqlsugar不带任何业务,之后会更新业务功能)
|
||||
@@ -89,9 +96,8 @@ WebFirst开发:所有代码生成器已经配置完成,无需任何操作数
|
||||
- [x] 支持采用`异步`开发awit/async
|
||||
- [x] 支持数据库主从`读写分离`
|
||||
- [x] 支持功能替换,无需改动代码,只需配置`json文件`进行装配即可
|
||||
- [x] ~~-支持采用DbFirst开发方式,使用`T4模板代码生成器`,自动映射模型一键生成Service及IService所有代码~~
|
||||
- [x] 支持WebFirst,无需改动代码,自动生成全套代码与数据库,只需点点点
|
||||
- [x] ~~-支持`用户-角色-菜单-接口`以及vue2.0前端全部逻辑代码,下载无需修改直接使用~~
|
||||
- [x] 支持`用户-角色-菜单-接口`以及vue2.0前端全部逻辑代码,下载无需修改直接使用
|
||||
- [x] 支持`Aop封装`,FilterAop、IocAop、LogAop、SqlAop
|
||||
- [x] 支持`Log4Net日志`记录,自动生成至bin目录下的logs文件夹
|
||||
- [x] 支持`DbSeed数据库种子数据`接入
|
||||
@@ -107,7 +113,6 @@ WebFirst开发:所有代码生成器已经配置完成,无需任何操作数
|
||||
- [x] 支持`Ocelot`网关,路由、服务聚合、服务发现、认证、鉴权、限流、熔断、缓存、Header头传递
|
||||
- [x] 支持`Apollo`全局配置中心;
|
||||
- [x] 支持`docker`镜像制作
|
||||
- [x] ~~-支持页面`静态化处理`,将动态页面生成静态页面~~
|
||||
- [x] 支持`Quartz.net`任务调度,实现任意接口被调度
|
||||
- [x] 支持`ELK`,log4net+kafka+es+logstach+kibana
|
||||
- [x] 支持`IdentityService4`授权中心
|
||||
@@ -117,20 +122,23 @@ WebFirst开发:所有代码生成器已经配置完成,无需任何操作数
|
||||
- [x] 支持`Docker+k8s`部署
|
||||
- [x] 支持`Jenkins+CI/CD`
|
||||
- [x] 支持`AutoMapper`模块映射
|
||||
- [ ] 支持`微信支付`(没账号)
|
||||
- [x] 支持`微信支付`
|
||||
- [x] 支持`单表多租户`常用功能
|
||||
- [x] 支持`逻辑删除`常用功能
|
||||
- [x] 支持`操作日志`常用功能
|
||||
- [x] 支持`自动分表`
|
||||
- [x] 支持 太多了忘了
|
||||
|
||||
****
|
||||
### 目录结构:
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
我们大致依照DDD领域驱动设计分层
|
||||
|
||||
什么?感觉太复杂了?用户只需关注Api、Service其他都是轮子啊!
|
||||
分层如此清晰!什么?还感觉太复杂了?用户只需关注Api、Service其他都是轮子啊!
|
||||
|
||||
~~- BackGround:后台进程(目前可以无视,等待更新)~~
|
||||
- Client:客户端(测试、客户端)
|
||||
@@ -182,7 +190,9 @@ WebFirst开发:所有代码生成器已经配置完成,无需任何操作数
|
||||
****
|
||||
### 联系我们:
|
||||
|
||||
作者QQ:454313500
|
||||
作者QQ:`454313500`,2029年之前作者24小时在线,时刻保持活跃更新。
|
||||
|
||||
QQ交流群:官方一群(已满)、官方二群(已满)、官方三群:`786308927`(加作者QQ后同意)
|
||||
|
||||
联系作者,这里人人都是顾问
|
||||
|
||||
|
||||
Binary file not shown.
@@ -4,6 +4,51 @@
|
||||
<name>Yi.Framework.ApiMicroservice</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.AccountController">
|
||||
<summary>
|
||||
账户管理
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Login(Yi.Framework.DTOModel.LoginDto)">
|
||||
<summary>
|
||||
没啥说,登录
|
||||
</summary>
|
||||
<param name="loginDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Register(Yi.Framework.DTOModel.RegisterDto)">
|
||||
<summary>
|
||||
没啥说,注册
|
||||
</summary>
|
||||
<param name="registerDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Logout">
|
||||
<summary>
|
||||
没啥说,登出
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.GetUserAllInfo">
|
||||
<summary>
|
||||
通过已登录的用户获取用户信息及菜单
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.UpdatePassword(Yi.Framework.DTOModel.UpdatePasswordDto)">
|
||||
<summary>
|
||||
更新登录的用户密码
|
||||
</summary>
|
||||
<param name="updatePasswordDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.UpdateUserByHttp(Yi.Framework.Model.Models.UserEntity)">
|
||||
<summary>
|
||||
更新已登录用户的用户信息
|
||||
</summary>
|
||||
<param name="user"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1">
|
||||
<summary>
|
||||
Json To Sql 类比模式,通用模型
|
||||
@@ -51,12 +96,92 @@
|
||||
<param name="ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.FileController">
|
||||
<summary>
|
||||
文件
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.FileController.#ctor(Yi.Framework.Interface.IUserService,Microsoft.Extensions.Hosting.IHostEnvironment)">
|
||||
<summary>
|
||||
使用本地存储,未进行数据库记录
|
||||
</summary>
|
||||
<param name="iUserService"></param>
|
||||
<param name="env"></param>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.FileController.Get(System.String,System.String)">
|
||||
<summary>
|
||||
文件下载
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
<param name="fileName"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.FileController.Upload(System.String,Microsoft.AspNetCore.Http.IFormFile)">
|
||||
<summary>
|
||||
文件上传
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
<param name="file"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.LogController.Add">
|
||||
<summary>
|
||||
自动分表,日志添加
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.LogController.GetList">
|
||||
<summary>
|
||||
查询近20年与21年的日志表
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.MenuController">
|
||||
<summary>
|
||||
菜单管理
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.MenuController.GetMenuTree">
|
||||
<summary>
|
||||
得到树形菜单
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.RoleController">
|
||||
<summary>
|
||||
角色管理
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.GiveRoleSetMenu(Yi.Framework.DTOModel.GiveRoleSetMenuDto)">
|
||||
<summary>
|
||||
给多用户设置多角色
|
||||
</summary>
|
||||
<param name="giveRoleSetMenuDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.GetInMenuByRoleId(System.Int64)">
|
||||
<summary>
|
||||
通过角色id来获取菜单列表
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.TestController">
|
||||
<summary>
|
||||
测试控制器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.DbTest">
|
||||
<summary>
|
||||
仓储上下文对象测试
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.SqlTest">
|
||||
<summary>
|
||||
执行Sql返回
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.LocalTest">
|
||||
<summary>
|
||||
国际化测试
|
||||
@@ -69,7 +194,7 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.AutnTest">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.AuthTest">
|
||||
<summary>
|
||||
策略授权测试
|
||||
</summary>
|
||||
@@ -81,5 +206,48 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.IncludeTest">
|
||||
<summary>
|
||||
极爽导航属性
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.JobTest">
|
||||
<summary>
|
||||
启动一个定时任务
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.stopJob">
|
||||
<summary>
|
||||
停止任务
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.UserController">
|
||||
<summary>
|
||||
用户管理
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.Add(Yi.Framework.Model.Models.UserEntity)">
|
||||
<summary>
|
||||
添加用户,去重,密码加密
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.GiveUserSetRole(Yi.Framework.DTOModel.GiveUserSetRoleDto)">
|
||||
<summary>
|
||||
给多用户设置多角色
|
||||
</summary>
|
||||
<param name="giveUserSetRoleDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.GetRoleListByUserId(System.Int64)">
|
||||
<summary>
|
||||
通过用户id得到角色列表
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.DTOModel;
|
||||
@@ -17,30 +18,46 @@ using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 账户管理
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class AccountController :ControllerBase
|
||||
public class AccountController : ControllerBase
|
||||
{
|
||||
private IUserService _iUserService;
|
||||
private IUserService _iUserService;
|
||||
private JwtInvoker _jwtInvoker;
|
||||
private ILogger _logger;
|
||||
public AccountController(ILogger<UserEntity> logger, IUserService iUserService, JwtInvoker jwtInvoker)
|
||||
{
|
||||
_iUserService = iUserService;
|
||||
_jwtInvoker = jwtInvoker;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 没啥说,登录
|
||||
/// </summary>
|
||||
/// <param name="loginDto"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
public async Task<Result> Login(LoginDto loginDto)
|
||||
{
|
||||
UserEntity user=new();
|
||||
if (await _iUserService.Login(loginDto.UserName, loginDto.Password,o=> user=o))
|
||||
UserEntity user = new();
|
||||
if (await _iUserService.Login(loginDto.UserName, loginDto.Password, o => user = o))
|
||||
{
|
||||
return Result.Success("登录成功!").SetData(new { user, token = _jwtInvoker.GetAccessToken(user)});
|
||||
var userRoleMenu= await _iUserService.GetUserAllInfo(user.Id);
|
||||
return Result.Success("登录成功!").SetData(new { token = _jwtInvoker.GetAccessToken(userRoleMenu.User,userRoleMenu.Menus) });
|
||||
}
|
||||
return Result.SuccessError("登录失败!用户名或者密码错误!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 没啥说,注册
|
||||
/// </summary>
|
||||
/// <param name="registerDto"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
public async Task<Result> Register(RegisterDto registerDto)
|
||||
@@ -52,5 +69,68 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
}
|
||||
return Result.SuccessError("注册失败!用户名已存在!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 没啥说,登出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public Result Logout()
|
||||
{
|
||||
return Result.Success("安全登出成功!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过已登录的用户获取用户信息及菜单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<Result> GetUserAllInfo()
|
||||
{
|
||||
//通过鉴权jwt获取到用户的id
|
||||
var userId = HttpContext.GetCurrentUserEntityInfo(out _).Id;
|
||||
|
||||
return Result.Success().SetData(await _iUserService.GetUserAllInfo(userId));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新登录的用户密码
|
||||
/// </summary>
|
||||
/// <param name="updatePasswordDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdatePassword(UpdatePasswordDto updatePasswordDto)
|
||||
{
|
||||
var userId = HttpContext.GetCurrentUserEntityInfo(out _).Id;
|
||||
var userEntiy = await _iUserService._repository.GetByIdAsync(userId);
|
||||
|
||||
//判断输入的老密码是否和原密码相同
|
||||
if (_iUserService.JudgePassword(userEntiy, updatePasswordDto.OldPassword))
|
||||
{
|
||||
userEntiy.Password = updatePasswordDto.NewPassword;
|
||||
userEntiy.BuildPassword();
|
||||
return Result.Success().SetStatus(await _iUserService._repository.UpdateAsync(userEntiy));
|
||||
}
|
||||
return Result.SuccessError("原密码错误!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新已登录用户的用户信息
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateUserByHttp(UserEntity user)
|
||||
{
|
||||
//当然,密码是不能给他修改的
|
||||
user.Password = null;
|
||||
user.Salt = null;
|
||||
|
||||
//修改需要赋值上主键哦
|
||||
user.Id = HttpContext.GetCurrentUserEntityInfo(out _).Id;
|
||||
return Result.Success().SetStatus(await _iUserService._repository.UpdateIgnoreNullAsync(user));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class BaseCrudController<T> : ControllerBase where T : BaseModelEntity,new()
|
||||
public class BaseCrudController<T> : ControllerBase where T : class, IBaseModelEntity,new()
|
||||
{
|
||||
public readonly ILogger<T> _logger;
|
||||
public IBaseService<T> _baseService;
|
||||
public IRepository<T> _repository;
|
||||
private readonly ILogger<T> _logger;
|
||||
private IBaseService<T> _baseService;
|
||||
private IRepository<T> _repository;
|
||||
public BaseCrudController(ILogger<T> logger, IBaseService<T> iBaseService)
|
||||
{
|
||||
_logger = logger;
|
||||
@@ -33,9 +32,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get:one")]
|
||||
[Permission($"{nameof(T)}:get")]
|
||||
[HttpGet]
|
||||
public async Task<Result> GetById(long id)
|
||||
public virtual async Task<Result> GetById(long id)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.GetByIdAsync(id));
|
||||
}
|
||||
@@ -44,9 +43,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// 列表查询
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get:list")]
|
||||
[Permission($"{nameof(T)}:get")]
|
||||
[HttpPost]
|
||||
public async Task<Result> GetList(QueryCondition queryCondition)
|
||||
public virtual async Task<Result> GetList(QueryCondition queryCondition)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.GetListAsync(queryCondition));
|
||||
}
|
||||
@@ -56,9 +55,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <param name="queryCondition"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get:page")]
|
||||
[Permission($"{nameof(T)}:get")]
|
||||
[HttpPost]
|
||||
public async Task<Result> PageList(QueryPageCondition queryCondition)
|
||||
public virtual async Task<Result> PageList(QueryPageCondition queryCondition)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.CommonPageAsync(queryCondition));
|
||||
}
|
||||
@@ -70,7 +69,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:add")]
|
||||
[HttpPost]
|
||||
public async Task<Result> Add(T entity)
|
||||
public virtual async Task<Result> Add(T entity)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.InsertReturnSnowflakeIdAsync(entity));
|
||||
}
|
||||
@@ -82,7 +81,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:update")]
|
||||
[HttpPut]
|
||||
public async Task<Result> Update(T entity)
|
||||
public virtual async Task<Result> Update(T entity)
|
||||
{
|
||||
return Result.Success().SetStatus(await _repository.UpdateIgnoreNullAsync(entity));
|
||||
}
|
||||
@@ -92,9 +91,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:delete:list")]
|
||||
[Permission($"{nameof(T)}:del")]
|
||||
[HttpDelete]
|
||||
public async Task<Result> DeleteList(List<long> ids)
|
||||
public virtual async Task<Result> DeleteList(List<long> ids)
|
||||
{
|
||||
return Result.Success().SetStatus(await _repository.DeleteByLogicAsync(ids));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.WebCore;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class FileController : ControllerBase
|
||||
{
|
||||
private IUserService _iUserService;
|
||||
private readonly IHostEnvironment _env;
|
||||
/// <summary>
|
||||
/// 使用本地存储,未进行数据库记录
|
||||
/// </summary>
|
||||
/// <param name="iUserService"></param>
|
||||
/// <param name="env"></param>
|
||||
public FileController(IUserService iUserService, IHostEnvironment env)
|
||||
{
|
||||
_iUserService = iUserService;
|
||||
_env = env;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件下载
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
[Route("/api/{type}/{fileName}")]
|
||||
[HttpGet]
|
||||
public IActionResult Get(string type, string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = Path.Combine($"wwwroot/{type}", fileName);
|
||||
var stream = System.IO.File.OpenRead(path);
|
||||
var MimeType = Common.Helper.MimeHelper.GetMimeMapping(fileName);
|
||||
return new FileStreamResult(stream, MimeType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件上传
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
[Route("/api/Upload/{type}")]
|
||||
[HttpPost]
|
||||
public async Task<Result> Upload(string type, IFormFile file)
|
||||
{
|
||||
try
|
||||
{
|
||||
string filename = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
|
||||
using (var stream = new FileStream(Path.Combine($"wwwroot/{type}", filename), FileMode.CreateNew, FileAccess.Write))
|
||||
{
|
||||
await file.CopyToAsync(stream);
|
||||
}
|
||||
return Result.Success().SetData(filename);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Result.Error();
|
||||
}
|
||||
}
|
||||
|
||||
//[HttpGet]
|
||||
//public async Task<IActionResult> ExportFile()
|
||||
//{
|
||||
// var userdata = await _userService.GetAllEntitiesTrueAsync();
|
||||
// var userList = userdata.ToList();
|
||||
// List<string> header = new() { "用户", "密码", "头像", "昵称", "邮箱", "ip", "年龄", "个人介绍", "地址", "手机", "角色" };
|
||||
// var filename = Common.Helper.ExcelHelper.CreateExcelFromList(userList, header, _env.ContentRootPath.ToString());
|
||||
// var MimeType = Common.Helper.MimeHelper.GetMimeMapping(filename);
|
||||
// return new FileStreamResult(new FileStream(Path.Combine(_env.ContentRootPath+@"/wwwroot/excel", filename), FileMode.Open),MimeType);
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class LogController : ControllerBase
|
||||
{
|
||||
private ILogService _iLogService;
|
||||
//大量日志,将采用自动分表形式,默认1年分一次表
|
||||
public LogController(ILogger<LogEntity> logger, ILogService iLogService)
|
||||
{
|
||||
_iLogService = iLogService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动分表,日志添加
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> Add()
|
||||
{
|
||||
Random random = new Random();
|
||||
var logList = new List<LogEntity>() {
|
||||
new LogEntity() { LogCreateTime = Convert.ToDateTime("2019-12-1"), Message = "jack"+random.Next() } ,
|
||||
new LogEntity() { LogCreateTime = Convert.ToDateTime("2022-02-1"), Message = "jack"+random.Next() },
|
||||
new LogEntity() { LogCreateTime = Convert.ToDateTime("2020-02-1"), Message = "jack"+random.Next() },
|
||||
new LogEntity() { LogCreateTime = Convert.ToDateTime("2021-12-1"), Message = "jack"+random.Next() } };
|
||||
return Result.Success().SetData(await _iLogService.AddListTest(logList));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询近20年与21年的日志表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetList()
|
||||
{
|
||||
return Result.Success().SetData(await _iLogService.GetListTest());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜单管理
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class MenuController : BaseCrudController<MenuEntity>
|
||||
{
|
||||
private IMenuService _iMenuService;
|
||||
public MenuController(ILogger<MenuEntity> logger, IMenuService iMenuService) : base(logger, iMenuService)
|
||||
{
|
||||
_iMenuService = iMenuService;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 得到树形菜单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
//暂未制作逻辑删除与多租户的过滤
|
||||
public async Task<Result> GetMenuTree()
|
||||
{
|
||||
return Result.Success().SetData(await _iMenuService. GetMenuTreeAsync());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色管理
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class RoleController : BaseCrudController<RoleEntity>
|
||||
{
|
||||
private IRoleService _iRoleService;
|
||||
public RoleController(ILogger<RoleEntity> logger, IRoleService iRoleService) : base(logger, iRoleService)
|
||||
{
|
||||
_iRoleService = iRoleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给多用户设置多角色
|
||||
/// </summary>
|
||||
/// <param name="giveRoleSetMenuDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> GiveRoleSetMenu(GiveRoleSetMenuDto giveRoleSetMenuDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRoleService.GiveRoleSetMenu(giveRoleSetMenuDto.RoleIds, giveRoleSetMenuDto.MenuIds));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色id来获取菜单列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetInMenuByRoleId(long RoleId)
|
||||
{
|
||||
return Result.Success().SetData(await _iRoleService.GetInMenuByRoleId(RoleId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Language;
|
||||
using Yi.Framework.Model.Models;
|
||||
@@ -17,17 +19,24 @@ using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 测试控制器
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class TestController : ControllerBase
|
||||
{
|
||||
private IStringLocalizer<LocalLanguage> _local;
|
||||
private IUserService _iUserService;
|
||||
private IRoleService _iRoleService;
|
||||
private QuartzInvoker _quartzInvoker;
|
||||
//你可以依赖注入服务层各各接口,也可以注入其他仓储层,怎么爽怎么来!
|
||||
public TestController(ILogger<UserEntity> logger, IUserService iUserService, IStringLocalizer<LocalLanguage> local)
|
||||
public TestController(ILogger<UserEntity> logger, IRoleService iRoleService, IUserService iUserService, IStringLocalizer<LocalLanguage> local, QuartzInvoker quartzInvoker)
|
||||
{
|
||||
_local = local;
|
||||
_iUserService = iUserService;
|
||||
_iRoleService = iRoleService;
|
||||
_quartzInvoker = quartzInvoker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -36,30 +45,41 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
// 特点:化繁为简!意框架仓储代理上下文对象,用起来就是爽,但最好按规范来爽!
|
||||
// 规范:控制器建议不要使用切换仓储方法,控制器严禁使用DB上下文对象,其它怎么爽怎么来!
|
||||
// 规范:控制器严禁使用DB上下文对象,其它怎么爽怎么来!
|
||||
public async Task<Result> DbTest()
|
||||
{
|
||||
//非常好,使用UserService的特有方法
|
||||
await _iUserService.DbTest();
|
||||
|
||||
//非常好,依赖注入使用其他Service的特有方法(就tm一张表,自己注入自己)
|
||||
await _iUserService.DbTest();
|
||||
//非常好,依赖注入使用其他Service的特有方法
|
||||
await _iRoleService.DbTest();
|
||||
|
||||
//很核理,使用仓储的通用方法
|
||||
await _iUserService._repository.GetListAsync();
|
||||
|
||||
//挺不错,依赖注入其他仓储(就tm一张表,自己注入自己)
|
||||
await _iUserService._repository.GetListAsync();
|
||||
//挺不错,依赖注入其他仓储
|
||||
await _iRoleService._repository.GetListAsync();
|
||||
|
||||
//不建议,但爽了再说,直接切换其他仓储(就tm一张表,自己切换自己)
|
||||
await _iUserService._repository.ChangeRepository<Repository<UserEntity>>().GetListAsync();
|
||||
//还行,直接切换其他仓储,怎么爽怎么来
|
||||
await _iUserService._repository.ChangeRepository<Repository<RoleEntity>>().GetListAsync();
|
||||
|
||||
//恭喜你已经毕业了!此后将有一天,接手到这个的软件的程序员将破口大骂。
|
||||
//最好不要直接操作Db对象
|
||||
await _iUserService._repository._Db.Queryable<UserEntity>().ToListAsync();
|
||||
|
||||
return Result.Success().SetData(await _iUserService.DbTest());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行Sql返回
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
//简单语句不推荐使用sql!
|
||||
public async Task<Result> SqlTest()
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService._repository.UseSqlAsync<UserEntity>("select * from User"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 国际化测试
|
||||
/// </summary>
|
||||
@@ -88,7 +108,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Authorize(PolicyName.Sid)]
|
||||
public Result AutnTest()
|
||||
public Result AuthTest()
|
||||
{
|
||||
return Result.Success();
|
||||
}
|
||||
@@ -121,6 +141,43 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
|
||||
}
|
||||
|
||||
//emmmm,看来一张表已经满足不了,接下来将要大更新一波
|
||||
/// <summary>
|
||||
/// 极爽导航属性
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
//Sqlsugar精髓之一!必学!最新版本
|
||||
public async Task<Result> IncludeTest()
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService.GetListInRole());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动一个定时任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
//每5秒访问一次百度,可查看控制台
|
||||
public async Task<Result> JobTest()
|
||||
{
|
||||
Dictionary<string, object> data = new Dictionary<string, object>()
|
||||
{
|
||||
{JobConst.method,"get" },
|
||||
{JobConst.url,"https://www.baidu.com" }
|
||||
};
|
||||
await _quartzInvoker.start("*/5 * * * * ?", new Quartz.JobKey("test", "my"), "Yi.Framework.Job", "HttpJob", data: data);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> stopJob()
|
||||
{
|
||||
await _quartzInvoker.Stop(new Quartz.JobKey("test", "my"));
|
||||
return Result.Success();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
@@ -15,6 +16,9 @@ using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户管理
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class UserController : BaseCrudController<UserEntity>
|
||||
@@ -24,5 +28,44 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
_iUserService = iUserService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户,去重,密码加密
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(UserEntity)}:add")]
|
||||
[HttpPost]
|
||||
public override async Task<Result> Add(UserEntity entity)
|
||||
{
|
||||
if (!await _iUserService.Exist(entity.UserName))
|
||||
{
|
||||
entity.BuildPassword();
|
||||
return Result.Success().SetData(await _iUserService._repository.InsertReturnSnowflakeIdAsync(entity));
|
||||
}
|
||||
return Result.SuccessError("用户已存在");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给多用户设置多角色
|
||||
/// </summary>
|
||||
/// <param name="giveUserSetRoleDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> GiveUserSetRole(GiveUserSetRoleDto giveUserSetRoleDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iUserService.GiveUserSetRole(giveUserSetRoleDto.UserIds, giveUserSetRoleDto.RoleIds));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户id得到角色列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetRoleListByUserId(long userId)
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService.GetRoleListByUserId(userId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ ServiceLocator.Instance = app.Services;
|
||||
#region
|
||||
//错误抓取反馈注入
|
||||
#endregion
|
||||
//app.UseErrorHandlingService();
|
||||
app.UseErrorHandlingService();
|
||||
#region
|
||||
//静态文件注入
|
||||
#endregion
|
||||
|
||||
@@ -20,6 +20,16 @@
|
||||
<None Remove="wwwrooot\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="yi-sqlsugar-dev.db" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="yi-sqlsugar-dev.db">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.DTOModel\Yi.Framework.DTOModel.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Interface\Yi.Framework.Interface.csproj" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"StartUrl": "http://localohost:19001",
|
||||
"StartUrl": "http://*:19001",
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"StartUrl": "http://localohost:19001",
|
||||
"StartUrl": "http://*:19001",
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
"PolicyName": "permission",
|
||||
"DefaultScheme": "Bearer",
|
||||
"IsHttps": false,
|
||||
"Expiration": 30,
|
||||
"Expiration": 300,
|
||||
"ReExpiration": 3000
|
||||
},
|
||||
"RedisConnOptions": {
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
@@ -61,6 +61,7 @@ namespace Yi.Framework.Common.Helper
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
|
||||
request.CookieContainer = cookie;
|
||||
|
||||
Stream myRequestStream = request.GetRequestStream();
|
||||
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
|
||||
myStreamWriter.Write(postDataStr);
|
||||
|
||||
@@ -10,5 +10,7 @@ namespace Yi.Framework.Common.IOCOptions
|
||||
{
|
||||
public string Url { get; set; }
|
||||
public string IndexName { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string PassWord { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,14 @@ namespace Yi.Framework.Common.Models
|
||||
}
|
||||
public Result SetStatus(bool _status)
|
||||
{
|
||||
if (_status)
|
||||
{
|
||||
this.message = "操作成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.message = "操作失败";
|
||||
}
|
||||
this.status = _status;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Yi.Framework.Core
|
||||
public ElasticSearchInvoker(IOptionsMonitor<ElasticSearchOptions> optionsMonitor)
|
||||
{
|
||||
_elasticSearchOptions = optionsMonitor.CurrentValue;
|
||||
var settings = new ConnectionSettings(new Uri(_elasticSearchOptions.Url)).DefaultIndex(this._elasticSearchOptions.IndexName);
|
||||
var settings = new ConnectionSettings(new Uri(_elasticSearchOptions.Url)).DefaultIndex(this._elasticSearchOptions.IndexName).BasicAuthentication(this._elasticSearchOptions.UserName, this._elasticSearchOptions.PassWord); ;
|
||||
Client = new ElasticClient(settings);
|
||||
}
|
||||
private ElasticClient Client;
|
||||
|
||||
@@ -23,15 +23,15 @@ namespace Yi.Framework.Core
|
||||
}
|
||||
public string GetRefreshToken(UserEntity user)
|
||||
{
|
||||
return this.GetToken(_JWTTokenOptions.ReExpiration, user, true);
|
||||
return this.GetToken(_JWTTokenOptions.ReExpiration, user,null, true);
|
||||
}
|
||||
|
||||
public string GetAccessToken(UserEntity user)
|
||||
public string GetAccessToken(UserEntity user,HashSet<MenuEntity> menus)
|
||||
{
|
||||
return this.GetToken(_JWTTokenOptions.Expiration, user);
|
||||
return this.GetToken(_JWTTokenOptions.Expiration, user, menus);
|
||||
}
|
||||
|
||||
private string GetToken(int minutes, UserEntity user, bool isRefresh = false)
|
||||
private string GetToken(int minutes, UserEntity user, HashSet<MenuEntity> menus,bool isRefresh = false)
|
||||
{
|
||||
List<Claim> claims = new List<Claim>();
|
||||
claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"));
|
||||
@@ -39,8 +39,11 @@ namespace Yi.Framework.Core
|
||||
claims.Add(new Claim(JwtRegisteredClaimNames.Sid, user.Id.ToString()));
|
||||
|
||||
//-----------------------------以下从user的权限表中添加权限-----------------------例如:
|
||||
claims.Add(new Claim("permission", "userentity:get:list"));
|
||||
claims.Add(new Claim("permission", "userentity:get:one"));
|
||||
|
||||
foreach (var m in menus)
|
||||
{
|
||||
claims.Add(new Claim("permission", m.PermissionCode.ToString()));
|
||||
}
|
||||
|
||||
if (isRefresh)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class GiveRoleSetMenuDto
|
||||
{
|
||||
public List<long> RoleIds { get; set; }
|
||||
public List<long> MenuIds { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class GiveUserSetRoleDto
|
||||
{
|
||||
public List<long> UserIds { get; set; }
|
||||
public List<long> RoleIds { get; set;}
|
||||
}
|
||||
}
|
||||
14
Yi.Framework.Net6/Yi.Framework.DTOModel/UpdatePasswordDto.cs
Normal file
14
Yi.Framework.Net6/Yi.Framework.DTOModel/UpdatePasswordDto.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class UpdatePasswordDto
|
||||
{
|
||||
public string NewPassword { get; set; }
|
||||
public string OldPassword { get; set; }
|
||||
}
|
||||
}
|
||||
17
Yi.Framework.Net6/Yi.Framework.DTOModel/UserRoleMenuDto.cs
Normal file
17
Yi.Framework.Net6/Yi.Framework.DTOModel/UserRoleMenuDto.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class UserRoleMenuDto
|
||||
{
|
||||
public UserEntity User { get; set; }=new ();
|
||||
public HashSet<RoleEntity> Roles { get; set; } = new();
|
||||
public HashSet<MenuEntity> Menus { get; set; }=new();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public interface IBaseService<T> where T:BaseModelEntity,new()
|
||||
public interface IBaseService<T> where T: class, IBaseModelEntity,new()
|
||||
{
|
||||
public IRepository<T> _repository { get; set; }
|
||||
}
|
||||
|
||||
13
Yi.Framework.Net6/Yi.Framework.Interface/ILogService.cs
Normal file
13
Yi.Framework.Net6/Yi.Framework.Interface/ILogService.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface ILogService
|
||||
{
|
||||
Task<List<long>> AddListTest(List<LogEntity> logEntities);
|
||||
Task<List<LogEntity>> GetListTest();
|
||||
}
|
||||
}
|
||||
12
Yi.Framework.Net6/Yi.Framework.Interface/IMenuService.cs
Normal file
12
Yi.Framework.Net6/Yi.Framework.Interface/IMenuService.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IMenuService:IBaseService<MenuEntity>
|
||||
{
|
||||
Task<List<MenuEntity>> GetMenuTreeAsync();
|
||||
}
|
||||
}
|
||||
31
Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
Normal file
31
Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IRoleService
|
||||
{
|
||||
/// <summary>
|
||||
/// DbTest
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<RoleEntity>> DbTest();
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色id获取角色实体包含菜单
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RoleEntity> GetInMenuByRoleId(long roleId);
|
||||
|
||||
/// <summary>
|
||||
/// 给角色设置菜单,多角色,多菜单
|
||||
/// </summary>
|
||||
/// <param name="roleIds"></param>
|
||||
/// <param name="menuIds"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> GiveRoleSetMenu(List<long> roleIds, List<long> menuIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface ILogService : IBaseService<LogEntity>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IMenuService : IBaseService<MenuEntity>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IRoleService:IBaseService<RoleEntity>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
@@ -12,7 +13,7 @@ namespace Yi.Framework.Interface
|
||||
/// 测试仓储的上下文对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<List<UserEntity>> DbTest();
|
||||
Task<List<UserEntity>> DbTest();
|
||||
|
||||
/// <summary>
|
||||
/// 登录方法
|
||||
@@ -21,7 +22,7 @@ namespace Yi.Framework.Interface
|
||||
/// <param name="password"></param>
|
||||
/// <param name="userAction"></param>
|
||||
/// <returns></returns>
|
||||
public Task<bool> Login(string userName, string password, Action<UserEntity> userAction = null);
|
||||
Task<bool> Login(string userName, string password, Action<UserEntity> userAction = null);
|
||||
|
||||
/// <summary>
|
||||
/// 注册方法
|
||||
@@ -29,6 +30,50 @@ namespace Yi.Framework.Interface
|
||||
/// <param name="userEntity"></param>
|
||||
/// <param name="userAction"></param>
|
||||
/// <returns></returns>
|
||||
public Task<bool> Register(UserEntity userEntity, Action<UserEntity> userAction = null);
|
||||
Task<bool> Register(UserEntity userEntity, Action<UserEntity> userAction = null);
|
||||
|
||||
/// <summary>
|
||||
/// 导航属性关联角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<UserEntity>> GetListInRole();
|
||||
|
||||
/// <summary>
|
||||
/// 给用户设置角色,多用户,多角色
|
||||
/// </summary>
|
||||
/// <param name="userIds"></param>
|
||||
/// <param name="roleIds"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> GiveUserSetRole(List<long> userIds, List<long> roleIds);
|
||||
|
||||
/// <summary>
|
||||
/// 判断用户名是否存在,如果存在可返回该用户
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="userAction"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> Exist(string userName, Action<UserEntity> userAction = null);
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户id得到角色列表
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<RoleEntity>> GetRoleListByUserId(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前登录用户的所有信息
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<UserRoleMenuDto> GetUserAllInfo(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 判断用户密码是否和原密码相同
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
bool JudgePassword(UserEntity user, string password);
|
||||
}
|
||||
}
|
||||
|
||||
18
Yi.Framework.Net6/Yi.Framework.Model/LogEntity.cs
Normal file
18
Yi.Framework.Net6/Yi.Framework.Model/LogEntity.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志表
|
||||
///</summary>
|
||||
[SplitTable(SplitType.Year)]
|
||||
[SugarTable("SplitLog_{year}{month}{day}")]
|
||||
public partial class LogEntity
|
||||
{
|
||||
[SplitField] //分表字段 在插入的时候会根据这个字段插入哪个表,在更新删除的时候用这个字段找出相关表
|
||||
public DateTime? LogCreateTime { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
15
Yi.Framework.Net6/Yi.Framework.Model/MenuEntity.cs
Normal file
15
Yi.Framework.Net6/Yi.Framework.Model/MenuEntity.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜单表
|
||||
///</summary>
|
||||
public partial class MenuEntity
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public List<MenuEntity> Children { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public abstract class BaseModelEntity
|
||||
{
|
||||
public BaseModelEntity()
|
||||
{
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
/// <summary>
|
||||
/// 1
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
/// 创建者
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "CreateUser")]
|
||||
public long? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
/// 修改者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "ModifyUser")]
|
||||
public long? ModifyUser { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "CreateTime")]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "ModifyTime")]
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "IsDeleted")]
|
||||
public bool? IsDeleted { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarTable("User")]
|
||||
public partial class UserEntity:BaseModelEntity
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Name" )]
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Age" )]
|
||||
public int? Age { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="UserName" )]
|
||||
public string UserName { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Password" )]
|
||||
public string Password { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Salt" )]
|
||||
public string Salt { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public interface IBaseModelEntity
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
public long? CreateUser { get; set; }
|
||||
|
||||
public long? ModifyUser { get; set; }
|
||||
|
||||
public DateTime? CreateTime { get; set; }
|
||||
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
public bool? IsDeleted { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志表
|
||||
///</summary>
|
||||
public partial class LogEntity:IBaseModelEntity
|
||||
{
|
||||
public LogEntity()
|
||||
{
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
/// <summary>
|
||||
/// 1
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateUser" )]
|
||||
public long? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateTime" )]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 修改者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyUser" )]
|
||||
public long? ModifyUser { get; set; }
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyTime" )]
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="IsDeleted" )]
|
||||
public bool? IsDeleted { get; set; }
|
||||
/// <summary>
|
||||
/// 租户Id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
/// <summary>
|
||||
/// 消息
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Message" )]
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜单表
|
||||
///</summary>
|
||||
[SugarTable("Menu")]
|
||||
public partial class MenuEntity:IBaseModelEntity
|
||||
{
|
||||
public MenuEntity()
|
||||
{
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="MenuName" )]
|
||||
public string MenuName { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="MenuType" )]
|
||||
public int? MenuType { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="PermissionCode" )]
|
||||
public string PermissionCode { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ParentId" )]
|
||||
public long? ParentId { get; set; }
|
||||
/// <summary>
|
||||
/// 创建者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateUser" )]
|
||||
public long? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateTime" )]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 修改者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyUser" )]
|
||||
public long? ModifyUser { get; set; }
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyTime" )]
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="IsDeleted" )]
|
||||
public bool? IsDeleted { get; set; }
|
||||
/// <summary>
|
||||
/// 租户Id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="MenuIcon" )]
|
||||
public string MenuIcon { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Router" )]
|
||||
public string Router { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色表
|
||||
///</summary>
|
||||
[SugarTable("Role")]
|
||||
public partial class RoleEntity:IBaseModelEntity
|
||||
{
|
||||
public RoleEntity()
|
||||
{
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="RoleName" )]
|
||||
public string RoleName { get; set; }
|
||||
/// <summary>
|
||||
/// 创建者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateUser" )]
|
||||
public long? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateTime" )]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyTime" )]
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="IsDeleted" )]
|
||||
public bool? IsDeleted { get; set; }
|
||||
/// <summary>
|
||||
/// 租户Id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
/// <summary>
|
||||
/// 修改者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyUser" )]
|
||||
public long? ModifyUser { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="RoleCode" )]
|
||||
public string RoleCode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色菜单关系表
|
||||
///</summary>
|
||||
[SugarTable("RoleMenu")]
|
||||
public partial class RoleMenuEntity:IBaseModelEntity
|
||||
{
|
||||
public RoleMenuEntity()
|
||||
{
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="RoleId" )]
|
||||
public long? RoleId { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="MenuId" )]
|
||||
public long? MenuId { get; set; }
|
||||
/// <summary>
|
||||
/// 创建者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateUser" )]
|
||||
public long? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateTime" )]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 修改者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyUser" )]
|
||||
public long? ModifyUser { get; set; }
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyTime" )]
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="IsDeleted" )]
|
||||
public bool? IsDeleted { get; set; }
|
||||
/// <summary>
|
||||
/// 租户Id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 租户表
|
||||
///</summary>
|
||||
[SugarTable("Tenant")]
|
||||
public partial class TenantEntity:IBaseModelEntity
|
||||
{
|
||||
public TenantEntity()
|
||||
{
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantName" )]
|
||||
public string TenantName { get; set; }
|
||||
/// <summary>
|
||||
/// 创建者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateUser" )]
|
||||
public long? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateTime" )]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 修改者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyUser" )]
|
||||
public long? ModifyUser { get; set; }
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyTime" )]
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="IsDeleted" )]
|
||||
public bool? IsDeleted { get; set; }
|
||||
/// <summary>
|
||||
/// 租户Id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户表
|
||||
///</summary>
|
||||
[SugarTable("User")]
|
||||
public partial class UserEntity:IBaseModelEntity
|
||||
{
|
||||
public UserEntity()
|
||||
{
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Name" )]
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Age" )]
|
||||
public int? Age { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateUser" )]
|
||||
public long? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateTime" )]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyUser" )]
|
||||
public long? ModifyUser { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyTime" )]
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="IsDeleted" )]
|
||||
public bool? IsDeleted { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="UserName" )]
|
||||
public string UserName { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Password" )]
|
||||
public string Password { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Salt" )]
|
||||
public string Salt { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Icon" )]
|
||||
public string Icon { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Nick" )]
|
||||
public string Nick { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Email" )]
|
||||
public string Email { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Ip" )]
|
||||
public string Ip { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Address" )]
|
||||
public string Address { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Phone" )]
|
||||
public string Phone { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Introduction" )]
|
||||
public string Introduction { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户角色关系表
|
||||
///</summary>
|
||||
[SugarTable("UserRole")]
|
||||
public partial class UserRoleEntity:IBaseModelEntity
|
||||
{
|
||||
public UserRoleEntity()
|
||||
{
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="RoleId" )]
|
||||
public long? RoleId { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="UserId" )]
|
||||
public long? UserId { get; set; }
|
||||
/// <summary>
|
||||
/// 创建者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateUser" )]
|
||||
public long? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateTime" )]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyTime" )]
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="IsDeleted" )]
|
||||
public bool? IsDeleted { get; set; }
|
||||
/// <summary>
|
||||
/// 租户Id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
/// <summary>
|
||||
/// 修改者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyUser" )]
|
||||
public long? ModifyUser { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ namespace Yi.Framework.Model.Query
|
||||
public List<QueryParameter> Parameters { get; set; } = new List<QueryParameter>();
|
||||
public List<string> OrderBys { get; set; } = new List<string>();
|
||||
|
||||
public bool IsAsc { get; set; } = false;
|
||||
}
|
||||
|
||||
public class QueryCondition
|
||||
@@ -21,5 +22,7 @@ namespace Yi.Framework.Model.Query
|
||||
public List<QueryParameter> Parameters { get; set; } = new List<QueryParameter>();
|
||||
public List<string> OrderBys { get; set; } = new List<string>();
|
||||
|
||||
public bool IsAsc { get; set; } = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Query
|
||||
|
||||
16
Yi.Framework.Net6/Yi.Framework.Model/RoleEntity.cs
Normal file
16
Yi.Framework.Net6/Yi.Framework.Model/RoleEntity.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
|
||||
public partial class RoleEntity
|
||||
{
|
||||
//[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.RoleId), nameof(UserRoleEntity.UserId))]
|
||||
//public List<UserEntity> Users { get; set; }
|
||||
[Navigate(typeof(RoleMenuEntity),nameof(RoleMenuEntity.RoleId),nameof(RoleMenuEntity.MenuId))]
|
||||
public List<MenuEntity> Menus { get; set; }
|
||||
}
|
||||
}
|
||||
30
Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs
Normal file
30
Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public partial class UserEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 看好啦!ORM精髓,导航属性
|
||||
///</summary>
|
||||
[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.UserId), nameof(UserRoleEntity.RoleId))]
|
||||
public List<RoleEntity> Roles { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构建密码,MD5盐值加密
|
||||
/// </summary>
|
||||
public void BuildPassword(string password = null)
|
||||
{
|
||||
//如果不传值,那就把自己的password当作传进来的password
|
||||
if (password == null)
|
||||
{
|
||||
password = this.Password;
|
||||
}
|
||||
this.Salt = Common.Helper.MD5Helper.GenerateSalt();
|
||||
this.Password = Common.Helper.MD5Helper.SHA2Encode(password, this.Salt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NEST" Version="7.16.0" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.0.6.5" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.0.7.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Common.Models;
|
||||
//using SqlSugar;
|
||||
//using Yi.Framework.Common.Models;
|
||||
//using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Repository
|
||||
{
|
||||
public class DataContext<T> : SimpleClient<T> where T : class, new()
|
||||
{
|
||||
public DataContext(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
Db =base.Context;
|
||||
}
|
||||
//namespace Yi.Framework.Repository
|
||||
//{
|
||||
// public class DataContext<T> : SimpleClient<T> where T : class, IBaseModelEntity, new()
|
||||
// {
|
||||
// public DataContext(ISqlSugarClient context) : base(context)
|
||||
// {
|
||||
// }
|
||||
|
||||
public ISqlSugarClient Db;
|
||||
}
|
||||
}
|
||||
// }
|
||||
//}
|
||||
//简化已被弃用
|
||||
|
||||
@@ -11,7 +11,7 @@ using Yi.Framework.Model.Query;
|
||||
|
||||
namespace Yi.Framework.Repository
|
||||
{
|
||||
public interface IRepository<T> : ISimpleClient<T> where T : BaseModelEntity,new()
|
||||
public interface IRepository<T> : ISimpleClient<T> where T : class, IBaseModelEntity, new()
|
||||
{
|
||||
public ISqlSugarClient _Db { get; set; }
|
||||
public Task<bool> UseTranAsync(Func<Task> func);
|
||||
@@ -21,5 +21,9 @@ namespace Yi.Framework.Repository
|
||||
public Task<List<T>> GetListAsync(QueryCondition pars);
|
||||
public Task<bool> DeleteByLogicAsync(List<long> ids);
|
||||
public Task<bool> UpdateIgnoreNullAsync(T entity);
|
||||
public Task<List<S>> UseSqlAsync<S>(string sql, object parameters = null);
|
||||
public Task<bool> UseSqlAsync(string sql, object parameters = null);
|
||||
ISugarQueryable<T> QueryConditionHandler(QueryCondition pars);
|
||||
Task<bool> UpdateSuperSaveAsync(T data, Expression<Func<T, object>> columns);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,16 +12,15 @@ namespace Yi.Framework.Repository
|
||||
/// 仓储模式
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class Repository<T> : DataContext<T>, IRepository<T> where T : BaseModelEntity,new()
|
||||
public class Repository<T> : SimpleClient<T>, IRepository<T> where T : class, IBaseModelEntity, new()
|
||||
{
|
||||
public ISqlSugarClient _Db { get; set; }
|
||||
public ISqlSugarClient _Db { get { return base.Context; } set { } }
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public Repository(ISqlSugarClient context) : base(context)//注意这里要有默认值等于null
|
||||
{
|
||||
_Db = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -31,11 +30,32 @@ namespace Yi.Framework.Repository
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UseTranAsync(Func<Task> func)
|
||||
{
|
||||
var res = await Db.AsTenant().UseTranAsync(func);
|
||||
var con = Context;
|
||||
var res = await _Db.AsTenant().UseTranAsync(func);
|
||||
return res.IsSuccess;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行查询sql返回dto列表
|
||||
/// </summary>
|
||||
/// <typeparam name="S"></typeparam>
|
||||
/// <param name="sql"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<S>> UseSqlAsync<S>(string sql, object parameters = null)
|
||||
{
|
||||
return await _Db.Ado.SqlQueryAsync<S>(sql, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行增删改sql返回状态
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UseSqlAsync(string sql, object parameters)
|
||||
{
|
||||
return await _Db.Ado.ExecuteCommandAsync(sql, parameters) >0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加返回实体
|
||||
@@ -45,7 +65,7 @@ namespace Yi.Framework.Repository
|
||||
public async Task<T> InsertReturnEntityAsync(T entity)
|
||||
{
|
||||
entity.Id =SnowFlakeSingle.instance.getID();
|
||||
return await Db.Insertable(entity).ExecuteReturnEntityAsync();
|
||||
return await _Db.Insertable(entity).ExecuteReturnEntityAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -55,7 +75,7 @@ namespace Yi.Framework.Repository
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UpdateIgnoreNullAsync(T entity)
|
||||
{
|
||||
return await Db.Updateable(entity).IgnoreColumns(true).ExecuteCommandAsync()>0;
|
||||
return await _Db.Updateable(entity).IgnoreColumns(true).ExecuteCommandAsync()>0;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,9 +85,9 @@ namespace Yi.Framework.Repository
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DeleteByLogicAsync(List<long> ids)
|
||||
{
|
||||
var entitys = await Db.Queryable<T>().Where(u => ids.Contains(u.Id)).ToListAsync();
|
||||
var entitys = await _Db.Queryable<T>().Where(u => ids.Contains(u.Id)).ToListAsync();
|
||||
entitys.ForEach(u=>u.IsDeleted=true);
|
||||
return await Db.Updateable(entitys).ExecuteCommandAsync()>0;
|
||||
return await _Db.Updateable(entitys).ExecuteCommandAsync()>0;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +100,7 @@ namespace Yi.Framework.Repository
|
||||
/// <returns></returns>
|
||||
public async Task<List<S>> StoreAsync<S>(string storeName, object para)
|
||||
{
|
||||
return await Db.Ado.UseStoredProcedure().SqlQueryAsync<S>(storeName, para);
|
||||
return await _Db.Ado.UseStoredProcedure().SqlQueryAsync<S>(storeName, para);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +131,7 @@ namespace Yi.Framework.Repository
|
||||
|
||||
|
||||
|
||||
private ISugarQueryable<T> QueryConditionHandler(QueryCondition pars)
|
||||
public ISugarQueryable<T> QueryConditionHandler(QueryCondition pars)
|
||||
{
|
||||
var sugarParamters = pars.Parameters.Select(it => (IConditionalModel)new ConditionalModel()
|
||||
{
|
||||
@@ -119,17 +139,57 @@ namespace Yi.Framework.Repository
|
||||
FieldName = it.Key,
|
||||
FieldValue = it.Value
|
||||
}).ToList();
|
||||
var query = Db.Queryable<T>();
|
||||
var query = _Db.Queryable<T>();
|
||||
if (pars.OrderBys != null)
|
||||
{
|
||||
foreach (var item in pars.OrderBys)
|
||||
{
|
||||
query.OrderBy(item.ToSqlFilter());
|
||||
if (pars.IsAsc)
|
||||
{
|
||||
query.OrderBy(item.ToSqlFilter() + " asc");
|
||||
}
|
||||
else
|
||||
{
|
||||
query.OrderBy(item.ToSqlFilter() + " desc");
|
||||
}
|
||||
}
|
||||
}
|
||||
return query.Where(sugarParamters);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新高级保存,验证重复
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="columns"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UpdateSuperSaveAsync(T data, Expression<Func<T, object>> columns)
|
||||
{
|
||||
var x = _Db.Storageable(data)
|
||||
.SplitError(it => it.Any())
|
||||
.SplitUpdate(it => true)
|
||||
.WhereColumns(columns)//这里用name作为数据库查找条件
|
||||
.ToStorage();
|
||||
return await x.AsInsertable.ExecuteCommandAsync() > 0;//插入可插入部分
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加高级保存,验证重复
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="columns"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> InsertSuperSaveAsync(T data, Expression<Func<T, object>> columns)
|
||||
{
|
||||
var x = _Db.Storageable(data)
|
||||
.SplitError(it => it.Any())
|
||||
.SplitInsert(it => true)
|
||||
.WhereColumns(columns)//这里用name作为数据库查找条件
|
||||
.ToStorage();
|
||||
return await x.AsInsertable.ExecuteCommandAsync() > 0;//插入可插入部分
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public class BaseService<T>:IBaseService<T> where T:BaseModelEntity,new()
|
||||
public class BaseService<T>:IBaseService<T> where T:class, IBaseModelEntity,new()
|
||||
{
|
||||
public IRepository<T> _repository { get; set; }
|
||||
public BaseService(IRepository<T> iRepository)
|
||||
|
||||
23
Yi.Framework.Net6/Yi.Framework.Service/LogService.cs
Normal file
23
Yi.Framework.Net6/Yi.Framework.Service/LogService.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class LogService
|
||||
{
|
||||
public async Task<List<long>> AddListTest(List<LogEntity> logEntities)
|
||||
{
|
||||
return await _repository._Db.Insertable(logEntities).SplitTable().ExecuteReturnSnowflakeIdListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<LogEntity>> GetListTest()
|
||||
{
|
||||
return await _repository._Db.Queryable<LogEntity>().SplitTable(tas => tas.Where(u => u.TableName.Contains("2020") || u.TableName.Contains("2021"))).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Yi.Framework.Net6/Yi.Framework.Service/MenuService.cs
Normal file
19
Yi.Framework.Net6/Yi.Framework.Service/MenuService.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class MenuService : BaseService<MenuEntity>, IMenuService
|
||||
{
|
||||
public async Task<List<MenuEntity>> GetMenuTreeAsync()
|
||||
{
|
||||
//ParentId 0,代表为根目录,只能存在一个
|
||||
//复杂查询直接使用db代理
|
||||
return await _repository._Db.Queryable<MenuEntity>().Where(u=>u.IsDeleted==false).ToTreeAsync(it=>it.Children,it=>it.ParentId,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
50
Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
Normal file
50
Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class RoleService
|
||||
{
|
||||
public async Task<List<RoleEntity>> DbTest()
|
||||
{
|
||||
return await _repository._Db.Queryable<RoleEntity>().ToListAsync();
|
||||
}
|
||||
public async Task<bool> GiveRoleSetMenu(List<long> roleIds, List<long> menuIds)
|
||||
{
|
||||
var _repositoryRoleMenu= _repository.ChangeRepository<Repository<RoleMenuEntity>>();
|
||||
//多次操作,需要事务确保原子性
|
||||
return await _repositoryRoleMenu.UseTranAsync(async () =>
|
||||
{
|
||||
|
||||
//遍历用户
|
||||
foreach (var roleId in roleIds)
|
||||
{
|
||||
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
|
||||
await _repositoryRoleMenu.DeleteAsync(u => u.RoleId==roleId);
|
||||
|
||||
//添加新的关系
|
||||
List<RoleMenuEntity> roleMenuEntity = new();
|
||||
foreach (var menu in menuIds)
|
||||
{
|
||||
roleMenuEntity.Add(new RoleMenuEntity() { RoleId = roleId,MenuId=menu });
|
||||
}
|
||||
|
||||
//一次性批量添加
|
||||
await _repositoryRoleMenu.InsertReturnSnowflakeIdAsync(roleMenuEntity);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async Task<RoleEntity> GetInMenuByRoleId(long roleId)
|
||||
{
|
||||
return await _repository._Db.Queryable<RoleEntity>().Includes(u => u.Menus).InSingleAsync(roleId);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class LogService : BaseService<LogEntity>, ILogService
|
||||
{
|
||||
public LogService(IRepository<LogEntity> repository) : base(repository)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class MenuService : BaseService<MenuEntity>, IMenuService
|
||||
{
|
||||
public MenuService(IRepository<MenuEntity> repository) : base(repository)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class RoleService : BaseService<RoleEntity>, IRoleService
|
||||
{
|
||||
public RoleService(IRepository<RoleEntity> repository) : base(repository)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
@@ -15,7 +18,7 @@ namespace Yi.Framework.Service
|
||||
{
|
||||
return await _repository._Db.Queryable<UserEntity>().ToListAsync();
|
||||
}
|
||||
public async Task<bool> Exist(Guid id, Action<UserEntity> userAction = null)
|
||||
public async Task<bool> Exist(long id, Action<UserEntity> userAction = null)
|
||||
{
|
||||
var user = await _repository.GetByIdAsync(id);
|
||||
userAction.Invoke(user);
|
||||
@@ -27,7 +30,7 @@ namespace Yi.Framework.Service
|
||||
}
|
||||
public async Task<bool> Exist(string userName, Action<UserEntity> userAction = null)
|
||||
{
|
||||
var user = await _repository.GetFirstAsync(u=>u.UserName== userName);
|
||||
var user = await _repository.GetFirstAsync(u => u.UserName == userName);
|
||||
if (userAction != null)
|
||||
{
|
||||
userAction.Invoke(user);
|
||||
@@ -38,18 +41,18 @@ namespace Yi.Framework.Service
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public async Task<bool> Login(string userName, string password,Action<UserEntity> userAction = null)
|
||||
public async Task<bool> Login(string userName, string password, Action<UserEntity> userAction = null)
|
||||
{
|
||||
var user=new UserEntity();
|
||||
var user = new UserEntity();
|
||||
if (await Exist(userName, o => user = o))
|
||||
{
|
||||
userAction.Invoke(user);
|
||||
if (user.Password== Common.Helper.MD5Helper.SHA2Encode(password, user.Salt))
|
||||
if (user.Password == Common.Helper.MD5Helper.SHA2Encode(password, user.Salt))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> Register(UserEntity userEntity, Action<UserEntity> userAction = null)
|
||||
@@ -57,13 +60,89 @@ namespace Yi.Framework.Service
|
||||
var user = new UserEntity();
|
||||
if (!await Exist(userEntity.UserName))
|
||||
{
|
||||
user.UserName= userEntity.UserName;
|
||||
user.Salt = Common.Helper.MD5Helper.GenerateSalt();
|
||||
user.Password = Common.Helper.MD5Helper.SHA2Encode(userEntity.Password,user.Salt);
|
||||
user.UserName = userEntity.UserName;
|
||||
user.BuildPassword();
|
||||
userAction.Invoke(await _repository.InsertReturnEntityAsync(user));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<List<UserEntity>> GetListInRole()
|
||||
{
|
||||
return await _repository._Db.Queryable<UserEntity>().Includes(u => u.Roles).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> GiveUserSetRole(List<long> userIds, List<long> roleIds)
|
||||
{
|
||||
var _repositoryUserRole = _repository.ChangeRepository<Repository<UserRoleEntity>>();
|
||||
|
||||
//多次操作,需要事务确保原子性
|
||||
return await _repositoryUserRole.UseTranAsync(async () =>
|
||||
{
|
||||
|
||||
//遍历用户
|
||||
foreach (var userId in userIds)
|
||||
{
|
||||
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
|
||||
await _repositoryUserRole.DeleteAsync(u => u.UserId == userId);
|
||||
|
||||
//添加新的关系
|
||||
List<UserRoleEntity> userRoleEntities = new();
|
||||
foreach (var roleId in roleIds)
|
||||
{
|
||||
userRoleEntities.Add(new UserRoleEntity() { UserId = userId, RoleId = roleId });
|
||||
}
|
||||
|
||||
//一次性批量添加
|
||||
await _repositoryUserRole.InsertReturnSnowflakeIdAsync(userRoleEntities);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<RoleEntity>> GetRoleListByUserId(long userId)
|
||||
{
|
||||
return (await _repository._Db.Queryable<UserEntity>().Includes(u => u.Roles).InSingleAsync(userId)).Roles;
|
||||
}
|
||||
|
||||
public async Task<UserRoleMenuDto> GetUserAllInfo(long userId)
|
||||
{
|
||||
|
||||
var userRoleMenu = new UserRoleMenuDto();
|
||||
//首先获取到该用户全部信息,导航到角色、菜单,(菜单需要去重,完全交给Set来处理即可)
|
||||
|
||||
//得到用户
|
||||
var user = await _repository._Db.Queryable<UserEntity>().Includes(u => u.Roles.Where(r=>r.IsDeleted==false).ToList(), r => r.Menus.Where(m=>m.IsDeleted==false).ToList()).InSingleAsync(userId);
|
||||
|
||||
//得到角色集合
|
||||
var roleList = user.Roles;
|
||||
|
||||
//得到菜单集合
|
||||
foreach (var role in roleList)
|
||||
{
|
||||
foreach (var menu in role.Menus)
|
||||
{
|
||||
userRoleMenu.Menus.Add(menu);
|
||||
}
|
||||
//刚好可以去除一下多余的导航属性
|
||||
role.Menus = null;
|
||||
userRoleMenu.Roles.Add(role);
|
||||
}
|
||||
|
||||
user.Roles = null;
|
||||
userRoleMenu.User = user;
|
||||
|
||||
return userRoleMenu;
|
||||
}
|
||||
|
||||
public bool JudgePassword(UserEntity user,string password)
|
||||
{
|
||||
if (user.Password == MD5Helper.SHA2Encode(password, user.Salt))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
namespace Yi.Framework.WeChatPay.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// IConfig
|
||||
/// </summary>
|
||||
public interface IPayConfig
|
||||
{
|
||||
|
||||
//=======【基本信息设置】=====================================
|
||||
/* 微信公众号信息配置
|
||||
* APPID:绑定支付的APPID(必须配置)
|
||||
* MCHID:商户号(必须配置)
|
||||
* KEY:商户支付密钥,参考开户邮件设置(必须配置),请妥善保管,避免密钥泄露
|
||||
* APPSECRET:公众帐号secert(仅JSAPI支付的时候需要配置),请妥善保管,避免密钥泄露
|
||||
*/
|
||||
|
||||
string GetAppID();
|
||||
string GetMchID();
|
||||
string GetKey();
|
||||
string GetAppSecret();
|
||||
|
||||
|
||||
|
||||
//=======【证书路径设置】=====================================
|
||||
/* 证书路径,注意应该填写绝对路径(仅退款、撤销订单时需要)
|
||||
* 1.证书文件不能放在web服务器虚拟目录,应放在有访问权限控制的目录中,防止被他人下载;
|
||||
* 2.建议将证书文件名改为复杂且不容易猜测的文件
|
||||
* 3.商户服务器要做好病毒和木马防护工作,不被非法侵入者窃取证书文件。
|
||||
*/
|
||||
string GetSSlCertPath();
|
||||
string GetSSlCertPassword();
|
||||
|
||||
|
||||
|
||||
//=======【支付结果通知url】=====================================
|
||||
/* 支付结果通知回调url,用于商户接收支付结果
|
||||
*/
|
||||
string GetNotifyUrl();
|
||||
|
||||
//=======【商户系统后台机器IP】=====================================
|
||||
/* 此参数可手动配置也可在程序中自动获取
|
||||
*/
|
||||
string GetIp();
|
||||
|
||||
|
||||
//=======【代理服务器设置】===================================
|
||||
/* 默认IP和端口号分别为0.0.0.0和0,此时不开启代理(如有需要才设置)
|
||||
*/
|
||||
string GetProxyUrl();
|
||||
|
||||
|
||||
//=======【上报信息配置】===================================
|
||||
/* 测速上报等级,0.关闭上报; 1.仅错误时上报; 2.全量上报
|
||||
*/
|
||||
int GetReportLevel();
|
||||
|
||||
|
||||
//=======【日志级别】===================================
|
||||
/* 日志等级,0.不输出日志;1.只输出错误信息; 2.输出错误和正常信息; 3.输出错误信息、正常信息和调试信息
|
||||
*/
|
||||
int GetLogLevel();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Yi.Framework.WeChatPay.Options;
|
||||
|
||||
namespace Yi.Framework.WeChatPay.Core
|
||||
{
|
||||
public class PayConfig : IPayConfig
|
||||
{
|
||||
public static PayConfig Current = null;
|
||||
|
||||
public PayConfig(PayOptions payOptions)
|
||||
{
|
||||
Current = this;
|
||||
_BasicConfig = payOptions;
|
||||
}
|
||||
|
||||
private static PayOptions _BasicConfig = null;
|
||||
|
||||
|
||||
//=======【基本信息设置】=====================================
|
||||
/* 微信公众号信息配置
|
||||
* APPID:绑定支付的APPID(必须配置)
|
||||
* MCHID:商户号(必须配置)
|
||||
* KEY:商户支付密钥,参考开户邮件设置(必须配置),请妥善保管,避免密钥泄露
|
||||
* APPSECRET:公众帐号secert(仅JSAPI支付的时候需要配置),请妥善保管,避免密钥泄露
|
||||
*/
|
||||
|
||||
public string GetAppID()
|
||||
{
|
||||
return _BasicConfig.AppID;
|
||||
}
|
||||
public string GetMchID()
|
||||
{
|
||||
return _BasicConfig.MchID;
|
||||
}
|
||||
public string GetKey()
|
||||
{
|
||||
return _BasicConfig.Key;
|
||||
}
|
||||
public string GetAppSecret()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======【证书路径设置】=====================================
|
||||
/* 证书路径,注意应该填写绝对路径(仅退款、撤销订单时需要)
|
||||
* 1.证书文件不能放在web服务器虚拟目录,应放在有访问权限控制的目录中,防止被他人下载;
|
||||
* 2.建议将证书文件名改为复杂且不容易猜测的文件
|
||||
* 3.商户服务器要做好病毒和木马防护工作,不被非法侵入者窃取证书文件。
|
||||
*/
|
||||
public string GetSSlCertPath()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
public string GetSSlCertPassword()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======【支付结果通知url】=====================================
|
||||
/* 支付结果通知回调url,用于商户接收支付结果
|
||||
*/
|
||||
public string GetNotifyUrl()
|
||||
{
|
||||
return _BasicConfig.NotifyUrl;
|
||||
}
|
||||
|
||||
//=======【商户系统后台机器IP】=====================================
|
||||
/* 此参数可手动配置也可在程序中自动获取
|
||||
*/
|
||||
public string GetIp()
|
||||
{
|
||||
return "0.0.0.0";
|
||||
}
|
||||
|
||||
//=======【代理服务器设置】===================================
|
||||
/* 默认IP和端口号分别为0.0.0.0和0,此时不开启代理(如有需要才设置)
|
||||
*/
|
||||
public string GetProxyUrl()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
//=======【上报信息配置】===================================
|
||||
/* 测速上报等级,0.关闭上报; 1.仅错误时上报; 2.全量上报
|
||||
*/
|
||||
public int GetReportLevel()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
//=======【日志级别】===================================
|
||||
/* 日志等级,0.不输出日志;1.只输出错误信息; 2.输出错误和正常信息; 3.输出错误信息、正常信息和调试信息
|
||||
*/
|
||||
public int GetLogLevel()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
138
Yi.Framework.Net6/Yi.Framework.WeChatPay/Core/Helper/PayApi.cs
Normal file
138
Yi.Framework.Net6/Yi.Framework.WeChatPay/Core/Helper/PayApi.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using FizzWare.NBuilder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.WeChatPay.Exceptions;
|
||||
|
||||
namespace Yi.Framework.WeChatPay.Core
|
||||
{
|
||||
public class PayApi
|
||||
{
|
||||
private readonly IPayConfig _IPayConfig = null;
|
||||
private readonly PayHttpService _PayHttpService = null;
|
||||
public PayApi(IPayConfig payConfig, PayHttpService payHttpService)
|
||||
{
|
||||
this._IPayConfig = payConfig;
|
||||
this._PayHttpService = payHttpService;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 统一下单
|
||||
* @param WxPaydata inputObj 提交给统一下单API的参数
|
||||
* @param int timeOut 超时时间
|
||||
* @throws WxPayException
|
||||
* @return 成功时返回,其他抛异常
|
||||
*/
|
||||
public PayData UnifiedOrder(PayData inputObj, int timeOut = 6)
|
||||
{
|
||||
string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
|
||||
//检测必填参数
|
||||
if (!inputObj.IsSet("out_trade_no"))
|
||||
{
|
||||
throw new PayException("缺少统一支付接口必填参数out_trade_no!");
|
||||
}
|
||||
else if (!inputObj.IsSet("body"))
|
||||
{
|
||||
throw new PayException("缺少统一支付接口必填参数body!");
|
||||
}
|
||||
else if (!inputObj.IsSet("total_fee"))
|
||||
{
|
||||
throw new PayException("缺少统一支付接口必填参数total_fee!");
|
||||
}
|
||||
else if (!inputObj.IsSet("trade_type"))
|
||||
{
|
||||
throw new PayException("缺少统一支付接口必填参数trade_type!");
|
||||
}
|
||||
|
||||
//关联参数
|
||||
if (inputObj.GetValue("trade_type").ToString() == "JSAPI" && !inputObj.IsSet("openid"))
|
||||
{
|
||||
throw new PayException("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
|
||||
}
|
||||
if (inputObj.GetValue("trade_type").ToString() == "NATIVE" && !inputObj.IsSet("product_id"))
|
||||
{
|
||||
throw new PayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
|
||||
}
|
||||
|
||||
//异步通知url未设置,则使用配置文件中的url
|
||||
/*if (!inputObj.IsSet("notify_url"))
|
||||
{
|
||||
inputObj.SetValue("notify_url", this._IWxPayConfig().GetNotifyUrl());//异步通知url
|
||||
}*/
|
||||
|
||||
inputObj.SetValue("appid", this._IPayConfig.GetAppID());//公众账号ID
|
||||
inputObj.SetValue("mch_id", this._IPayConfig.GetMchID());//商户号
|
||||
inputObj.SetValue("spbill_create_ip", this._IPayConfig.GetIp());//终端ip
|
||||
inputObj.SetValue("nonce_str", GenerateNonceStr());//随机字符串
|
||||
inputObj.SetValue("sign_type", PayData.SIGN_TYPE_HMAC_SHA256);//签名类型
|
||||
|
||||
//签名
|
||||
inputObj.SetValue("sign", inputObj.MakeSign());
|
||||
string xml = inputObj.ToXml();
|
||||
// 发起http请求
|
||||
string response = this._PayHttpService.Post(xml, url, false, timeOut);
|
||||
PayData result = new PayData();
|
||||
result.FromXml(response);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 查询订单
|
||||
* @param WxPayData inputObj 提交给查询订单API的参数
|
||||
* @param int timeOut 超时时间
|
||||
* @throws WxPayException
|
||||
* @return 成功时返回订单查询结果,其他抛异常
|
||||
*/
|
||||
public PayData OrderQuery(PayData inputObj, HttpContext httpContext, int timeOut = 6)
|
||||
{
|
||||
string url = "https://api.mch.weixin.qq.com/pay/orderquery";
|
||||
//检测必填参数
|
||||
if (!inputObj.IsSet("out_trade_no") && !inputObj.IsSet("transaction_id"))
|
||||
{
|
||||
throw new PayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
|
||||
}
|
||||
|
||||
inputObj.SetValue("appid", this._IPayConfig.GetAppID());//公众账号ID
|
||||
inputObj.SetValue("mch_id", this._IPayConfig.GetMchID());//商户号
|
||||
inputObj.SetValue("nonce_str", GenerateNonceStr());//随机字符串
|
||||
inputObj.SetValue("sign_type", PayData.SIGN_TYPE_HMAC_SHA256);//签名类型
|
||||
inputObj.SetValue("sign", inputObj.MakeSign());//签名
|
||||
string xml = inputObj.ToXml();
|
||||
//Log.Debug("WxPayApi", "OrderQuery request : " + xml);
|
||||
string response = this._PayHttpService.Post(xml, url, false, timeOut);//调用HTTP通信接口提交数据
|
||||
//Log.Debug("WxPayApi", "OrderQuery response : " + response);
|
||||
|
||||
//将xml格式的数据转化为对象以返回
|
||||
PayData result = new PayData();
|
||||
result.FromXml(response);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成时间戳,标准北京时间,时区为东八区,自1970年1月1日 0点0分0秒以来的秒数
|
||||
* @return 时间戳
|
||||
*/
|
||||
public static string GenerateTimeStamp()
|
||||
{
|
||||
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
return Convert.ToInt64(ts.TotalSeconds).ToString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机串,随机串包含字母或数字
|
||||
* @return 随机串
|
||||
*/
|
||||
public static string GenerateNonceStr()
|
||||
{
|
||||
RandomGenerator randomGenerator = new RandomGenerator();
|
||||
return randomGenerator.Int().ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
322
Yi.Framework.Net6/Yi.Framework.WeChatPay/Core/Helper/PayData.cs
Normal file
322
Yi.Framework.Net6/Yi.Framework.WeChatPay/Core/Helper/PayData.cs
Normal file
@@ -0,0 +1,322 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Xml;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Yi.Framework.WeChatPay.Core;
|
||||
|
||||
namespace Yi.Framework.WeChatPay.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 微信支付协议接口数据类,所有的API接口通信都依赖这个数据结构,
|
||||
/// 在调用接口之前先填充各个字段的值,然后进行接口通信,
|
||||
/// 这样设计的好处是可扩展性强,用户可随意对协议进行更改而不用重新设计数据结构,
|
||||
/// 还可以随意组合出不同的协议数据包,不用为每个协议设计一个数据包结构
|
||||
/// </summary>
|
||||
public class PayData
|
||||
{
|
||||
public const string SIGN_TYPE_MD5 = "MD5";
|
||||
public const string SIGN_TYPE_HMAC_SHA256 = "HMAC-SHA256";
|
||||
|
||||
|
||||
//采用排序的Dictionary的好处是方便对数据包进行签名,不用再签名之前再做一次排序
|
||||
private SortedDictionary<string, object> m_values = new SortedDictionary<string, object>();
|
||||
|
||||
/**
|
||||
* 设置某个字段的值
|
||||
* @param key 字段名
|
||||
* @param value 字段值
|
||||
*/
|
||||
public void SetValue(string key, object value)
|
||||
{
|
||||
m_values[key] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字段名获取某个字段的值
|
||||
* @param key 字段名
|
||||
* @return key对应的字段值
|
||||
*/
|
||||
public object GetValue(string key)
|
||||
{
|
||||
object o = null;
|
||||
m_values.TryGetValue(key, out o);
|
||||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断某个字段是否已设置
|
||||
* @param key 字段名
|
||||
* @return 若字段key已被设置,则返回true,否则返回false
|
||||
*/
|
||||
public bool IsSet(string key)
|
||||
{
|
||||
object o = null;
|
||||
m_values.TryGetValue(key, out o);
|
||||
if (null != o && !o.Equals(""))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @将Dictionary转成xml
|
||||
* @return 经转换得到的xml串
|
||||
* @throws WxPayException
|
||||
**/
|
||||
public string ToXml()
|
||||
{
|
||||
//数据为空时不能转化为xml格式
|
||||
if (0 == m_values.Count)
|
||||
{
|
||||
throw new Exception("WxPayData数据为空!");
|
||||
}
|
||||
|
||||
string xml = "<xml>";
|
||||
foreach (KeyValuePair<string, object> pair in m_values)
|
||||
{
|
||||
//字段值不能为null,会影响后续流程
|
||||
if (pair.Value == null)
|
||||
{
|
||||
throw new Exception("WxPayData内部含有值为null的字段!");
|
||||
}
|
||||
|
||||
if (pair.Value.GetType() == typeof(int))
|
||||
{
|
||||
xml += "<" + pair.Key + ">" + pair.Value + "</" + pair.Key + ">";
|
||||
}
|
||||
else if (pair.Value.GetType() == typeof(string))
|
||||
{
|
||||
xml += "<" + pair.Key + ">" + "<![CDATA[" + pair.Value + "]]></" + pair.Key + ">";
|
||||
}
|
||||
else//除了string和int类型不能含有其他数据类型
|
||||
{
|
||||
throw new Exception("WxPayData字段数据类型错误!");
|
||||
}
|
||||
}
|
||||
xml += "</xml>";
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* @将xml转为WxPayData对象并返回对象内部的数据
|
||||
* @param string 待转换的xml串
|
||||
* @return 经转换得到的Dictionary
|
||||
* @throws WxPayException
|
||||
*/
|
||||
public SortedDictionary<string, object> FromXml(string xml)
|
||||
{
|
||||
if (string.IsNullOrEmpty(xml))
|
||||
{
|
||||
throw new Exception("将空的xml串转换为WxPayData不合法!");
|
||||
}
|
||||
|
||||
|
||||
SafeXmlDocument xmlDoc = new SafeXmlDocument();
|
||||
xmlDoc.LoadXml(xml);
|
||||
XmlNode xmlNode = xmlDoc.FirstChild;//获取到根节点<xml>
|
||||
XmlNodeList nodes = xmlNode.ChildNodes;
|
||||
foreach (XmlNode xn in nodes)
|
||||
{
|
||||
XmlElement xe = (XmlElement)xn;
|
||||
m_values[xe.Name] = xe.InnerText;//获取xml的键值对到WxPayData内部的数据中
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//2015-06-29 错误是没有签名
|
||||
if (m_values["return_code"].ToString() != "SUCCESS")
|
||||
{
|
||||
return m_values;
|
||||
}
|
||||
//验证签名,不通过会抛异常
|
||||
CheckSign();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
|
||||
return m_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Dictionary格式转化成url参数格式
|
||||
* @ return url格式串, 该串不包含sign字段值
|
||||
*/
|
||||
public string ToUrl()
|
||||
{
|
||||
string buff = "";
|
||||
foreach (KeyValuePair<string, object> pair in m_values)
|
||||
{
|
||||
if (pair.Value == null)
|
||||
{
|
||||
throw new Exception("WxPayData内部含有值为null的字段!");
|
||||
}
|
||||
|
||||
if (pair.Key != "sign" && pair.Value.ToString() != "")
|
||||
{
|
||||
buff += pair.Key + "=" + pair.Value + "&";
|
||||
}
|
||||
}
|
||||
|
||||
buff = buff.Trim('&');
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Dictionary格式化成Json
|
||||
* @return json串数据
|
||||
*/
|
||||
public string ToJson()
|
||||
{
|
||||
string jsonStr = JsonConvert.SerializeObject(m_values);
|
||||
return jsonStr;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @values格式化成能在Web页面上显示的结果(因为web页面上不能直接输出xml格式的字符串)
|
||||
*/
|
||||
public string ToPrintStr()
|
||||
{
|
||||
string str = "";
|
||||
foreach (KeyValuePair<string, object> pair in m_values)
|
||||
{
|
||||
if (pair.Value == null)
|
||||
{
|
||||
throw new Exception("WxPayData内部含有值为null的字段!");
|
||||
}
|
||||
|
||||
|
||||
str += string.Format("{0}={1}\n", pair.Key, pair.Value.ToString());
|
||||
}
|
||||
str = HttpUtility.HtmlEncode(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @生成签名,详见签名生成算法
|
||||
* @return 签名, sign字段不参加签名
|
||||
*/
|
||||
public string MakeSign(string signType)
|
||||
{
|
||||
//转url格式
|
||||
string str = ToUrl();
|
||||
//在string后加入API KEY
|
||||
string apiKey = PayConfig.Current.GetKey();
|
||||
str += "&key=" + apiKey;
|
||||
if (signType == SIGN_TYPE_MD5)
|
||||
{
|
||||
var md5 = MD5.Create();
|
||||
var bs = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
|
||||
var sb = new StringBuilder();
|
||||
foreach (byte b in bs)
|
||||
{
|
||||
sb.Append(b.ToString("x2"));
|
||||
}
|
||||
//所有字符转为大写
|
||||
return sb.ToString().ToUpper();
|
||||
}
|
||||
else if (signType == SIGN_TYPE_HMAC_SHA256)
|
||||
{
|
||||
return CalcHMACSHA256Hash(str, apiKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("sign_type 不合法");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @生成签名,详见签名生成算法
|
||||
* @return 签名, sign字段不参加签名 SHA256
|
||||
*/
|
||||
public string MakeSign()
|
||||
{
|
||||
return MakeSign(SIGN_TYPE_HMAC_SHA256);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 检测签名是否正确
|
||||
* 正确返回true,错误抛异常
|
||||
*/
|
||||
public bool CheckSign(string signType)
|
||||
{
|
||||
//如果没有设置签名,则跳过检测
|
||||
if (!IsSet("sign"))
|
||||
{
|
||||
throw new Exception("WxPayData签名存在但不合法!");
|
||||
}
|
||||
//如果设置了签名但是签名为空,则抛异常
|
||||
else if (GetValue("sign") == null || GetValue("sign").ToString() == "")
|
||||
{
|
||||
throw new Exception("WxPayData签名存在但不合法!");
|
||||
}
|
||||
|
||||
//获取接收到的签名
|
||||
string return_sign = GetValue("sign").ToString();
|
||||
|
||||
//在本地计算新的签名
|
||||
string cal_sign = MakeSign(signType);
|
||||
|
||||
if (cal_sign == return_sign)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new Exception("WxPayData签名验证错误!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 检测签名是否正确
|
||||
* 正确返回true,错误抛异常
|
||||
*/
|
||||
public bool CheckSign()
|
||||
{
|
||||
return CheckSign(SIGN_TYPE_HMAC_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @获取Dictionary
|
||||
*/
|
||||
public SortedDictionary<string, object> GetValues()
|
||||
{
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
private string CalcHMACSHA256Hash(string plaintext, string salt)
|
||||
{
|
||||
string result = "";
|
||||
var enc = Encoding.Default;
|
||||
byte[]
|
||||
baText2BeHashed = enc.GetBytes(plaintext),
|
||||
baSalt = enc.GetBytes(salt);
|
||||
HMACSHA256 hasher = new HMACSHA256(baSalt);
|
||||
byte[] baHashedText = hasher.ComputeHash(baText2BeHashed);
|
||||
result = string.Join("", baHashedText.ToList().Select(b => b.ToString("x2")).ToArray());
|
||||
return result.ToUpper();
|
||||
}
|
||||
|
||||
|
||||
private class SafeXmlDocument : XmlDocument
|
||||
{
|
||||
public SafeXmlDocument()
|
||||
{
|
||||
this.XmlResolver = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.WeChatPay.Options;
|
||||
|
||||
namespace Yi.Framework.WeChatPay.Core
|
||||
{
|
||||
public class PayHelper
|
||||
{
|
||||
public static readonly string KEY_PAY_PREFIX = "order:pay:url:";
|
||||
private readonly IPayConfig _IPayConfig = null;
|
||||
private readonly PayApi _PayApi = null;
|
||||
|
||||
private HttpContext _httpContext;
|
||||
public PayHelper(IPayConfig PayConfig, PayApi PayApi, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
this._IPayConfig = PayConfig;
|
||||
this._PayApi = PayApi;
|
||||
this._httpContext = httpContextAccessor.HttpContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建支付连接
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <param name="description"></param>
|
||||
/// <param name="totalPay"></param>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <returns></returns>
|
||||
public string CreatePayUrl(long orderId, string description, long totalPay)
|
||||
{
|
||||
// 定义返回的支付连接
|
||||
string url;
|
||||
try
|
||||
{
|
||||
// 构建支付需要的参数对象
|
||||
PayData data = new PayData();
|
||||
//描述
|
||||
data.SetValue("body", description);
|
||||
//订单号
|
||||
data.SetValue("out_trade_no", orderId.ToString());
|
||||
data.SetValue("product_id", orderId.ToString());
|
||||
//货币(默认就是人民币)
|
||||
data.SetValue("fee_type", "CNY");
|
||||
//TODO 总金额 (模拟1分钱, 线上环境换成真实价格)
|
||||
data.SetValue("total_fee", /*totalPay.ToString()*/ 1); // 单位是分
|
||||
//调用微信支付的终端ip
|
||||
data.SetValue("spbill_create_ip", "0.0.0.0");
|
||||
//回调地址
|
||||
data.SetValue("notify_url", this._IPayConfig.GetNotifyUrl());
|
||||
//交易类型为扫码支付
|
||||
data.SetValue("trade_type", "NATIVE");
|
||||
|
||||
PayData result = this._PayApi.UnifiedOrder(data);//调用统一下单接口
|
||||
url = result.GetValue("code_url").ToString();//获得统一下单接口返回的二维码链接
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("生成支付链接连接失败", e);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// (调用微信API)根据订单ID查询订单信息,全部信息
|
||||
/// </summary>
|
||||
/// <param name="transaction_id"></param>
|
||||
/// <returns></returns>
|
||||
public PayData QueryOrderById(long orderId)
|
||||
{
|
||||
PayData req = new PayData();
|
||||
req.SetValue("out_trade_no", orderId.ToString());
|
||||
PayData res = this._PayApi.OrderQuery(req, _httpContext);
|
||||
return res;// 返回查询数据
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static PayOptions GetPayOptions(string path)
|
||||
{
|
||||
string config = File.ReadAllText(path);
|
||||
var option = JsonConvert.DeserializeObject<PayOptions>(config);
|
||||
Console.WriteLine($"configPath={path} AppID={option.AppID}");
|
||||
return option;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成二维码方法
|
||||
/// </summary>
|
||||
/// <param name="text">输入的字符串</param>
|
||||
/// <param name="width">二维码宽度</param>
|
||||
/// <param name="height">二维码高度</param>
|
||||
/// <returns></returns>
|
||||
public static string QRcode(string text, int width = 360, int height = 360)
|
||||
{
|
||||
|
||||
//这里要感谢一下http://old.wwei.cn/
|
||||
Dictionary<string, string> dic = new()
|
||||
{
|
||||
{ "qrid", "0" },
|
||||
{ "data[type]", "index" },
|
||||
{ "data[text]", text },
|
||||
{ "moban_id", "0" },
|
||||
{ "size", "300" },
|
||||
{ "level", "M" },
|
||||
{ "moban_type", "qrcpu" },
|
||||
{ "style_setting[protype]", "1" },
|
||||
{ "style_setting[ptcolor]", "#000000" },
|
||||
{ "style_setting[inptcolor]", "#000000" },
|
||||
{ "style_setting[fcolor]", "#000000" },
|
||||
{ "style_setting[bcolor]", "#ffffff" },
|
||||
{ "style_setting[mbtype_hb]", "0" },
|
||||
{ "style_setting[logo_id]", "" },
|
||||
{ "style_setting[logo_width]", "46" },
|
||||
{ "style_setting[logo_height]", "46" },
|
||||
{ "style_setting[logo_border]", "0" }
|
||||
|
||||
};
|
||||
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
if (dic.Count > 0)
|
||||
{
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
string postDataStr = builder.ToString();
|
||||
|
||||
|
||||
#pragma warning disable SYSLIB0014 // 类型或成员已过时
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://old.wwei.cn/qrcode-wwei_create.html");
|
||||
#pragma warning restore SYSLIB0014 // 类型或成员已过时
|
||||
|
||||
request.Method = "POST";
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
|
||||
request.Headers.Add("Host", "old.wwei.cn");
|
||||
request.Headers.Add("User-Agent", "PostmanRuntime/6.66.6");
|
||||
request.Headers.Add("Origin", "http://old.wwei.cn");
|
||||
request.Headers.Add("Referer", "http://old.wwei.cn/");
|
||||
|
||||
Stream myRequestStream = request.GetRequestStream();
|
||||
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("utf-8"));
|
||||
myStreamWriter.Write(postDataStr);
|
||||
myStreamWriter.Close();
|
||||
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
Stream myResponseStream = response.GetResponseStream();
|
||||
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
|
||||
string retString = myStreamReader.ReadToEnd();
|
||||
myStreamReader.Close();
|
||||
myResponseStream.Close();
|
||||
|
||||
var json = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(retString);
|
||||
var data = json["data"].ToString();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Net.Security;
|
||||
using System.Security.Authentication;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Yi.Framework.WeChatPay.Exceptions;
|
||||
|
||||
namespace Yi.Framework.WeChatPay.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// http连接基础类,负责底层的http通信
|
||||
/// </summary>
|
||||
public class PayHttpService
|
||||
{
|
||||
private readonly IPayConfig _IPayConfig = null;
|
||||
private readonly HttpContext _httpContext = null;
|
||||
public PayHttpService(IPayConfig PayConfig, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
this._IPayConfig = PayConfig;
|
||||
this._httpContext = httpContextAccessor.HttpContext;
|
||||
}
|
||||
|
||||
public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
|
||||
{
|
||||
//直接确认,否则打不开
|
||||
return true;
|
||||
}
|
||||
|
||||
public string Post(string xml, string url, bool isUseCert, int timeout)
|
||||
{
|
||||
System.GC.Collect();//垃圾回收,回收没有正常关闭的http连接
|
||||
|
||||
string result = "";//返回结果
|
||||
|
||||
|
||||
HttpWebRequest request = null;
|
||||
HttpWebResponse response = null;
|
||||
Stream reqStream = null;
|
||||
|
||||
try
|
||||
{
|
||||
//设置最大连接数
|
||||
ServicePointManager.DefaultConnectionLimit = 200;
|
||||
//设置https验证方式
|
||||
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback =
|
||||
new RemoteCertificateValidationCallback(CheckValidationResult);
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* 下面设置HttpWebRequest的相关属性
|
||||
* ************************************************************/
|
||||
#pragma warning disable SYSLIB0014 // 类型或成员已过时
|
||||
request = (HttpWebRequest)WebRequest.Create(url);
|
||||
#pragma warning restore SYSLIB0014 // 类型或成员已过时
|
||||
request.UserAgent = string.Format("WXPaySDK/{3} ({0}) .net/{1} {2}", Environment.OSVersion, Environment.Version, this._IPayConfig.GetMchID(), typeof(PayHttpService).Assembly.GetName().Version);
|
||||
request.Method = "POST";
|
||||
request.Timeout = timeout * 1000;
|
||||
|
||||
//设置POST的数据类型和长度
|
||||
request.ContentType = "text/xml";
|
||||
byte[] data = Encoding.UTF8.GetBytes(xml);
|
||||
request.ContentLength = data.Length;
|
||||
|
||||
|
||||
if (isUseCert)//是否使用证书--没用证书
|
||||
{
|
||||
string path = _httpContext.Request.Path;
|
||||
X509Certificate2 cert = new X509Certificate2(path + this._IPayConfig.GetSSlCertPath(), this._IPayConfig.GetSSlCertPassword());
|
||||
request.ClientCertificates.Add(cert);
|
||||
}
|
||||
|
||||
//往服务器写入数据
|
||||
reqStream = request.GetRequestStream();
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
|
||||
//获取服务端返回
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
//获取服务端返回数据
|
||||
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
||||
result = sr.ReadToEnd().Trim();
|
||||
sr.Close();
|
||||
}
|
||||
catch (System.Threading.ThreadAbortException)
|
||||
{
|
||||
#pragma warning disable SYSLIB0006 // 类型或成员已过时
|
||||
Thread.ResetAbort();
|
||||
#pragma warning restore SYSLIB0006 // 类型或成员已过时
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
if (e.Status == WebExceptionStatus.ProtocolError)
|
||||
{
|
||||
throw new PayException(e.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new PayException(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
//关闭连接和流
|
||||
if (response != null)
|
||||
{
|
||||
response.Close();
|
||||
}
|
||||
if (request != null)
|
||||
{
|
||||
request.Abort();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理http GET请求,返回数据
|
||||
/// </summary>
|
||||
/// <param name="url">请求的url地址</param>
|
||||
/// <returns>http GET成功后返回的数据,失败抛WebException异常</returns>
|
||||
public string Get(string url)
|
||||
{
|
||||
System.GC.Collect();
|
||||
string result = "";
|
||||
|
||||
HttpWebRequest request = null;
|
||||
HttpWebResponse response = null;
|
||||
|
||||
//请求url以获取数据
|
||||
try
|
||||
{
|
||||
//设置最大连接数
|
||||
ServicePointManager.DefaultConnectionLimit = 200;
|
||||
//设置https验证方式
|
||||
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback =
|
||||
new RemoteCertificateValidationCallback(CheckValidationResult);
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* 下面设置HttpWebRequest的相关属性
|
||||
* ************************************************************/
|
||||
#pragma warning disable SYSLIB0014 // 类型或成员已过时
|
||||
request = (HttpWebRequest)WebRequest.Create(url);
|
||||
#pragma warning restore SYSLIB0014 // 类型或成员已过时
|
||||
request.UserAgent = string.Format("WXPaySDK/{3} ({0}) .net/{1} {2}", Environment.OSVersion, Environment.Version, this._IPayConfig.GetMchID(), typeof(PayHttpService).Assembly.GetName().Version);
|
||||
request.Method = "GET";
|
||||
|
||||
//获取服务器返回
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
//获取HTTP返回数据
|
||||
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
||||
result = sr.ReadToEnd().Trim();
|
||||
sr.Close();
|
||||
}
|
||||
catch (System.Threading.ThreadAbortException)
|
||||
{
|
||||
#pragma warning disable SYSLIB0006 // 类型或成员已过时
|
||||
Thread.ResetAbort();
|
||||
#pragma warning restore SYSLIB0006 // 类型或成员已过时
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
throw new PayException(e.ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new PayException(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
//关闭连接和流
|
||||
if (response != null)
|
||||
{
|
||||
response.Close();
|
||||
}
|
||||
if (request != null)
|
||||
{
|
||||
request.Abort();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Yi.Framework.Net6/Yi.Framework.WeChatPay/Core/IPayInvoker.cs
Normal file
29
Yi.Framework.Net6/Yi.Framework.WeChatPay/Core/IPayInvoker.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.WeChatPay.Core
|
||||
{
|
||||
public interface IPayInvoker
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取WX支付链接的方法
|
||||
/// 然后发布定时同步状态任务
|
||||
/// </summary>
|
||||
/// <param name="orderId">订单ID</param>
|
||||
/// <param name="user">用户信息</param>
|
||||
/// <param name="httpContext">请求上下文</param>
|
||||
/// <returns>返回生成的支持链接</returns>
|
||||
string GenerateUrl(long orderId, long totalPay);
|
||||
/// <summary>
|
||||
/// 处理微信支付回调
|
||||
/// </summary>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <returns></returns>
|
||||
PayData HandleNotify();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.WeChatPay.Exceptions;
|
||||
|
||||
namespace Yi.Framework.WeChatPay.Core
|
||||
{
|
||||
public abstract class AbstractNotify
|
||||
{
|
||||
protected HttpContext _httpContext;
|
||||
|
||||
public AbstractNotify(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
this._httpContext = httpContextAccessor.HttpContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从请求对象中获取信息
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> GetRawBodyStringAsync(HttpRequest request, Encoding encoding = null)
|
||||
{
|
||||
if (encoding is null)
|
||||
{
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
var stream = new MemoryStream();
|
||||
await request.Body.CopyToAsync(stream);
|
||||
stream.Seek(0, 0);
|
||||
using (var reader = new StreamReader(stream, encoding))
|
||||
{
|
||||
var result = await reader.ReadToEndAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收从微信支付后台发送过来的数据并验证签名
|
||||
/// </summary>
|
||||
/// <returns>微信支付后台返回的数据</returns>
|
||||
public PayData GetNotifyData()
|
||||
{
|
||||
//接收从微信后台POST过来的数据
|
||||
string content = GetRawBodyStringAsync(_httpContext.Request).Result;
|
||||
Console.WriteLine(this.GetType().ToString(), "Receive data from WeChat : " + content);
|
||||
|
||||
//转换数据格式并验证签名
|
||||
PayData data = new PayData();
|
||||
try
|
||||
{
|
||||
data.FromXml(content);
|
||||
}
|
||||
catch (PayException ex)
|
||||
{
|
||||
throw new Exception("验签失败", ex);
|
||||
}
|
||||
|
||||
Console.WriteLine(this.GetType().ToString(), "Check sign success");
|
||||
return data;
|
||||
}
|
||||
|
||||
//派生类需要重写这个方法,进行不同的回调处理
|
||||
public abstract PayData ProcessNotify();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Yi.Framework.WeChatPay.Core
|
||||
{
|
||||
public class ResultNotify : AbstractNotify
|
||||
{
|
||||
private readonly PayApi _PayApi;
|
||||
private readonly ILogger<ResultNotify> _logger;
|
||||
public ResultNotify(PayApi PayApi,ILogger<ResultNotify> logger, IHttpContextAccessor httpContextAccessor) :base(httpContextAccessor)
|
||||
{
|
||||
this._PayApi = PayApi;
|
||||
this._logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理支付回调
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override PayData ProcessNotify()
|
||||
{
|
||||
PayData notifyData = GetNotifyData();
|
||||
//解析数据
|
||||
string totalFee = notifyData.GetValue("total_fee").ToString(); //订单金额
|
||||
string outTradeNo = notifyData.GetValue("out_trade_no").ToString(); //订单编号
|
||||
string transactionId = notifyData.GetValue("transaction_id").ToString(); //商户订单号
|
||||
string bankType = notifyData.GetValue("bank_type").ToString(); //银行类型
|
||||
|
||||
_logger.LogInformation($"======支付回调参数:{totalFee}=={outTradeNo}=={transactionId}=={bankType}");
|
||||
if (totalFee.Equals("") || outTradeNo.Equals("") || transactionId.Equals("") || bankType.Equals(""))
|
||||
{
|
||||
PayData res = new();
|
||||
res.SetValue("return_code", "FAIL");
|
||||
res.SetValue("return_msg", "支付回调返回数据不正确");
|
||||
_logger.LogInformation("支付错误结果 : " + res.ToXml());
|
||||
return res;
|
||||
}
|
||||
|
||||
//检查支付结果中transaction_id是否存在--流水号
|
||||
if (!notifyData.IsSet("transaction_id"))
|
||||
{
|
||||
//若transaction_id不存在,则立即返回结果给微信支付后台
|
||||
PayData res = new();
|
||||
res.SetValue("return_code", "FAIL");
|
||||
res.SetValue("return_msg", "支付结果中微信订单号不存在");
|
||||
_logger.LogInformation("支付错误结果 : " + res.ToXml());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//查询订单,判断订单真实性
|
||||
if (!QueryOrder(transactionId))
|
||||
{
|
||||
//若订单查询失败,则立即返回结果给微信支付后台
|
||||
PayData res = new();
|
||||
res.SetValue("return_code", "FAIL");
|
||||
res.SetValue("return_msg", "订单查询失败");
|
||||
_logger.LogInformation("订单查询失败 : " + res.ToXml());
|
||||
|
||||
return res;
|
||||
}
|
||||
//查询订单成功
|
||||
else
|
||||
{
|
||||
// 打印结果 (仅打印)
|
||||
PayData res = new PayData();
|
||||
res.SetValue("return_code", "SUCCESS");
|
||||
res.SetValue("return_msg", "OK");
|
||||
res.SetValue("transaction_id", transactionId);
|
||||
_logger.LogInformation("订单查成功: " + res.ToXml());
|
||||
|
||||
// 设置返回响应结果
|
||||
notifyData.SetValue("return_code", "SUCCESS");
|
||||
notifyData.SetValue("return_msg", "OK");
|
||||
|
||||
return notifyData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据流水号查询订单信息
|
||||
/// </summary>
|
||||
/// <param name="transaction_id"></param>
|
||||
/// <returns></returns>
|
||||
private bool QueryOrder(string transaction_id)
|
||||
{
|
||||
PayData req = new PayData();
|
||||
req.SetValue("transaction_id", transaction_id);
|
||||
PayData res = this._PayApi.OrderQuery(req, _httpContext);
|
||||
if (res.GetValue("return_code").ToString() == "SUCCESS" &&
|
||||
res.GetValue("result_code").ToString() == "SUCCESS")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Yi.Framework.Net6/Yi.Framework.WeChatPay/Core/PayInvoker.cs
Normal file
55
Yi.Framework.Net6/Yi.Framework.WeChatPay/Core/PayInvoker.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.WeChatPay.Options;
|
||||
|
||||
namespace Yi.Framework.WeChatPay.Core
|
||||
{
|
||||
public class PayInvoker:IPayInvoker
|
||||
{
|
||||
private readonly PayHelper _payHelper;
|
||||
private readonly ILogger<PayInvoker> _logger;
|
||||
private readonly AbstractNotify _notify;
|
||||
|
||||
public PayInvoker(PayHelper payHelper, ILogger<PayInvoker> logger, AbstractNotify notify)
|
||||
{
|
||||
this._payHelper = payHelper;
|
||||
this._logger = logger;
|
||||
this._notify = notify;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取WX支付链接的方法
|
||||
/// 然后发布定时同步状态任务
|
||||
/// </summary>
|
||||
/// <param name="orderId">订单ID</param>
|
||||
/// <param name="user">用户信息</param>
|
||||
/// <param name="httpContext">请求上下文</param>
|
||||
/// <returns>返回生成的支持链接</returns>
|
||||
public string GenerateUrl(long orderId, long totalPay)
|
||||
{
|
||||
string payUrl = null;
|
||||
_logger.LogInformation("准备生成支付链接.....");
|
||||
payUrl = _payHelper.CreatePayUrl(orderId, "微信支付链接", totalPay);
|
||||
_logger.LogInformation("生成支付链接为:{payUrl}", payUrl);
|
||||
return payUrl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理微信支付回调
|
||||
/// </summary>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <returns></returns>
|
||||
public PayData HandleNotify()
|
||||
{
|
||||
PayData wxPayData = this._notify.ProcessNotify();
|
||||
|
||||
return wxPayData;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Yi.Framework.WeChatPay.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
public class PayException : Exception
|
||||
{
|
||||
public PayException()
|
||||
{
|
||||
}
|
||||
|
||||
public PayException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public PayException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected PayException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Yi.Framework.WeChatPay.Options
|
||||
{
|
||||
public class PayOptions
|
||||
{
|
||||
public string AppID { get; set; }
|
||||
public string MchID { get; set; }
|
||||
public string Key { get; set; }
|
||||
public string NotifyUrl { get; set; }
|
||||
|
||||
public bool IsFileConfig { get; set; } = false;
|
||||
|
||||
public string ConfigPath { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.WeChatPay.Core;
|
||||
using Yi.Framework.WeChatPay.Exceptions;
|
||||
using Yi.Framework.WeChatPay.Options;
|
||||
|
||||
namespace Yi.Framework.WeChatPay.WebCore
|
||||
{
|
||||
public static class PayServiceExtensions
|
||||
{
|
||||
public static IServiceCollection AddWeChatPayService(this IServiceCollection services,Action<PayOptions> configure)
|
||||
{
|
||||
var option= new PayOptions();
|
||||
configure(option);
|
||||
if (option.IsFileConfig)
|
||||
{
|
||||
option=PayHelper.GetPayOptions(option.ConfigPath);
|
||||
}
|
||||
if (option.AppID == null)
|
||||
{
|
||||
throw new PayException("AppId为空值");
|
||||
}
|
||||
if (option.MchID == null)
|
||||
{
|
||||
throw new PayException("MchID为空值");
|
||||
}
|
||||
if (option.Key == null)
|
||||
{
|
||||
throw new PayException("Key为空值");
|
||||
}
|
||||
if (option.NotifyUrl == null)
|
||||
{
|
||||
throw new PayException("NotifyUrl为空值");
|
||||
}
|
||||
services.AddSingleton(option);
|
||||
services.AddTransient<PayInvoker>();
|
||||
services.AddTransient<IPayInvoker, PayInvoker>();
|
||||
services.AddTransient<IPayConfig, PayConfig>();
|
||||
services.AddTransient<PayHelper>();
|
||||
services.AddTransient<PayApi>();
|
||||
services.AddTransient<PayHttpService>();
|
||||
services.AddTransient<AbstractNotify, ResultNotify>();
|
||||
services.AddHttpContextAccessor();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
|
||||
<PackageReference Include="NBuilder" Version="6.1.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -3,6 +3,7 @@ using Microsoft.IdentityModel.JsonWebTokens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.WebCore.AttributeExtend
|
||||
@@ -40,11 +41,24 @@ namespace Yi.Framework.WebCore.AttributeExtend
|
||||
var perList = context.HttpContext.User.Claims.Where(u => u.Type == "permission").Select(u=> u.Value.ToString().ToLower()). ToList();
|
||||
//判断权限是否存在Redis中,或者jwt中
|
||||
|
||||
//if (perList.Contains(permission.ToLower()))
|
||||
//{
|
||||
// result = true;
|
||||
//}
|
||||
result = true;
|
||||
//进行正则表达式的匹配,以code开头
|
||||
Regex regex = new Regex($"^{permission.ToLower()}");
|
||||
foreach (var p in perList)
|
||||
{
|
||||
//过滤多余的标签
|
||||
p.Replace("Entity","");
|
||||
p.Replace("entity","");
|
||||
if (regex.IsMatch(p))
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//用户的增删改查直接可以user:*即可
|
||||
|
||||
|
||||
//这里暂时全部放行即可
|
||||
result = true;
|
||||
|
||||
|
||||
if (!result)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -15,6 +17,8 @@ namespace Yi.Framework.WebCore.BuilderExtend
|
||||
{
|
||||
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
|
||||
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm";
|
||||
|
||||
//options.SerializerSettings.Converters.Add(new ValueToStringConverter());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Yi.Framework.WebCore.BuilderExtend
|
||||
{
|
||||
if (JsonFile==null)
|
||||
{
|
||||
string[] myJsonFile = new string[] { "appsettings.json", "configuration.json" };
|
||||
string[] myJsonFile = new string[] { "appsettings.json", "Config/configuration.json" };
|
||||
foreach (var item in myJsonFile)
|
||||
{
|
||||
builder.AddJsonFile(item, optional: true, reloadOnChange: false);
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
|
||||
namespace Yi.Framework.WebCore
|
||||
{
|
||||
@@ -32,17 +33,22 @@ namespace Yi.Framework.WebCore
|
||||
/// <returns></returns>
|
||||
public static UserEntity GetCurrentUserEntityInfo(this HttpContext httpContext, out List<Guid> menuIds)
|
||||
{
|
||||
IEnumerable<Claim> claimlist = httpContext.AuthenticateAsync().Result.Principal.Claims;
|
||||
|
||||
long.TryParse(claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Sid).Value,out var resId) ;
|
||||
|
||||
IEnumerable<Claim> claimlist = null;
|
||||
long resId = 0;
|
||||
try
|
||||
{
|
||||
claimlist = httpContext.AuthenticateAsync().Result.Principal.Claims;
|
||||
resId = Convert.ToInt64(claimlist.FirstOrDefault(u => u.Type == JwtRegisteredClaimNames.Sid).Value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new Exception("未授权,Token鉴权失败!");
|
||||
}
|
||||
menuIds = claimlist.Where(u => u.Type == "menuIds").ToList().Select(u => new Guid(u.Value)).ToList();
|
||||
|
||||
|
||||
return new UserEntity()
|
||||
{
|
||||
Id = resId,
|
||||
Name = claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Name).Value
|
||||
//Name = claimlist.FirstOrDefault(u => u.Type == JwtRegisteredClaimNames.Name).Value
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
{
|
||||
public static void AddSqlsugarServer(this IServiceCollection services)
|
||||
{
|
||||
|
||||
|
||||
|
||||
DbType dbType;
|
||||
var slavaConFig = new List<SlaveConnectionConfig>();
|
||||
if (Appsettings.appBool("MutiDB_Enabled"))
|
||||
@@ -42,7 +45,19 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
DisableNvarchar = true
|
||||
},
|
||||
SlaveConnectionConfigs = slavaConFig,
|
||||
|
||||
//设置codefirst非空值判断
|
||||
ConfigureExternalServices = new ConfigureExternalServices
|
||||
{
|
||||
EntityService = (c, p) =>
|
||||
{
|
||||
// int? decimal?这种 isnullable=true
|
||||
if (c.PropertyType.IsGenericType &&
|
||||
c.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||
{
|
||||
p.IsNullable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
db =>
|
||||
{
|
||||
@@ -80,6 +95,10 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
|
||||
Console.WriteLine("_______________________________________________");
|
||||
Console.WriteLine("执行SQL:"+s.ToString());
|
||||
foreach (var i in p)
|
||||
{
|
||||
Console.WriteLine("参数:" +i.ParameterName+",参数值"+i.Value);
|
||||
}
|
||||
Console.WriteLine("_______________________________________________");
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
var apiXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//控制器层注释
|
||||
//var entityXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//实体注释
|
||||
//c.IncludeXmlComments(apiXmlPath, true);//true表示显示控制器注释
|
||||
c.IncludeXmlComments(apiXmlPath,true);
|
||||
c.IncludeXmlComments(apiXmlPath, true);
|
||||
|
||||
//添加控制器注释
|
||||
//c.DocumentFilter<SwaggerDocTag>();
|
||||
@@ -42,36 +42,51 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
//添加header验证信息
|
||||
//c.OperationFilter<SwaggerHeader>();
|
||||
//var security = new Dictionary<string, IEnumerable<string>> { { "Bearer", new string[] { } }, };
|
||||
c.AddSecurityDefinition("JwtBearer", new OpenApiSecurityScheme()
|
||||
{
|
||||
Description = "直接输入Token即可",
|
||||
Name = "Authorization",
|
||||
In = ParameterLocation.Header,
|
||||
Type = SecuritySchemeType.Http,
|
||||
Scheme = "bearer"
|
||||
});
|
||||
var scheme = new OpenApiSecurityScheme()
|
||||
{
|
||||
Reference = new OpenApiReference() { Type = ReferenceType.SecurityScheme, Id = "JwtBearer" }
|
||||
};
|
||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement()
|
||||
{
|
||||
[scheme] = new string[0]
|
||||
});
|
||||
//c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
|
||||
//{
|
||||
// Description = "文本框里输入从服务器获取的Token。格式为:Bearer + 空格+token",//JWT授权(数据将在请求头中进行传输) 参数结构: \"Authorization: Bearer {token}\"
|
||||
// Name = "Authorization",////jwt默认的参数名称
|
||||
// In = ParameterLocation.Header,////jwt默认存放Authorization信息的位置(请求头中)
|
||||
// Type = SecuritySchemeType.ApiKey,
|
||||
//});
|
||||
//c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
//{
|
||||
// { new OpenApiSecurityScheme
|
||||
// {
|
||||
// Reference = new OpenApiReference()
|
||||
// {
|
||||
// Id = "Bearer",
|
||||
// Type = ReferenceType.SecurityScheme
|
||||
// }
|
||||
// }, Array.Empty<string>() }
|
||||
//});
|
||||
|
||||
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
|
||||
{
|
||||
Description = "文本框里输入从服务器获取的Token。格式为:Bearer + 空格+token",//JWT授权(数据将在请求头中进行传输) 参数结构: \"Authorization: Bearer {token}\"
|
||||
Name = "Authorization",////jwt默认的参数名称
|
||||
In = ParameterLocation.Header,////jwt默认存放Authorization信息的位置(请求头中)
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
});
|
||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{ new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference()
|
||||
{
|
||||
Id = "Bearer",
|
||||
Type = ReferenceType.SecurityScheme
|
||||
}
|
||||
}, Array.Empty<string>() }
|
||||
});
|
||||
|
||||
c.AddServer(new OpenApiServer()
|
||||
{
|
||||
Url = "https://ccnetcore.com",
|
||||
Description = "Yi-Framework"
|
||||
});
|
||||
c.CustomOperationIds(apiDesc =>
|
||||
{
|
||||
var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor;
|
||||
return controllerAction.ActionName;
|
||||
});
|
||||
//c.AddServer(new OpenApiServer()
|
||||
//{
|
||||
// Url = "https://ccnetcore.com",
|
||||
// Description = "Yi-Framework"
|
||||
//});
|
||||
//c.CustomOperationIds(apiDesc =>
|
||||
//{
|
||||
// var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor;
|
||||
// return controllerAction.ActionName;
|
||||
//});
|
||||
});
|
||||
#endregion
|
||||
|
||||
@@ -85,27 +100,12 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
app.UseSwagger();
|
||||
|
||||
|
||||
app.UseKnife4UI(c =>
|
||||
{
|
||||
c.RoutePrefix = "swagger"; // serve the UI at root
|
||||
if (swaggerModels.Length == 0)
|
||||
{
|
||||
c.SwaggerEndpoint("/v1/swagger.json", "Yi.Framework");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var k in swaggerModels)
|
||||
{
|
||||
c.SwaggerEndpoint(k.url, k.name);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//app.UseSwaggerUI(c =>
|
||||
//app.UseKnife4UI(c =>
|
||||
//{
|
||||
// c.RoutePrefix = "swagger"; // serve the UI at root
|
||||
// if (swaggerModels.Length == 0)
|
||||
// {
|
||||
// c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework");
|
||||
// c.SwaggerEndpoint("/v1/swagger.json", "Yi.Framework");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
@@ -114,10 +114,25 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
// c.SwaggerEndpoint(k.url, k.name);
|
||||
// }
|
||||
// }
|
||||
//});
|
||||
|
||||
//}
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
if (swaggerModels.Length == 0)
|
||||
{
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var k in swaggerModels)
|
||||
{
|
||||
c.SwaggerEndpoint(k.url, k.name);
|
||||
}
|
||||
}
|
||||
|
||||
//);
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,9 +41,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Job", "Yi.Fram
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.SMSProcessor", "Yi.Framework.SMSProcessor\Yi.Framework.SMSProcessor.csproj", "{7C58FB7C-9AB5-47CF-ACEB-B784CF820E7E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Repository", "Yi.Framework.Repository\Yi.Framework.Repository.csproj", "{DA96B62F-2D4C-4AFB-937C-5AEA1119A129}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Repository", "Yi.Framework.Repository\Yi.Framework.Repository.csproj", "{DA96B62F-2D4C-4AFB-937C-5AEA1119A129}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Language", "Yi.Framework.Language\Yi.Framework.Language.csproj", "{3047069B-4084-461F-BC9F-023BC60401D1}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Language", "Yi.Framework.Language\Yi.Framework.Language.csproj", "{3047069B-4084-461F-BC9F-023BC60401D1}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.WeChatPay", "Yi.Framework.WeChatPay\Yi.Framework.WeChatPay.csproj", "{C307189D-C42C-4C09-BB65-5A386C9F182B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -115,6 +117,10 @@ Global
|
||||
{3047069B-4084-461F-BC9F-023BC60401D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3047069B-4084-461F-BC9F-023BC60401D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3047069B-4084-461F-BC9F-023BC60401D1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C307189D-C42C-4C09-BB65-5A386C9F182B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C307189D-C42C-4C09-BB65-5A386C9F182B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C307189D-C42C-4C09-BB65-5A386C9F182B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C307189D-C42C-4C09-BB65-5A386C9F182B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -136,6 +142,7 @@ Global
|
||||
{7C58FB7C-9AB5-47CF-ACEB-B784CF820E7E} = {D6B44435-EAFA-4D55-90D0-3AF80485FB83}
|
||||
{DA96B62F-2D4C-4AFB-937C-5AEA1119A129} = {DB2506F5-05FD-4E76-940E-41D7AA148550}
|
||||
{3047069B-4084-461F-BC9F-023BC60401D1} = {9ABAF6B1-6C02-498A-90A2-ABC1140CF89A}
|
||||
{C307189D-C42C-4C09-BB65-5A386C9F182B} = {9ABAF6B1-6C02-498A-90A2-ABC1140CF89A}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {1ED77A6E-377F-4EEF-A3D0-D65C94657DAF}
|
||||
|
||||
3
Yi.Vue2.x/.browserslistrc
Normal file
3
Yi.Vue2.x/.browserslistrc
Normal file
@@ -0,0 +1,3 @@
|
||||
> 1%
|
||||
last 2 versions
|
||||
not dead
|
||||
4
Yi.Vue2.x/.env.development
Normal file
4
Yi.Vue2.x/.env.development
Normal file
@@ -0,0 +1,4 @@
|
||||
#接口服务地址
|
||||
VUE_APP_SERVICE_URL='http://localhost:19001/api'
|
||||
#开发环境路径前缀
|
||||
VUE_APP_BASE_API='/dev-apis'
|
||||
2
Yi.Vue2.x/.env.production
Normal file
2
Yi.Vue2.x/.env.production
Normal file
@@ -0,0 +1,2 @@
|
||||
#生成环境路径前缀
|
||||
VUE_APP_BASE_API='/prod-apis'
|
||||
23
Yi.Vue2.x/.gitignore
vendored
Normal file
23
Yi.Vue2.x/.gitignore
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/dist
|
||||
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Log files
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
.vscode
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
19
Yi.Vue2.x/README.md
Normal file
19
Yi.Vue2.x/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# vuetify-test
|
||||
|
||||
## Project setup
|
||||
```
|
||||
npm install
|
||||
```
|
||||
|
||||
### Compiles and hot-reloads for development
|
||||
```
|
||||
npm run serve
|
||||
```
|
||||
|
||||
### Compiles and minifies for production
|
||||
```
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Customize configuration
|
||||
See [Configuration Reference](https://cli.vuejs.org/config/).
|
||||
10212
Yi.Vue2.x/package-lock.json
generated
Normal file
10212
Yi.Vue2.x/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
Yi.Vue2.x/package.json
Normal file
30
Yi.Vue2.x/package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "vuetify-test",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mdi/font": "^6.6.96",
|
||||
"axios": "^0.22.0",
|
||||
"json-bigint": "^1.0.0",
|
||||
"typeface-roboto": "^1.1.13",
|
||||
"vue": "^2.6.11",
|
||||
"vue-chartist": "^2.3.1",
|
||||
"vue-router": "^3.2.0",
|
||||
"vuetify": "^2.4.0",
|
||||
"vuetify-dialog": "^2.0.17",
|
||||
"vuex": "^3.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-router": "~4.5.0",
|
||||
"@vue/cli-service": "~4.5.0",
|
||||
"sass": "~1.32.0",
|
||||
"sass-loader": "^10.0.0",
|
||||
"vue-cli-plugin-vuetify": "~2.4.2",
|
||||
"vue-template-compiler": "^2.6.11",
|
||||
"vuetify-loader": "^1.7.0"
|
||||
}
|
||||
}
|
||||
BIN
Yi.Vue2.x/public/favicon.ico
Normal file
BIN
Yi.Vue2.x/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
20
Yi.Vue2.x/public/index.html
Normal file
20
Yi.Vue2.x/public/index.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||
<title>Yi-Vue</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but Yi-Vue doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
</body>
|
||||
|
||||
</html>
|
||||
23
Yi.Vue2.x/src/App.vue
Normal file
23
Yi.Vue2.x/src/App.vue
Normal file
@@ -0,0 +1,23 @@
|
||||
<template>
|
||||
<v-fade-transition mode="out-in">
|
||||
<router-view />
|
||||
</v-fade-transition>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// Styles
|
||||
import '@/styles/overrides.sass'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
metaInfo: {
|
||||
title: 'App',
|
||||
titleTemplate: '%s | Material Dashboard Free',
|
||||
htmlAttrs: { lang: 'en' },
|
||||
meta: [
|
||||
{ charset: 'utf-8' },
|
||||
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
||||
],
|
||||
},
|
||||
}
|
||||
</script>
|
||||
61
Yi.Vue2.x/src/api/accountApi.js
Normal file
61
Yi.Vue2.x/src/api/accountApi.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import myaxios from '@/util/myaxios'
|
||||
export default {
|
||||
login(username, password) {
|
||||
return myaxios({
|
||||
url: '/Account/login',
|
||||
method: 'post',
|
||||
data: {
|
||||
username,
|
||||
password
|
||||
}
|
||||
})
|
||||
},
|
||||
logout() {
|
||||
return myaxios({
|
||||
url: '/Account/logout',
|
||||
method: 'post',
|
||||
})
|
||||
},
|
||||
register(username, password, phone, code) {
|
||||
return myaxios({
|
||||
url: `/Account/register?code=${code}`,
|
||||
method: 'post',
|
||||
data: { username, password, phone }
|
||||
})
|
||||
},
|
||||
email(emailAddress) {
|
||||
return myaxios({
|
||||
url: `/Account/email?emailAddress=${emailAddress}`,
|
||||
method: 'post',
|
||||
})
|
||||
},
|
||||
SendSMS(smsAddress) {
|
||||
return myaxios({
|
||||
url: `/Account/SendSMS?SMSAddress=${smsAddress}`,
|
||||
method: 'post',
|
||||
})
|
||||
},
|
||||
updatePassword(oldPassword, newPassword) {
|
||||
return myaxios({
|
||||
url: `/Account/updatePassword`,
|
||||
method: 'put',
|
||||
data: { oldPassword, newPassword }
|
||||
})
|
||||
},
|
||||
getUserAllInfo()
|
||||
{
|
||||
return myaxios({
|
||||
url: `/Account/getUserAllInfo`,
|
||||
method: 'get'
|
||||
})
|
||||
},
|
||||
updateUserByHttp(user)
|
||||
{
|
||||
return myaxios({
|
||||
url: `/Account/updateUserByHttp`,
|
||||
method: 'put',
|
||||
data:user
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
11
Yi.Vue2.x/src/api/fileApi.js
Normal file
11
Yi.Vue2.x/src/api/fileApi.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import myaxios from '@/util/myaxios'
|
||||
export default {
|
||||
UploadImage(file) {
|
||||
return myaxios({
|
||||
url: '/Upload/image',
|
||||
method: 'post',
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
data: file
|
||||
})
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user