From 0ac5707edb7d07d4889bdce2da0f4f189fe0adcb Mon Sep 17 00:00:00 2001 From: wyw <571921741@qq.com> Date: Fri, 13 Mar 2026 17:19:59 +0800 Subject: [PATCH] =?UTF-8?q?Gen=20=E6=96=B9=E6=B3=95=20=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BB=A3=E7=A0=81=20GetUser=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20=E5=AF=86=E7=A0=81=E5=88=A4=E6=96=AD=20=E8=BD=AC?= =?UTF-8?q?=E5=A4=A7=E5=86=99=20=E5=B0=91=E5=AE=9A=E4=B9=89=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/TokenController.cs | 84 +------------------ 1 file changed, 4 insertions(+), 80 deletions(-) diff --git a/APT.MicroApi/APT.PF.WebApi/Controllers/Api/TokenController.cs b/APT.MicroApi/APT.PF.WebApi/Controllers/Api/TokenController.cs index 7728b4c..5223da1 100644 --- a/APT.MicroApi/APT.PF.WebApi/Controllers/Api/TokenController.cs +++ b/APT.MicroApi/APT.PF.WebApi/Controllers/Api/TokenController.cs @@ -46,28 +46,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM if (request.Grant_type == (int)PFGrantTypeEnum.账号密码) { var client = new System.Net.Http.HttpClient(); - /// - //var disco = await client.GetDiscoveryDocumentAsync(ConfigurationManager.AppSettings["IdentityServer"]); - //if (disco.IsError) - //{ - // Console.WriteLine(disco.Error); - // return BadRequest(new { error = disco.Error, error_description = "验证服务器无法连接" }); - //} - BaseFilter filter = new BaseFilter(); - //if (string.IsNullOrEmpty(request.orgId)) - //{ - //using (var context = new MigrationContext(ConfigurationManager.ConnectionStrings["default"])) - //{ - // var opUser = context.GetEntity(i => i.CODE == request.UserName || i.PHONE == request.UserName, new string[] { "CODE", "TENANT", "PHONE" }); - // if (opUser == null) - // throw new Exception("用户账号不存在"); - // filter.IsSpecifyDb = true; - // filter.SpecifyTenant = opUser.TENANT; - // filter.IgnoreOrgRule = true; - // //request.orgId = opUser.ORG_ID.ToString(); - //} - //} if (request.ClientId != "app") { if (!string.IsNullOrEmpty(request.random)) @@ -82,29 +61,16 @@ namespace APT.PF.WebApi.Controllers.Api.FM return BadRequest(new { error = "error VERIFY_CODE ", error_description = "验证码不正确" }); } } - //filter.OrgId = new Guid(request.orgId); - } - else - { - //filter.IgnoreOrgRule = true; - //filter.IsMultipleDb = true; - } var user = this.GetUser(request, filter); if (user == null) return BadRequest(new { error = "error Account ", error_description = "用户不存在或者密码错误" }); ; - // request access token - //var scope = "offline_access oEnergyPF oEnergyBD oEnergyDD oEnergyEA oEnergyED oEnergyEM oEnergyFC oEnergyFM oEnergyKR oEnergyLG" + - // " oEnergyMR oEnergyNW oEnergyPM oEnergyQC oEnergyUT oEnergyMT"; - // oEnergyMT oEnergySO oEnergyCP oEnergyFC oEnergyCM oEnergyCA var scope = "offline_access oEnergyPF oEnergyBD oEnergyDD oEnergyEA oEnergyED oEnergyEM oEnergyFC oEnergyFM oEnergyKR oEnergyLG" + " oEnergyMR oEnergyNW oEnergyPM oEnergyQC oEnergyUT oEnergyMT oEnergySO oEnergyCP oEnergyCM oEnergyCA oEnergyHM oEnergyPP oEnergyFO oEnergyBS oEnergySC"; - //var scope = GetAllScopes(user.ORG_ID ?? Guid.Empty); var dic = new Dictionary(); dic.Add("UserId", user.ID.ToString()); var tokenResponse = await client.RequestPasswordTokenAsync(new PasswordTokenRequest { - //Address = disco.TokenEndpoint, Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token", ClientId = ConfigurationManager.AppSettings["ClientId"], ClientSecret = ConfigurationManager.AppSettings["SecurityKey"], @@ -119,39 +85,13 @@ namespace APT.PF.WebApi.Controllers.Api.FM return BadRequest(new { error = tokenResponse.Error, error_description = tokenResponse.Error ?? tokenResponse.ErrorDescription }); } int second = 60; - /* - #region 是否发送手机验证码 - - var orgId = new Guid(request.orgId); - BaseFilter baseFilter = new BaseFilter(orgId); - var commonService = APT.Infrastructure.Api.ServiceLocator.Instance.GetService(); - var baseConfig = commonService.GetEntity(null, baseFilter, "Nav_MessageTemplate"); - var belongRoles = commonService.GetEntities(x => x.USER_ID == user.ID, baseFilter, "Nav_BelongRole"); - var isCheckPhoneCode = false; - - if (baseConfig != null && baseConfig.IS_CHECK_MESSAGE)//新增用户站点参数为null - { - foreach (var belongRole in belongRoles) - { - if (belongRole.Nav_BelongRole.IS_CHECK_MESSAGE) - { - isCheckPhoneCode = true; - } - } - if (string.IsNullOrEmpty(user.PHONE)) - { - return BadRequest(new { error = "error phoneNull ", error_description = "已开启手机短信验证,请先维护手机号码!" }); - } - } - #endregion - */ return Ok(new { access_token = tokenResponse.AccessToken, token_type = tokenResponse.TokenType, expiresIn = tokenResponse.ExpiresIn, userid = user.ID, - userName=user.CODE, + userName = user.CODE, orgId = user.ORG_ID, refreshToken = tokenResponse.RefreshToken, isCheckPhoneCode = false, @@ -163,17 +103,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM else if (request.Grant_type == (int)PFGrantTypeEnum.客户端) { var client = new System.Net.Http.HttpClient(); - //var disco = await client.GetDiscoveryDocumentAsync(ConfigurationManager.AppSettings["IdentityServer"]); - //if (disco.IsError) - //{ - // Console.WriteLine(disco.Error); - // return BadRequest(new { error = "identity server Error", error_description = "验证服务器无法连接" }); - //} - // request access token - //获取clentid的scops var scope = "oEnergyBD oEnergyLG oEnergyFM oEnergyPF oEnergyOP oEnergyPP"; - //var dataChanel = GetDataChanel(request); - //var scope = GetScopes(request); var tokenResponse = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest { Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token", @@ -192,7 +122,6 @@ namespace APT.PF.WebApi.Controllers.Api.FM token_type = tokenResponse.TokenType, refreshToken = tokenResponse.RefreshToken, expiresIn = tokenResponse.ExpiresIn, - //dataChanel = dataChanel, }); } if (request.Grant_type == (int)PFGrantTypeEnum.Refresh) @@ -201,7 +130,6 @@ namespace APT.PF.WebApi.Controllers.Api.FM var tokenResponse = await client.RequestRefreshTokenAsync(new RefreshTokenRequest { - //Address = disco.TokenEndpoint, Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token", ClientId = ConfigurationManager.AppSettings["ClientId"], ClientSecret = ConfigurationManager.AppSettings["SecurityKey"], @@ -226,10 +154,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM catch (Exception ex) { return BadRequest(new { error = "excetion", error_description = ex.Message }); - //return BadRequest(new { error = "excetion", error_description = ex.Message + ex.Source + "," + ex.StackTrace + "," + ex.TargetSite }); } - - } [HttpPost, Route("AppGen")] public async Task AppGen([FromBody] TokenRequest request) @@ -318,10 +243,9 @@ namespace APT.PF.WebApi.Controllers.Api.FM filter.IgnoreOrgRule = true; } //} - var pwdLower = request.Password.ToLower(); + var md5SuperPwd = DataHelper.MD5(SUPER_PASSWORD).ToUpper(); var pwdUpper = request.Password.ToUpper(); - var md5SuperPwd = DataHelper.MD5(SUPER_PASSWORD); - if (pwdLower == md5SuperPwd || pwdUpper == md5SuperPwd) + if (md5SuperPwd == pwdUpper) { loginUser = commonService.GetEntity(i => (i.CODE == request.UserName || i.PHONE == request.UserName), filter); @@ -334,7 +258,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM || i.PHONE == request.UserName), filter); if (loginUser == null) throw new Exception("用户信息不存在"); - if (loginUser.PASSWORD != pwdLower && loginUser.PASSWORD != pwdUpper) + if (loginUser.PASSWORD.ToUpper() != pwdUpper) { throw new Exception("用户名或密码错误"); }