Compare commits
2 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
45c1291aa5 | |
|
|
f9cc1fb291 |
|
|
@ -14,6 +14,7 @@ import com.bonus.auth.form.LoginBody;
|
||||||
import com.bonus.auth.mapper.AuthCustCasualMapper;
|
import com.bonus.auth.mapper.AuthCustCasualMapper;
|
||||||
import com.bonus.auth.service.*;
|
import com.bonus.auth.service.*;
|
||||||
import com.bonus.domain.SmsCodeVerifyDTO;
|
import com.bonus.domain.SmsCodeVerifyDTO;
|
||||||
|
import com.bonus.system.api.model.LoginUser;
|
||||||
import com.bonus.utils.AesEncryptUtil;
|
import com.bonus.utils.AesEncryptUtil;
|
||||||
import com.bonus.utils.id.Id;
|
import com.bonus.utils.id.Id;
|
||||||
import com.bonus.utils.SM4EncryptUtils;
|
import com.bonus.utils.SM4EncryptUtils;
|
||||||
|
|
@ -101,15 +102,13 @@ public class TokenController {
|
||||||
if (keys.size() >= concurrency){
|
if (keys.size() >= concurrency){
|
||||||
return R.fail("当前系统用户并发数超过系统配置,请稍后再试");
|
return R.fail("当前系统用户并发数超过系统配置,请稍后再试");
|
||||||
}
|
}
|
||||||
CustInfoAppIdLoginVO loginUser = custLogin(form);
|
LoginUser loginUser = custLogin(form);
|
||||||
Map<String, Object> map = tokenService.createToken(loginUser);
|
Map<String, Object> map = tokenService.createToken(loginUser);
|
||||||
loginUser.setToken((String) map.get(CustTokenService.ACCESS_TOKEN));
|
loginUser.setToken((String) map.get(CustTokenService.ACCESS_TOKEN));
|
||||||
loginUser.setExpireIn((Long) map.get(CustTokenService.EXPIRES_IN));
|
|
||||||
loginUser.setLogin((boolean) map.get(CustTokenService.IS_LOGIN));
|
|
||||||
return R.ok(loginUser);
|
return R.ok(loginUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CustInfoAppIdLoginVO custLogin(LoginBody content) {
|
private LoginUser custLogin(LoginBody content) {
|
||||||
// if (CharSequenceUtil.isNotBlank(content.getMobile())) {
|
// if (CharSequenceUtil.isNotBlank(content.getMobile())) {
|
||||||
// content.setMobile(AesEncryptUtil.aesDecode(content.getMobile()));
|
// content.setMobile(AesEncryptUtil.aesDecode(content.getMobile()));
|
||||||
// }
|
// }
|
||||||
|
|
@ -136,14 +135,13 @@ public class TokenController {
|
||||||
}
|
}
|
||||||
custInfo.setIdCard(SM4EncryptUtils.sm4Encryptbyconfig(content.getIdCard()));
|
custInfo.setIdCard(SM4EncryptUtils.sm4Encryptbyconfig(content.getIdCard()));
|
||||||
}
|
}
|
||||||
CustInfoAppIdLoginVO result = this.custInfoMapper.selectLoginInfo(custInfo);
|
LoginUser result = this.custInfoMapper.selectLoginInfo(custInfo);
|
||||||
if (Objects.isNull(result)) {
|
if (Objects.isNull(result)) {
|
||||||
throw new ServiceException("未找到用户");
|
throw new ServiceException("未找到用户");
|
||||||
} else {
|
} else {
|
||||||
result.setCustIdStr(result.getCustId().toString());
|
|
||||||
if (CustLoginTypeEnum.getNeedPasswordLoginTypeToMap().containsKey(content.getLoginType())) {
|
if (CustLoginTypeEnum.getNeedPasswordLoginTypeToMap().containsKey(content.getLoginType())) {
|
||||||
content.setPassword(AesEncryptUtil.aesDecode(content.getPassword()));
|
content.setPassword(AesEncryptUtil.aesDecode(content.getPassword()));
|
||||||
if (!encoder.matches(content.getPassword(), result.getPwd())) {
|
if (!encoder.matches(content.getPassword(), result.getPassword())) {
|
||||||
throw new ServiceException("密码错误");
|
throw new ServiceException("密码错误");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +156,7 @@ public class TokenController {
|
||||||
System.out.println(flag);
|
System.out.println(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustInfoAppIdLoginVO addOrUpdateCustCasual(Integer sourceType, CustInfoAppIdLoginVO result) {
|
public LoginUser addOrUpdateCustCasual(Integer sourceType, LoginUser result) {
|
||||||
Long custId = result.getCustId();
|
Long custId = result.getCustId();
|
||||||
CustCasual custCasual = this.authCustCasualMapper.selectCustCasualByCustId(custId, sourceType, DelFlagEnum.DEL_FALSE.key());
|
CustCasual custCasual = this.authCustCasualMapper.selectCustCasualByCustId(custId, sourceType, DelFlagEnum.DEL_FALSE.key());
|
||||||
String openid;
|
String openid;
|
||||||
|
|
@ -166,9 +164,9 @@ public class TokenController {
|
||||||
CustCasual insertCasual = new CustCasual();
|
CustCasual insertCasual = new CustCasual();
|
||||||
openid = IdUtil.simpleUUID();
|
openid = IdUtil.simpleUUID();
|
||||||
insertCasual.setCasualId(Id.next()); //TODO, NPE
|
insertCasual.setCasualId(Id.next()); //TODO, NPE
|
||||||
insertCasual.setCasualName(SM4EncryptUtils.sm4Decrypt(result.getCustName()));
|
insertCasual.setCasualName(SM4EncryptUtils.sm4Decrypt(result.getNickName()));
|
||||||
insertCasual.setCustId(result.getCustId());
|
insertCasual.setCustId(result.getCustId());
|
||||||
insertCasual.setMobile(SM4EncryptUtils.sm4Decrypt(result.getMobile()));
|
insertCasual.setMobile(SM4EncryptUtils.sm4Decrypt(result.getPhonenumber()));
|
||||||
insertCasual.setOpenid(openid);
|
insertCasual.setOpenid(openid);
|
||||||
insertCasual.setSourceType(sourceType);
|
insertCasual.setSourceType(sourceType);
|
||||||
this.authCustCasualMapper.addCustCasual(insertCasual);
|
this.authCustCasualMapper.addCustCasual(insertCasual);
|
||||||
|
|
@ -180,9 +178,9 @@ public class TokenController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.setOpenid(openid);
|
result.setOpenId(openid);
|
||||||
result.setCustName(SM4EncryptUtils.sm4Decrypt(result.getCustName()));
|
result.setNickName(SM4EncryptUtils.sm4Decrypt(result.getNickName()));
|
||||||
result.setMobile(SM4EncryptUtils.sm4Decrypt(result.getMobile()));
|
result.setPhonenumber(SM4EncryptUtils.sm4Decrypt(result.getPhonenumber()));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,7 +237,7 @@ public class TokenController {
|
||||||
@PostMapping("refresh")
|
@PostMapping("refresh")
|
||||||
public R<?> refresh(HttpServletRequest request) {
|
public R<?> refresh(HttpServletRequest request) {
|
||||||
try {
|
try {
|
||||||
CustInfoAppIdLoginVO loginUser = tokenService.getLoginUser(request);
|
LoginUser loginUser = tokenService.getLoginUser(request);
|
||||||
if (StringUtils.isNotNull(loginUser)) {
|
if (StringUtils.isNotNull(loginUser)) {
|
||||||
tokenService.refreshToken(loginUser);
|
tokenService.refreshToken(loginUser);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@ package com.bonus.auth.mapper;
|
||||||
|
|
||||||
import com.bonus.domain.CustInfo;
|
import com.bonus.domain.CustInfo;
|
||||||
import com.bonus.domain.CustInfoAppIdLoginVO;
|
import com.bonus.domain.CustInfoAppIdLoginVO;
|
||||||
|
import com.bonus.system.api.model.LoginUser;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface AuthCustInfoMapper {
|
public interface AuthCustInfoMapper {
|
||||||
CustInfoAppIdLoginVO selectLoginInfo(CustInfo custInfo);
|
LoginUser selectLoginInfo(CustInfo custInfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import com.bonus.common.security.utils.SecurityUtils;
|
||||||
import com.bonus.config.SystemConfig;
|
import com.bonus.config.SystemConfig;
|
||||||
import com.bonus.system.api.RemoteUserService;
|
import com.bonus.system.api.RemoteUserService;
|
||||||
import com.bonus.domain.CustInfoAppIdLoginVO;
|
import com.bonus.domain.CustInfoAppIdLoginVO;
|
||||||
|
import com.bonus.system.api.domain.SysUser;
|
||||||
|
import com.bonus.system.api.model.LoginUser;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -67,15 +69,15 @@ public class CustTokenService {
|
||||||
/**
|
/**
|
||||||
* 创建令牌
|
* 创建令牌
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> createToken(CustInfoAppIdLoginVO loginUser) {
|
public Map<String, Object> createToken(LoginUser loginUser) {
|
||||||
// 检查并删除已有的token
|
// 检查并删除已有的token
|
||||||
delExistingToken(loginUser.getCustId());
|
delExistingToken(loginUser.getCustId());
|
||||||
String token = IdUtils.fastUUID();
|
String token = IdUtils.fastUUID();
|
||||||
Long custId = loginUser.getCustId();
|
Long custId = loginUser.getCustId();
|
||||||
String userName = loginUser.getCustName();
|
String userName = loginUser.getNickName();
|
||||||
loginUser.setToken(token);
|
loginUser.setToken(token);
|
||||||
loginUser.setCustId(custId);
|
loginUser.setCustId(custId);
|
||||||
loginUser.setCustName(userName);
|
loginUser.setNickName(userName);
|
||||||
loginUser.setIpaddr(IpUtils.getIpAddr());
|
loginUser.setIpaddr(IpUtils.getIpAddr());
|
||||||
refreshToken(loginUser);
|
refreshToken(loginUser);
|
||||||
// Jwt存储信息
|
// Jwt存储信息
|
||||||
|
|
@ -119,7 +121,7 @@ public class CustTokenService {
|
||||||
*
|
*
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
public CustInfoAppIdLoginVO getLoginUser() {
|
public LoginUser getLoginUser() {
|
||||||
return getLoginUser(ServletUtils.getRequest());
|
return getLoginUser(ServletUtils.getRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,7 +130,7 @@ public class CustTokenService {
|
||||||
*
|
*
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
public CustInfoAppIdLoginVO getLoginUser(HttpServletRequest request) {
|
public LoginUser getLoginUser(HttpServletRequest request) {
|
||||||
// 获取请求携带的令牌
|
// 获取请求携带的令牌
|
||||||
String token = SecurityUtils.getToken(request);
|
String token = SecurityUtils.getToken(request);
|
||||||
return getLoginUser(token);
|
return getLoginUser(token);
|
||||||
|
|
@ -139,8 +141,8 @@ public class CustTokenService {
|
||||||
*
|
*
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
public CustInfoAppIdLoginVO getLoginUser(String token) {
|
public LoginUser getLoginUser(String token) {
|
||||||
CustInfoAppIdLoginVO user = null;
|
LoginUser user = null;
|
||||||
try {
|
try {
|
||||||
if (StringUtils.isNotEmpty(token)) {
|
if (StringUtils.isNotEmpty(token)) {
|
||||||
String userkey = JwtUtils.getUserKey(token);
|
String userkey = JwtUtils.getUserKey(token);
|
||||||
|
|
@ -156,7 +158,7 @@ public class CustTokenService {
|
||||||
/**
|
/**
|
||||||
* 设置用户身份信息
|
* 设置用户身份信息
|
||||||
*/
|
*/
|
||||||
public void setLoginUser(CustInfoAppIdLoginVO loginUser) {
|
public void setLoginUser(LoginUser loginUser) {
|
||||||
if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) {
|
if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) {
|
||||||
refreshToken(loginUser);
|
refreshToken(loginUser);
|
||||||
}
|
}
|
||||||
|
|
@ -177,7 +179,7 @@ public class CustTokenService {
|
||||||
*
|
*
|
||||||
* @param loginUser
|
* @param loginUser
|
||||||
*/
|
*/
|
||||||
public void verifyToken(CustInfoAppIdLoginVO loginUser) {
|
public void verifyToken(LoginUser loginUser) {
|
||||||
long expireTime = loginUser.getExpireTime();
|
long expireTime = loginUser.getExpireTime();
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
if (expireTime - currentTime <= MILLIS_MINUTE_TEN) {
|
if (expireTime - currentTime <= MILLIS_MINUTE_TEN) {
|
||||||
|
|
@ -190,7 +192,7 @@ public class CustTokenService {
|
||||||
*
|
*
|
||||||
* @param loginUser 登录信息
|
* @param loginUser 登录信息
|
||||||
*/
|
*/
|
||||||
public void refreshToken(CustInfoAppIdLoginVO loginUser) {
|
public void refreshToken(LoginUser loginUser) {
|
||||||
long tokenTime = getTokenTime();
|
long tokenTime = getTokenTime();
|
||||||
loginUser.setLoginTime(System.currentTimeMillis());
|
loginUser.setLoginTime(System.currentTimeMillis());
|
||||||
loginUser.setExpireTime(loginUser.getLoginTime() + tokenTime * MILLIS_MINUTE);
|
loginUser.setExpireTime(loginUser.getLoginTime() + tokenTime * MILLIS_MINUTE);
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="com.bonus.auth.mapper.AuthCustInfoMapper">
|
<mapper namespace="com.bonus.auth.mapper.AuthCustInfoMapper">
|
||||||
<!--根据人员id集合获取人员信息-->
|
<!--根据人员id集合获取人员信息-->
|
||||||
<select id="selectLoginInfo" resultType="com.bonus.domain.CustInfoAppIdLoginVO">
|
<select id="selectLoginInfo" resultType="com.bonus.system.api.model.LoginUser">
|
||||||
select cust_id, cust_name, cust_num, cust_photo_url, mobile, pwd
|
select cust_id as custId, open_id as openId, cust_name as nickName, cust_photo_url as photoUrl, mobile as phonenumber, pwd as password
|
||||||
from cust_info
|
from cust_info
|
||||||
<where>
|
<where>
|
||||||
cust_state = 1 and (psn_type != 999 or psn_type is null)
|
cust_state = 1 and (psn_type != 999 or psn_type is null)
|
||||||
|
|
|
||||||
Reference in New Issue