From 270eac85987db54a74ff74ffd55b5056a7085902 Mon Sep 17 00:00:00 2001 From: yjz <3131811435@qq.com> Date: Tue, 31 Oct 2023 13:41:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(iam):=20=E5=8D=95=E7=82=B9=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/impl/LoginServiceImpl.java | 36 +++---------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java b/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java index e537a678..8ab89ff7 100644 --- a/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java +++ b/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java @@ -2,8 +2,6 @@ package com.jero.modules.system.service.impl; import cn.hutool.core.util.RandomUtil; import cn.hutool.crypto.asymmetric.RSA; -import cn.hutool.poi.excel.ExcelUtil; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.aliyuncs.exceptions.ClientException; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -244,55 +242,29 @@ public class LoginServiceImpl implements ILoginService { private OauthUserInfo getUserInfo(Oauth oauth, OauthAccessToken oauthAccessToken) { String userInfoUrl = oauth.getUserInfoUrl() + "?access_token=" + oauthAccessToken.getAccessToken() + "&client_id=" + oauth.getClientId(); - /** - * 如果返回json - * OauthUserInfo oauthUserInfo = restTemplate.getForObject(userInfoUrl, OauthUserInfo.class); - */ - - // 返回String --> jsonString --> jsonObject --> 实体 - String resultStr = restTemplate.getForObject(userInfoUrl, String.class); - JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(resultStr)); - OauthUserInfo oauthUserInfo = JSON.toJavaObject(jsonObject, OauthUserInfo.class); - + OauthUserInfo oauthUserInfo = restTemplate.getForObject(userInfoUrl, OauthUserInfo.class); if (Objects.isNull(oauthUserInfo) || Objects.isNull(oauthUserInfo.getSpRoleList()) || oauthUserInfo.getSpRoleList().isEmpty()){ throw new JeroBootException("获取用户信息返回信息为空!"); } - if (StringUtils.isBlank(oauthUserInfo.getErrCode())){ + if (StringUtils.isNotBlank(oauthUserInfo.getErrCode())){ throw new JeroBootException(oauthUserInfo.getMsg()); } return oauthUserInfo; } private OauthAccessToken getAccessToken(Oauth oauth) { - /** - // 1.表单提交方式 - // 设置为表单提交,按需求加 - HttpHeaders headers = new HttpHeaders(); - headers.add("Content-Type","application/x-www-form-urlencoded"); - headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - // 组装请求信息 - MultiValueMap params = new LinkedMultiValueMap<>(); - params.add("client_id", oauth.getClientId()); - params.add("client_secret", oauth.getClientSecret()); - params.add("grant_type", oauth.getGrantType()); - params.add("redirect_uri", oauth.getRedirectUri()); - params.add("code", oauth.getCode()); - HttpEntity> requestEntity = new HttpEntity<>(params, headers); - OauthAccessToken oauthAccessToken = restTemplate.postForObject(oauth.getAccessTokenUrl(), requestEntity, OauthAccessToken.class); - */ - // 2.params传参 String accessTokenUrl = oauth.getAccessTokenUrl(); // 拼接参数 accessTokenUrl = accessTokenUrl + "?client_id=" + oauth.getClientId() + "&grant_type=" + oauth.getGrantType() + "&code=" + oauth.getCode() - + "&client_secret" + oauth.getClientSecret(); + + "&client_secret=" + oauth.getClientSecret(); OauthAccessToken oauthAccessToken = restTemplate.postForObject(accessTokenUrl, null, OauthAccessToken.class); if (Objects.isNull(oauthAccessToken) || StringUtils.isBlank(oauthAccessToken.getAccessToken())){ throw new JeroBootException("获取AccessToken返回信息为空!"); } - if (StringUtils.isBlank(oauthAccessToken.getErrCode())){ + if (StringUtils.isNotBlank(oauthAccessToken.getErrCode())){ throw new JeroBootException(oauthAccessToken.getMsg()); } return oauthAccessToken;