wet 2 years ago
parent f86fe6d979
commit e8b819deb4

@ -1,5 +1,6 @@
using Furion;
using Furion.DataEncryption;
using Furion.RemoteRequest.Extensions;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@ -12,6 +13,7 @@ using RabbitMQ.Client.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Security.Claims;
using System.Text;
using System.Threading;
@ -38,15 +40,18 @@ namespace Myshipping.Core.MQ
private readonly SqlSugarRepository<SysRole> _sysRoleRep;
private readonly SqlSugarRepository<SysMenu> _sysMenuRep;
private readonly ISysRoleMenuService _sysRoleMenuService;
private readonly IAuthService _IAuthService;
private IConnection mqConn;
private IModel model;
public RecCompanyUserChangeService(IServiceScopeFactory scopeFactory, ISysUserService serviceUser, ISysRoleMenuService sysRoleMenuService)
public RecCompanyUserChangeService(IServiceScopeFactory scopeFactory, ISysUserService serviceUser, ISysRoleMenuService sysRoleMenuService,IAuthService IAuthService)
{
_scopeFactory = scopeFactory;
//通过这个注入DBContext
_serviceScope = _scopeFactory.CreateScope();
_serviceUser = serviceUser;
_IAuthService = IAuthService;
_sysRoleMenuService = sysRoleMenuService;
_logger = _serviceScope.ServiceProvider.GetService<ILogger<RecCompanyUserChangeService>>();
_tenantService = _serviceScope.ServiceProvider.GetService<ISysTenantService>();
@ -103,26 +108,16 @@ namespace Myshipping.Core.MQ
private async void Consumer_Received(object ch, BasicDeliverEventArgs ea)
{
//授权---------- (用超级管理员的权限)
var httpContext = App.HttpContext;
var sysTenant = _sysTenantRep.AsQueryable().Filter(null, true).First(x => x.TenantType == TenantTypeEnum.SYSTEM);
var systemtenantid = sysTenant.Id;
var userauth = _sysUserRep.AsQueryable().Filter(null, true).First(x => x.Account == "superAdmin" && x.TenantId == systemtenantid);
ClaimsIdentity identity = new ClaimsIdentity("AuthenticationTypes.Federation");
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_USERID, value: userauth.Id.ToString()));
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_ACCOUNT, value: userauth.Account));
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_NAME, value: userauth.Name));
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_SUPERADMIN, value: ((int)userauth.AdminType).ToString()));
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_TENANT_TYPE, value: sysTenant.TenantType.ToString()));
identity.AddClaim(new Claim(type: ClaimConst.TENANT_ID, value: sysTenant.Id.ToString()));
identity.AddClaim(new Claim(type: ClaimConst.TENANT_NAME, value: sysTenant.Name));
identity.AddClaim(new Claim(type: ClaimConst.DjyUserId, value: userauth.DjyUserId));
ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity);
httpContext.User = claimsPrincipal;
//获取授权---------- (用超级管理员的权限)
LoginInput login = new LoginInput();
login.Account = "superAdmin";
login.Password = "123456";
var rtn = "http://localhost:5000/login".SetHttpMethod(HttpMethod.Post).SetContentType("application/json").SetBody(login.ToJsonString()).SetRetryPolicy(3, 5000).PostAsStringAsync();
var token = JObject.Parse(rtn.Result).GetStringValue("data");
var headers = new Dictionary<string, object>();
headers.Add("Authorization", $"Bearer {token}");
//-----
var body = ea.Body;
var strBody = Encoding.UTF8.GetString(body.ToArray());
@ -204,7 +199,9 @@ namespace Myshipping.Core.MQ
PosIdList.Add(pos.Id);
empOutput2.PosIdList = PosIdList;
adduser.SysEmpParam = empOutput2;
await _serviceUser.AddUser(adduser, true);
await "http://localhost:5000/sysUser/add".SetHeaders(headers).SetHttpMethod(HttpMethod.Post).SetBody(adduser).SetRetryPolicy(3, 5000).PostAsStringAsync();
// await _serviceUser.AddUser(adduser, true);
}
//-----授权角色id普通用户
@ -297,7 +294,10 @@ namespace Myshipping.Core.MQ
PosIdList.Add(pos.Id);
empOutput2.PosIdList = PosIdList;
adduser.SysEmpParam = empOutput2;
await _serviceUser.AddUser(adduser, true);
//await _serviceUser.AddUser(adduser, true);
await "http://localhost:5000/sysUser/add".SetHeaders(headers).SetHttpMethod(HttpMethod.Post).SetBody(adduser).SetRetryPolicy(3, 5000).PostAsStringAsync();
}
//-----授权角色id普通用户

Loading…
Cancel
Save