单点登录
This commit is contained in:
parent
b441549956
commit
6f6ae29386
|
@ -6,6 +6,7 @@ import com.hzya.frame.web.entity.JsonResultEntity;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static com.hzya.frame.web.entity.BaseResult.getFailureMessageEntity;
|
||||
import static com.hzya.frame.web.entity.BaseResult.getSuccessMessageEntity;
|
||||
|
||||
@RestController
|
||||
|
@ -22,6 +23,9 @@ public class SSOController {
|
|||
@PostMapping("/check")
|
||||
public JsonResultEntity checkLogin(@RequestBody LoginVO loginVO){
|
||||
String token = iLoginService.checkLogin(loginVO.getWxUserId());
|
||||
if(token == null){
|
||||
return getFailureMessageEntity("校验失败","500",token);
|
||||
}
|
||||
return getSuccessMessageEntity("校验成功",token);
|
||||
}
|
||||
}
|
|
@ -346,20 +346,24 @@ public class LoginServiceImpl implements ILoginService {
|
|||
*/
|
||||
@Override
|
||||
public String checkLogin(String wxUserId) {
|
||||
if(wxUserId == null){
|
||||
throw new RuntimeException("wxUserId不能为空");
|
||||
if(wxUserId == null || wxUserId.equals("")){
|
||||
logger.error("wxUserId不能为空");
|
||||
return null;
|
||||
}
|
||||
// 查询对应用户
|
||||
SysUserEntity sysUserEntity = new SysUserEntity();
|
||||
sysUserEntity.setWxUserId(wxUserId);
|
||||
SysUserEntity query = sysUserDao.queryOne(sysUserEntity);
|
||||
if(query == null){
|
||||
SysUserEntity user = sysUserDao.queryOne(sysUserEntity);
|
||||
if(user == null){
|
||||
// 验证不通过
|
||||
throw new RuntimeException("用户不存在");
|
||||
logger.error("用户不存在");
|
||||
return null;
|
||||
}
|
||||
// 验证通过
|
||||
StpUtil.login(query.getId());
|
||||
StpUtil.login(user.getId());
|
||||
// 获取token
|
||||
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
|
||||
String token = tokenInfo.toString();
|
||||
String token = tokenInfo.getTokenValue();
|
||||
|
||||
return token;
|
||||
|
||||
|
|
Loading…
Reference in New Issue