终端登录接口
This commit is contained in:
parent
35a6dfa7e9
commit
307f01147f
@ -0,0 +1,124 @@
|
||||
package com.upchina.business.service;
|
||||
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.upchina.business.vo.*;
|
||||
import com.upchina.common.handler.BizException;
|
||||
import com.upchina.common.result.ResponseStatus;
|
||||
import com.upchina.common.util.logger.LoggerUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
// business信息Service
|
||||
@Service
|
||||
public class BusinessApiService {
|
||||
|
||||
private String host = "https://webdzapi.ceniu.sztg.com";
|
||||
|
||||
private String loginUrl = "/common/loginByUserName";
|
||||
|
||||
private String getUserUrl = "/common/getUserByToken";
|
||||
|
||||
private String authorizationDeptId = "16";
|
||||
|
||||
private String authorizationKey = "56e670eea5ff3a1aebbc02820e908ceb56e670eea5ff3a1aebbc02820e908ceb";
|
||||
|
||||
// private String authorizationDeptId = "33";
|
||||
//
|
||||
// private String authorizationKey = "90804bd6089d950e8804c6d7cad7558a90804bd6089d950e8804c6d7cad7558a";
|
||||
|
||||
private static final int timeout = 10000;
|
||||
|
||||
private static final int SUCCESS_CODE = 200;
|
||||
|
||||
public BusinessLoginVO loginByUserName(String userName, String password) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("username", userName);
|
||||
params.put("password", sha512(password));
|
||||
BusinessLoginRspVO vo = post(loginUrl, params, BusinessLoginRspVO.class);
|
||||
return vo.getData();
|
||||
}
|
||||
|
||||
public BusinessUserVO getUserByToken(String token) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("token", token);
|
||||
BusinessUserRspVO vo = post(getUserUrl, params, BusinessUserRspVO.class);
|
||||
return vo.getData();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
BusinessApiService service = new BusinessApiService();
|
||||
BusinessLoginVO loginVO = service.loginByUserName("sz545138", "Abc@123");
|
||||
String token = loginVO.getToken();
|
||||
BusinessUserVO userVO = service.getUserByToken(token);
|
||||
System.out.println(JSONUtil.toJsonStr(userVO));
|
||||
}
|
||||
|
||||
private <T extends BusinessVO> T post(String url, Map<String, Object> params, Class<T> type) {
|
||||
T vo;
|
||||
try {
|
||||
if (params == null) {
|
||||
params = new HashMap<>();
|
||||
}
|
||||
String body = JSONUtil.toJsonStr(params);
|
||||
Map<String, List<String>> header = buildHeader();
|
||||
LoggerUtil.api.info("url:" + url + ",body:" + body, ",header:" + JSONUtil.toJsonStr(header));
|
||||
String response = HttpRequest.post(host + url)
|
||||
.body(body, "application/json")
|
||||
.header(header, true)
|
||||
.timeout(timeout)//超时,毫秒
|
||||
.execute().body();
|
||||
LoggerUtil.api.info("response:" + response);
|
||||
vo = JSONUtil.toBean(response, type);
|
||||
LoggerUtil.api.info("vo:" + JSONUtil.toJsonStr(vo));
|
||||
if (vo.getCode() != null && vo.getCode() != SUCCESS_CODE) {
|
||||
throw new BizException(ResponseStatus.OUTSYS_ERROR, vo.getCode() + ":" + vo.getMessage());
|
||||
}
|
||||
} catch (BizException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new BizException(ResponseStatus.OUTSYS_ERROR, e);
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
private String encodeSign(String time) {
|
||||
return SecureUtil.md5(authorizationKey + authorizationDeptId + time);
|
||||
}
|
||||
|
||||
private static String sha512(String str) {
|
||||
try {
|
||||
// 获取SHA-512算法的MessageDigest实例
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-512");
|
||||
// 将输入字符串转换为字节数组并计算哈希值
|
||||
byte[] hashBytes = digest.digest(str.getBytes(StandardCharsets.UTF_8));
|
||||
// 将字节数组转换为十六进制字符串
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : hashBytes) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) hexString.append('0');
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, List<String>> buildHeader() {
|
||||
Map<String, List<String>> header = new HashMap<>();
|
||||
String time = String.valueOf(System.currentTimeMillis());
|
||||
header.put("Authorization-Dept-Id", List.of(authorizationDeptId));
|
||||
header.put("Authorization-Sign-Time", List.of(time));
|
||||
header.put("Authorization-Sign", List.of(encodeSign(time)));
|
||||
return header;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.upchina.business.vo;
|
||||
|
||||
public class BusinessLoginRspVO extends BusinessVO {
|
||||
|
||||
private BusinessLoginVO data;
|
||||
|
||||
public BusinessLoginVO getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(BusinessLoginVO data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
24
src/main/java/com/upchina/business/vo/BusinessLoginVO.java
Normal file
24
src/main/java/com/upchina/business/vo/BusinessLoginVO.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.upchina.business.vo;
|
||||
|
||||
public class BusinessLoginVO {
|
||||
|
||||
private String token;
|
||||
|
||||
private String refreshToken;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
15
src/main/java/com/upchina/business/vo/BusinessUserRspVO.java
Normal file
15
src/main/java/com/upchina/business/vo/BusinessUserRspVO.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.upchina.business.vo;
|
||||
|
||||
public class BusinessUserRspVO extends BusinessVO {
|
||||
|
||||
private BusinessUserVO data;
|
||||
|
||||
public BusinessUserVO getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(BusinessUserVO data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
95
src/main/java/com/upchina/business/vo/BusinessUserVO.java
Normal file
95
src/main/java/com/upchina/business/vo/BusinessUserVO.java
Normal file
@ -0,0 +1,95 @@
|
||||
package com.upchina.business.vo;
|
||||
|
||||
// {"id":3326,"userId":545138,"username":"sz545138","state":0,"email":"","mobile":"","umid":"","nickName":"sz545138","headPicUrl":"https://oss.ceniu.sztg.com/CRM2/HeadPic/16.jpg?t=20250215115612","regChannel":0,"regIp":"120.238.224.24","regExt":"","clientExt":"","remark":"","createTime":"2025-02-15 11:56:12","updateTime":"2025-02-15 11:56:56","userBindList":[],"userBusinessChannelList":[],"userModuleList":[]}
|
||||
public class BusinessUserVO {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Integer userId;
|
||||
|
||||
private String username;
|
||||
|
||||
private Integer state;
|
||||
|
||||
private String email;
|
||||
|
||||
private String mobile;
|
||||
|
||||
private String umid;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String headPicUrl;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Integer getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(Integer state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
public String getUmid() {
|
||||
return umid;
|
||||
}
|
||||
|
||||
public void setUmid(String umid) {
|
||||
this.umid = umid;
|
||||
}
|
||||
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
public String getHeadPicUrl() {
|
||||
return headPicUrl;
|
||||
}
|
||||
|
||||
public void setHeadPicUrl(String headPicUrl) {
|
||||
this.headPicUrl = headPicUrl;
|
||||
}
|
||||
}
|
||||
32
src/main/java/com/upchina/business/vo/BusinessVO.java
Normal file
32
src/main/java/com/upchina/business/vo/BusinessVO.java
Normal file
@ -0,0 +1,32 @@
|
||||
package com.upchina.business.vo;
|
||||
|
||||
public class BusinessVO {
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String message;
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BusinessVO{" +
|
||||
"code=" + code +
|
||||
", message='" + message + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,11 @@ public class AppUserInfoQuery {
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
@NotBlank
|
||||
private String userId;
|
||||
private String userName;
|
||||
|
||||
@ApiModelProperty("密码")
|
||||
@NotBlank
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty("客户类型 1:H5 2:Web")
|
||||
@NotNull
|
||||
@ -20,19 +24,27 @@ public class AppUserInfoQuery {
|
||||
@Max(2)
|
||||
private Integer clientType;
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
public @NotBlank String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
public void setUserName(@NotBlank String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public Integer getClientType() {
|
||||
public @NotBlank String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(@NotBlank String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public @NotNull @Min(1) @Max(2) Integer getClientType() {
|
||||
return clientType;
|
||||
}
|
||||
|
||||
public void setClientType(Integer clientType) {
|
||||
public void setClientType(@NotNull @Min(1) @Max(2) Integer clientType) {
|
||||
this.clientType = clientType;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,9 @@ package com.upchina.common.service;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.upchina.business.service.BusinessApiService;
|
||||
import com.upchina.business.vo.BusinessLoginVO;
|
||||
import com.upchina.business.vo.BusinessUserVO;
|
||||
import com.upchina.common.handler.BizException;
|
||||
import com.upchina.common.query.AppUserInfoQuery;
|
||||
import com.upchina.common.result.ResponseStatus;
|
||||
@ -37,26 +40,23 @@ public class AppUserService {
|
||||
@Resource
|
||||
private UserBlackListService userBlackListService;
|
||||
|
||||
@Resource
|
||||
private BusinessApiService businessApiService;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AppCUserInfoVO getUserInfo(AppUserInfoQuery query) {
|
||||
String userId = query.getUserId();
|
||||
String userName = query.getUserName();
|
||||
String password = query.getPassword();
|
||||
Integer clientType = query.getClientType();
|
||||
AppCUserInfoVO userInfoVO = new AppCUserInfoVO();
|
||||
userInfoVO.setUserId(userId);
|
||||
userInfoVO.setClientType(clientType);
|
||||
// TODO 对接前端健全
|
||||
FrontUserVO frontUserVO = new FrontUserVO();
|
||||
frontUserVO.setUserId(userId);
|
||||
frontUserVO.setUserName(userId);
|
||||
frontUserVO.setClientType(clientType);
|
||||
BusinessLoginVO loginVO = businessApiService.loginByUserName(userName, password);
|
||||
BusinessUserVO userVO = businessApiService.getUserByToken(loginVO.getToken());
|
||||
AppCUserInfoVO userInfoVO = new AppCUserInfoVO(loginVO, userVO, clientType);
|
||||
FrontUserVO frontUserVO = new FrontUserVO(userInfoVO);
|
||||
if (frontUserVO != null) {
|
||||
// 校验黑名单
|
||||
if (userBlackListService.check(userId)) {
|
||||
if (userBlackListService.check(frontUserVO.getUserId())) {
|
||||
throw new BizException(ResponseStatus.USER_BLACK_LIST_ERROR);
|
||||
}
|
||||
userInfoVO.setUserId(userId);
|
||||
userInfoVO.setUserName(frontUserVO.getUserName());
|
||||
userInfoVO.setImgUrl(frontUserVO.getImgUrl());
|
||||
String upToken = JwtUtil.encrypt(jwtSecret, jwtKey, frontUserVO);
|
||||
userInfoVO.setUpToken(upToken);
|
||||
//记录微信用户数据数据
|
||||
|
||||
@ -12,6 +12,8 @@ public class LoggerUtil {
|
||||
|
||||
public static final LoggerAgent auth = LoggerAgent.build("auth");
|
||||
|
||||
public static final LoggerAgent api = LoggerAgent.build("api");
|
||||
|
||||
public static void info(String message) {
|
||||
data.info(message);
|
||||
}
|
||||
|
||||
@ -1,47 +1,46 @@
|
||||
package com.upchina.common.vo;
|
||||
|
||||
import com.upchina.business.vo.BusinessLoginVO;
|
||||
import com.upchina.business.vo.BusinessUserVO;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
public class AppCUserInfoVO {
|
||||
|
||||
@ApiModelProperty("解析后的直播id")
|
||||
private Integer videoId;
|
||||
|
||||
@ApiModelProperty("upToken")
|
||||
private String upToken;
|
||||
|
||||
@ApiModelProperty("用户id")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("用户名")
|
||||
private String userName;
|
||||
|
||||
@ApiModelProperty("昵称")
|
||||
private String nickName;
|
||||
|
||||
@ApiModelProperty("用户头像")
|
||||
private String imgUrl;
|
||||
|
||||
@ApiModelProperty("客户类型 1 PC 2 app 3 web 4 H5")
|
||||
@ApiModelProperty("客户类型 1:H5 2:Web")
|
||||
private Integer clientType;
|
||||
|
||||
@ApiModelProperty("app登录的token")
|
||||
private String appToken;
|
||||
@ApiModelProperty("token")
|
||||
private String token;
|
||||
|
||||
@ApiModelProperty("app登录的sign")
|
||||
private String appSign;
|
||||
@ApiModelProperty("refreshToken")
|
||||
private String refreshToken;
|
||||
|
||||
public Integer getVideoId() {
|
||||
return videoId;
|
||||
@ApiModelProperty("upToken")
|
||||
private String upToken;
|
||||
|
||||
public AppCUserInfoVO() {
|
||||
}
|
||||
|
||||
public void setVideoId(Integer videoId) {
|
||||
this.videoId = videoId;
|
||||
}
|
||||
|
||||
public String getUpToken() {
|
||||
return upToken;
|
||||
}
|
||||
|
||||
public void setUpToken(String upToken) {
|
||||
this.upToken = upToken;
|
||||
public AppCUserInfoVO(BusinessLoginVO loginVO, 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();
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
@ -60,6 +59,14 @@ public class AppCUserInfoVO {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
public String getImgUrl() {
|
||||
return imgUrl;
|
||||
}
|
||||
@ -76,19 +83,27 @@ public class AppCUserInfoVO {
|
||||
this.clientType = clientType;
|
||||
}
|
||||
|
||||
public String getAppToken() {
|
||||
return appToken;
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setAppToken(String appToken) {
|
||||
this.appToken = appToken;
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getAppSign() {
|
||||
return appSign;
|
||||
public String getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
|
||||
public void setAppSign(String appSign) {
|
||||
this.appSign = appSign;
|
||||
public void setRefreshToken(String refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
|
||||
public String getUpToken() {
|
||||
return upToken;
|
||||
}
|
||||
|
||||
public void setUpToken(String upToken) {
|
||||
this.upToken = upToken;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ public class FrontUserVO {
|
||||
|
||||
private String userName;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String imgUrl;
|
||||
|
||||
private Integer clientType;
|
||||
@ -13,6 +15,14 @@ public class FrontUserVO {
|
||||
public FrontUserVO() {
|
||||
}
|
||||
|
||||
public FrontUserVO(AppCUserInfoVO appCUserInfoVO) {
|
||||
this.userId = appCUserInfoVO.getUserId();
|
||||
this.userName = appCUserInfoVO.getUserName();
|
||||
this.nickName = appCUserInfoVO.getNickName();
|
||||
this.imgUrl = appCUserInfoVO.getImgUrl();
|
||||
this.clientType = appCUserInfoVO.getClientType();
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
@ -29,6 +39,14 @@ public class FrontUserVO {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
public String getImgUrl() {
|
||||
return imgUrl;
|
||||
}
|
||||
@ -44,5 +62,4 @@ public class FrontUserVO {
|
||||
public void setClientType(Integer clientType) {
|
||||
this.clientType = clientType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -72,6 +72,17 @@
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="api" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/advisor_server-api-%d{yyyyMMdd}.log</fileNamePattern>
|
||||
<maxHistory>30</maxHistory> <!-- 保留最多30天的日志 -->
|
||||
<totalSizeCap>1GB</totalSizeCap> <!-- 限制日志总大小 -->
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}|%-4.5level|%X{requestId}|%msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 配置日志记录器,按业务模块使用不同的 appender -->
|
||||
<logger name="video" level="INFO" additivity="false">
|
||||
<appender-ref ref="video"/>
|
||||
@ -93,6 +104,10 @@
|
||||
<appender-ref ref="auth"/>
|
||||
</logger>
|
||||
|
||||
<logger name="api" level="INFO" additivity="false">
|
||||
<appender-ref ref="api"/>
|
||||
</logger>
|
||||
|
||||
<!-- 根 Logger 配置 (可以定义默认的日志记录器) -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="default"/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user