|
|
@@ -16,6 +16,8 @@ import cn.start.tz.module.system.api.social.dto.SocialUserRespDTO;
|
|
|
import cn.start.tz.module.system.controller.admin.auth.vo.*;
|
|
|
import cn.start.tz.module.system.controller.admin.clientunit.vo.UnitContactRespVO;
|
|
|
import cn.start.tz.module.system.controller.admin.supervisionunitaccount.vo.SupervisionUnitAccountRespVO;
|
|
|
+import cn.start.tz.module.system.controller.appapi.auth.vo.AuthAppTokenLoginReqVO;
|
|
|
+import cn.start.tz.module.system.controller.appapi.auth.vo.AuthYiqunUserDTO;
|
|
|
import cn.start.tz.module.system.convert.auth.AuthConvert;
|
|
|
import cn.start.tz.module.system.dal.dataobject.clientunit.ClientUnitDO;
|
|
|
import cn.start.tz.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
|
|
|
@@ -38,6 +40,7 @@ import cn.start.tz.module.system.service.supervisionunitaccount.SupervisionUnitA
|
|
|
import cn.start.tz.module.system.service.user.AdminUserService;
|
|
|
import com.alibaba.cloud.commons.lang.StringUtils;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
import com.xingyuv.captcha.model.common.ResponseModel;
|
|
|
@@ -50,8 +53,13 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
@@ -112,6 +120,9 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
|
|
|
@Resource
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RestTemplate restTemplate;
|
|
|
/**
|
|
|
* 验证码的开关,默认为 true
|
|
|
*/
|
|
|
@@ -340,6 +351,46 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
return respVO;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public AuthLoginRespVO loginByAppToken(AuthAppTokenLoginReqVO reqVO) {
|
|
|
+ HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
+ httpHeaders.add("Authorization", "Bearer " + reqVO.getAppToken());
|
|
|
+ httpHeaders.add("Content-Type", "application/json");
|
|
|
+
|
|
|
+ HttpEntity<Object> req = new HttpEntity<>(null, httpHeaders);
|
|
|
+ String baseUrl = "https://cloud-admin-uat.gzsei.com";
|
|
|
+ // 使用 token 交换用户信息
|
|
|
+ ResponseEntity<String> yiqunResp = restTemplate.postForEntity(baseUrl + "/external-api/system/auth/app-auth", req, String.class);
|
|
|
+ AuthYiqunUserDTO user = null;
|
|
|
+ if (!yiqunResp.getStatusCode().equals(HttpStatus.OK)) {
|
|
|
+ log.warn("[authenticate] APPToken 无效");
|
|
|
+ } else {
|
|
|
+ String json = yiqunResp.getBody();
|
|
|
+ try {
|
|
|
+ JsonNode jsonNode = objectMapper.readTree(json);
|
|
|
+ user = objectMapper.convertValue(jsonNode.get("data"), AuthYiqunUserDTO.class);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (user == null) {
|
|
|
+ log.warn("[authenticate] APPToken 无效");
|
|
|
+ createLoginLog(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_YIQUNAPP, LoginResultEnum.BAD_CREDENTIALS);
|
|
|
+ throw exception(AUTH_LOGIN_BAD_CREDENTIALS);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// log.info("[authenticate] 用户认证开始, appToken={}", reqVO.getAppToken());
|
|
|
+// AuthYiqunUserDTO user = new AuthYiqunUserDTO();
|
|
|
+// user.setId("598e72abeed14ceeba13c4dfcd036326");
|
|
|
+// user.setNickname("chenya1");
|
|
|
+
|
|
|
+ log.info("[authenticate] 用户认证通过, userId={}", user.getId());
|
|
|
+ // 创建 Token 令牌,记录登录日志
|
|
|
+ return createTokenAfterLoginSuccessApp(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public AuthLoginRespVO createTokenAfterLoginSuccessApp(String userId, String username, LoginLogTypeEnum logType) {
|
|
|
// 插入登陆日志
|