|
@@ -1,6 +1,7 @@
|
|
package com.hfln.portal.infrastructure.gateway.impl;
|
|
package com.hfln.portal.infrastructure.gateway.impl;
|
|
|
|
|
|
|
|
|
|
|
|
+import cn.dev33.satoken.session.SaSession;
|
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.hfln.framework.common.redis.service.RedisService;
|
|
import cn.hfln.framework.common.redis.service.RedisService;
|
|
@@ -8,11 +9,13 @@ import cn.hfln.framework.extension.BizException;
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.hfln.portal.common.constant.UserConstants;
|
|
import com.hfln.portal.common.constant.redis.RedisCacheConstant;
|
|
import com.hfln.portal.common.constant.redis.RedisCacheConstant;
|
|
import com.hfln.portal.common.dto.data.oss.OssFileDTO;
|
|
import com.hfln.portal.common.dto.data.oss.OssFileDTO;
|
|
import com.hfln.portal.common.dto.data.user.UserDto;
|
|
import com.hfln.portal.common.dto.data.user.UserDto;
|
|
import com.hfln.portal.common.request.user.*;
|
|
import com.hfln.portal.common.request.user.*;
|
|
import com.hfln.portal.common.response.user.UserInfoWxRes;
|
|
import com.hfln.portal.common.response.user.UserInfoWxRes;
|
|
|
|
+import com.hfln.portal.domain.customer.DeviceType;
|
|
import com.hfln.portal.domain.customer.OssBusiType;
|
|
import com.hfln.portal.domain.customer.OssBusiType;
|
|
import com.hfln.portal.domain.customer.util.PasswordUtil;
|
|
import com.hfln.portal.domain.customer.util.PasswordUtil;
|
|
import com.hfln.portal.domain.exception.ErrorEnum;
|
|
import com.hfln.portal.domain.exception.ErrorEnum;
|
|
@@ -147,18 +150,41 @@ public class UserGatewayImpl implements UserGateway {
|
|
@Override
|
|
@Override
|
|
public Boolean loginByPhone(PhoneLoginParams params) {
|
|
public Boolean loginByPhone(PhoneLoginParams params) {
|
|
|
|
|
|
|
|
+ // todo 这里的电话号码,不能由前端 传过来,根据下面的获取电话号码 方法来获取 参照老代码 loginByPhone 方法
|
|
|
|
+
|
|
|
|
+ // 1 校验当前用户是否已注册
|
|
|
|
+ UserInfo userInfo = userService.queryByPhone(params.getPhone());
|
|
|
|
+ if (userInfo == null) {
|
|
|
|
+ // 未注册的手机号直接注册用户
|
|
|
|
+ userInfo = new UserInfo();
|
|
|
|
+ userInfo.setOpenid(params.getOpenId());
|
|
|
|
+ userInfo.setPhone(params.getPhone());
|
|
|
|
+ userInfo.setUnionId(params.getUnionId());
|
|
|
|
+ userInfo.setAvatarUrl(params.getAvatarUrl());
|
|
|
|
+ userService.save(userInfo);
|
|
|
|
+ } else {
|
|
|
|
+ log.info("当前用户已注册:{}", params.getPhone());
|
|
|
|
+ }
|
|
|
|
|
|
- if (userService.checkAvailableOpenId(params.getOpenId())) {
|
|
|
|
- log.info("当前用户已登录:{}", params.getOpenId());
|
|
|
|
- return true;
|
|
|
|
|
|
+ // 2 校验当前用户是否已登录
|
|
|
|
+ boolean isLogin = StpUtil.isLogin();
|
|
|
|
+ if (!isLogin) {
|
|
|
|
+ StpUtil.login(userInfo.getUserId(), DeviceType.WX.getCode());
|
|
|
|
+
|
|
|
|
+ // 这里可以考虑 在session 中插入信息
|
|
|
|
+ // 同账户多设备 登录共享信息
|
|
|
|
+ SaSession session = StpUtil.getSession();
|
|
|
|
+ session.set(UserConstants.SA_USER_PHONE, userInfo.getPhone());
|
|
|
|
+ session.set(UserConstants.SA_USER_ID, userInfo.getUserId());
|
|
|
|
+
|
|
|
|
+ // 当前设备session 独享信息
|
|
|
|
+ SaSession wxSession = StpUtil.getTokenSession();
|
|
|
|
+ wxSession.set(UserConstants.SA_USER_OPEN_ID, userInfo.getOpenid());
|
|
|
|
+ wxSession.set(UserConstants.SA_USER_UNION_ID, userInfo.getUnionId());
|
|
|
|
+ } else {
|
|
|
|
+ log.info("当前用户已登录:{}", params.getPhone());
|
|
}
|
|
}
|
|
|
|
|
|
- UserInfo userInfo = new UserInfo();
|
|
|
|
- userInfo.setOpenid(params.getOpenId());
|
|
|
|
- userInfo.setPhone(params.getPhone());
|
|
|
|
- userInfo.setUnionId(params.getUnionId());
|
|
|
|
- userInfo.setAvatarUrl(params.getAvatarUrl());
|
|
|
|
- userService.save(userInfo);
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -205,6 +231,18 @@ public class UserGatewayImpl implements UserGateway {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ public UserDto queryByOpenId(String openId) {
|
|
|
|
+
|
|
|
|
+ UserInfo userInfo = userService.queryByOpenId(openId);
|
|
|
|
+ if (userInfo == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ UserDto userDto = new UserDto();
|
|
|
|
+ BeanUtils.copyProperties(userInfo, userDto);
|
|
|
|
+ return userDto;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
public UserDto loginBySmsCode(LoginBySmsCodeParams request) {
|
|
public UserDto loginBySmsCode(LoginBySmsCodeParams request) {
|
|
UserDto userDto = new UserDto();
|
|
UserDto userDto = new UserDto();
|
|
String phone = request.getUserName();
|
|
String phone = request.getUserName();
|
|
@@ -368,7 +406,7 @@ public class UserGatewayImpl implements UserGateway {
|
|
}
|
|
}
|
|
|
|
|
|
//2.消除登录凭证
|
|
//2.消除登录凭证
|
|
- StpUtil.logout(request.getUserId());
|
|
|
|
|
|
+ StpUtil.logout(request.getUserId(), DeviceType.WX.getCode());
|
|
|
|
|
|
//3.修改用户信息表中的is_delete字段为1
|
|
//3.修改用户信息表中的is_delete字段为1
|
|
// 使用 MyBatis Plus 的逻辑删除功能
|
|
// 使用 MyBatis Plus 的逻辑删除功能
|
|
@@ -492,6 +530,27 @@ public class UserGatewayImpl implements UserGateway {
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void freshToken(WxFreshTokenParams params) {
|
|
|
|
+
|
|
|
|
+ UserInfo userInfo = null;
|
|
|
|
+ if (StringUtils.isNotBlank(params.getOpenId())) {
|
|
|
|
+
|
|
|
|
+ } else if (StringUtils.isNotBlank(params.getPhone())) {
|
|
|
|
+ userInfo = userService.queryByPhone(params.getPhone());
|
|
|
|
+ } else if (params.getUserId() == null) {
|
|
|
|
+ userInfo = userService.queryById(params.getUserId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (userInfo == null) {
|
|
|
|
+ throw new BizException(ErrorEnum.USER_NOT_FOUND.getErrorCode(), ErrorEnum.USER_NOT_FOUND.getErrorMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!StpUtil.isLogin()) {
|
|
|
|
+ StpUtil.login(userInfo.getUserId(), DeviceType.WX.getCode());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private boolean checkPngMagicNumber(byte[] fileHeader) {
|
|
private boolean checkPngMagicNumber(byte[] fileHeader) {
|
|
byte[] pngMagicNumber = {(byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
|
|
byte[] pngMagicNumber = {(byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
|
|
return Arrays.equals(Arrays.copyOfRange(fileHeader, 0, 8), pngMagicNumber);
|
|
return Arrays.equals(Arrays.copyOfRange(fileHeader, 0, 8), pngMagicNumber);
|