diff --git a/src/main/java/com/upchina/business/service/BusinessApiService.java b/src/main/java/com/upchina/business/service/BusinessApiService.java index ad6844d..d3c890d 100644 --- a/src/main/java/com/upchina/business/service/BusinessApiService.java +++ b/src/main/java/com/upchina/business/service/BusinessApiService.java @@ -66,8 +66,9 @@ public class BusinessApiService { public static void main(String[] args) { BusinessApiService service = new BusinessApiService(); - BusinessLoginVO loginVO = service.loginByUserName("sz545138", "Abc@123"); - String token = loginVO.getToken(); +// BusinessLoginVO loginVO = service.loginByUserName("sz545138", "Abc@123"); +// String token = loginVO.getToken(); + String token = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1NDUxMzgiLCJpYXQiOjE3Mzk5NTcxMjYsImV4cCI6MTczOTk2MDcyNn0.02FnOeW7RnIeI7sqwTTw0H9NPj03iFRAkr9PPXwpaDMgRTK2v7krDqAYa6dSIkuGx8wnKWPp-kcA4Ajr_MLjdw"; BusinessUserVO userVO = service.getUserByToken(token); System.out.println(JSONUtil.toJsonStr(userVO)); service.getUserModuleList(userVO.getUserId().toString()); diff --git a/src/main/java/com/upchina/common/constant/AppLoginType.java b/src/main/java/com/upchina/common/constant/AppLoginType.java new file mode 100644 index 0000000..28c1182 --- /dev/null +++ b/src/main/java/com/upchina/common/constant/AppLoginType.java @@ -0,0 +1,26 @@ +package com.upchina.common.constant; + +// 登录方式 1:用户名密码 2:token +public enum AppLoginType { + + USERNAME_PASSWORD(1, "用户名密码"), + TOKEN(2, "token"), + ; + + public final Integer value; + + public final String name; + + AppLoginType(Integer value, String name) { + this.value = value; + this.name = name; + } + + public Integer getValue() { + return value; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/com/upchina/common/query/AppUserInfoQuery.java b/src/main/java/com/upchina/common/query/AppUserInfoQuery.java index e7ee119..5c68102 100644 --- a/src/main/java/com/upchina/common/query/AppUserInfoQuery.java +++ b/src/main/java/com/upchina/common/query/AppUserInfoQuery.java @@ -4,47 +4,79 @@ import io.swagger.annotations.ApiModelProperty; import javax.validation.constraints.Max; import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; - public class AppUserInfoQuery { - @ApiModelProperty("用户ID") - @NotBlank + @ApiModelProperty("登录方式 1:用户名密码 2:token") + @NotNull + @Min(1) + @Max(2) + private Integer loginType; + + @ApiModelProperty("用户名") private String userName; @ApiModelProperty("密码") - @NotBlank private String password; + @ApiModelProperty("token") + private String token; + + @ApiModelProperty("refreshToken") + private String refreshToken; + @ApiModelProperty("客户类型 1:H5 2:Web") @NotNull @Min(1) @Max(2) private Integer clientType; - public @NotBlank String getUserName() { + public Integer getLoginType() { + return loginType; + } + + public void setLoginType(Integer loginType) { + this.loginType = loginType; + } + + public String getUserName() { return userName; } - public void setUserName(@NotBlank String userName) { + public void setUserName(String userName) { this.userName = userName; } - public @NotBlank String getPassword() { + public String getPassword() { return password; } - public void setPassword(@NotBlank String password) { + public void setPassword(String password) { this.password = password; } - public @NotNull @Min(1) @Max(2) Integer getClientType() { + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getRefreshToken() { + return refreshToken; + } + + public void setRefreshToken(String refreshToken) { + this.refreshToken = refreshToken; + } + + public Integer getClientType() { return clientType; } - public void setClientType(@NotNull @Min(1) @Max(2) Integer clientType) { + public void setClientType(Integer clientType) { this.clientType = clientType; } } diff --git a/src/main/java/com/upchina/common/service/AppUserService.java b/src/main/java/com/upchina/common/service/AppUserService.java index 85f3898..1ca94e8 100644 --- a/src/main/java/com/upchina/common/service/AppUserService.java +++ b/src/main/java/com/upchina/common/service/AppUserService.java @@ -10,6 +10,7 @@ import com.upchina.business.service.BusinessApiService; import com.upchina.business.vo.BusinessLoginVO; import com.upchina.business.vo.BusinessModuleVO; import com.upchina.business.vo.BusinessUserVO; +import com.upchina.common.constant.AppLoginType; import com.upchina.common.handler.BizException; import com.upchina.common.query.AppUserInfoQuery; import com.upchina.common.result.ResponseStatus; @@ -53,12 +54,28 @@ public class AppUserService { @Transactional(rollbackFor = Exception.class) public AppCUserInfoVO getUserInfo(AppUserInfoQuery query) { + Integer loginType = query.getLoginType(); String userName = query.getUserName(); String password = query.getPassword(); + String token = query.getToken(); + String refreshToken = query.getRefreshToken(); Integer clientType = query.getClientType(); - BusinessLoginVO loginVO = businessApiService.loginByUserName(userName, password); - BusinessUserVO userVO = businessApiService.getUserByToken(loginVO.getToken()); - AppCUserInfoVO userInfoVO = new AppCUserInfoVO(loginVO, userVO, clientType); + if (AppLoginType.USERNAME_PASSWORD.value.equals(loginType)) { + if (StrUtil.isEmpty(userName) || StrUtil.isEmpty(password)) { + throw new BizException(ResponseStatus.PARM_ERROR, "用户名或密码为空"); + } + BusinessLoginVO loginVO = businessApiService.loginByUserName(userName, password); + token = loginVO.getToken(); + refreshToken = loginVO.getRefreshToken(); + } else if (AppLoginType.TOKEN.value.equals(loginType)) { + if (StrUtil.isEmpty(query.getToken()) || StrUtil.isEmpty(query.getRefreshToken())) { + throw new BizException(ResponseStatus.PARM_ERROR, "token或refreshToken为空"); + } + } else { + throw new BizException(ResponseStatus.PARM_ERROR, "登录方式错误"); + } + BusinessUserVO userVO = businessApiService.getUserByToken(token); + AppCUserInfoVO userInfoVO = new AppCUserInfoVO(token, refreshToken, userVO, clientType); FrontUserVO frontUserVO = new FrontUserVO(userInfoVO); if (frontUserVO != null) { // 校验黑名单 diff --git a/src/main/java/com/upchina/common/vo/AppCUserInfoVO.java b/src/main/java/com/upchina/common/vo/AppCUserInfoVO.java index e7dc553..556519e 100644 --- a/src/main/java/com/upchina/common/vo/AppCUserInfoVO.java +++ b/src/main/java/com/upchina/common/vo/AppCUserInfoVO.java @@ -33,14 +33,14 @@ public class AppCUserInfoVO { public AppCUserInfoVO() { } - public AppCUserInfoVO(BusinessLoginVO loginVO, BusinessUserVO userVO, Integer clientType) { + public AppCUserInfoVO(String token, String refreshToken, BusinessUserVO userVO, Integer clientType) { this.userId = userVO.getUserId().toString(); this.userName = userVO.getUsername(); this.nickName = userVO.getNickName(); this.imgUrl = userVO.getHeadPicUrl(); this.clientType = clientType; - this.token = loginVO.getToken(); - this.refreshToken = loginVO.getRefreshToken(); + this.token = token; + this.refreshToken = refreshToken; } public String getUserId() {